You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@reef.apache.org by we...@apache.org on 2015/01/23 00:46:34 UTC

[01/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Repository: incubator-reef
Updated Branches:
  refs/heads/master c908a526d -> 53ea32cce


http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/MultiEventHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/MultiEventHandler.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/MultiEventHandler.java
new file mode 100644
index 0000000..0c026b2
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/MultiEventHandler.java
@@ -0,0 +1,60 @@
+/**
+ * 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.reef.wake.impl;
+
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.exception.WakeRuntimeException;
+
+import java.util.Map;
+
+/**
+ * Event handler that dispatches an event to a specific handler based on an event class type
+ *
+ * @param <T> type
+ */
+public class MultiEventHandler<T> implements EventHandler<T> {
+
+  private final Map<Class<? extends T>, EventHandler<? extends T>> map;
+
+  /**
+   * Constructs a multi-event handler
+   *
+   * @param map a map of class types to event handlers
+   */
+  public MultiEventHandler(Map<Class<? extends T>, EventHandler<? extends T>> map) {
+    this.map = map;
+  }
+
+  /**
+   * Invokes a specific handler for the event class type if it exists
+   *
+   * @param an event
+   * @throws WakeRuntimeException
+   */
+  @Override
+  public void onNext(T event) {
+    EventHandler<T> handler = (EventHandler<T>) map.get(event.getClass());
+    if (handler == null)
+      throw new WakeRuntimeException("No event " + event.getClass() + " handler");
+    handler.onNext(event);
+  }
+
+}
+
+


[43/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ContextClosedHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ContextClosedHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ContextClosedHandlers.java
new file mode 100644
index 0000000..e5b282a
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ContextClosedHandlers.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.context.ClosedContext;
+import org.apache.reef.runtime.common.driver.defaults.DefaultContextClosureHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Handler for ClosedContext.
+ */
+@NamedParameter(doc = "Handler for ClosedContext", default_classes = DefaultContextClosureHandler.class)
+public final class ContextClosedHandlers implements Name<Set<EventHandler<ClosedContext>>> {
+  private ContextClosedHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ContextFailedHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ContextFailedHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ContextFailedHandlers.java
new file mode 100644
index 0000000..1ded6f9
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ContextFailedHandlers.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.runtime.common.driver.defaults.DefaultContextFailureHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Handler for FailedContext
+ */
+@NamedParameter(doc = "Handler for FailedContext", default_classes = DefaultContextFailureHandler.class)
+public final class ContextFailedHandlers implements Name<Set<EventHandler<FailedContext>>> {
+  private ContextFailedHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ContextMessageHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ContextMessageHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ContextMessageHandlers.java
new file mode 100644
index 0000000..dc3ddd2
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ContextMessageHandlers.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.context.ContextMessage;
+import org.apache.reef.runtime.common.driver.defaults.DefaultContextMessageHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Context message handler.
+ */
+@NamedParameter(doc = "Context message handler.", default_classes = DefaultContextMessageHandler.class)
+public final class ContextMessageHandlers implements Name<Set<EventHandler<ContextMessage>>> {
+  private ContextMessageHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverIdentifier.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverIdentifier.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverIdentifier.java
new file mode 100644
index 0000000..1a0002b
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverIdentifier.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * Driver Identifier
+ */
+@NamedParameter(doc = "Driver Identifier", default_value = DriverIdentifier.DEFAULT_VALUE)
+public final class DriverIdentifier implements Name<String> {
+
+  private DriverIdentifier() {
+  }
+
+  public static final String DEFAULT_VALUE = "##NONE##DEFAULT##NEVERUSE##";
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverIdleSources.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverIdleSources.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverIdleSources.java
new file mode 100644
index 0000000..403513d
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverIdleSources.java
@@ -0,0 +1,34 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.runtime.common.driver.idle.DriverIdlenessSource;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+import java.util.Set;
+
+/**
+ * Sources considered when making an idleness decision.
+ */
+@NamedParameter(doc = "Sources considered when making an idleness decision.")
+public final class DriverIdleSources implements Name<Set<DriverIdlenessSource>> {
+  private DriverIdleSources() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverJobSubmissionDirectory.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverJobSubmissionDirectory.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverJobSubmissionDirectory.java
new file mode 100644
index 0000000..8201960
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverJobSubmissionDirectory.java
@@ -0,0 +1,32 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * Job submission directory
+ */
+@NamedParameter(doc = "Job submission directory. This is the folder on the DFS used to stage the files for the Driver and subsequently for the Evaluators. It will be created if it doesn't exist yet.")
+public final class DriverJobSubmissionDirectory implements Name<String> {
+  private DriverJobSubmissionDirectory() {
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverLocalFiles.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverLocalFiles.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverLocalFiles.java
new file mode 100644
index 0000000..4ecfc54
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverLocalFiles.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+import java.util.Set;
+
+/**
+ * Files to be made accessible on the Driver only.
+ */
+@NamedParameter(doc = "Files to be made accessible on the Driver only.")
+public final class DriverLocalFiles implements Name<Set<String>> {
+  private DriverLocalFiles() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverLocalLibraries.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverLocalLibraries.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverLocalLibraries.java
new file mode 100644
index 0000000..10eb996
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverLocalLibraries.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+import java.util.Set;
+
+/**
+ * Libraries to be made accessible on the Driver only.
+ */
+@NamedParameter(doc = "Libraries to be made accessible on the Driver only.")
+public final class DriverLocalLibraries implements Name<Set<String>> {
+  private DriverLocalLibraries() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverMemory.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverMemory.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverMemory.java
new file mode 100644
index 0000000..8df693c
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverMemory.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * Driver RAM allocation in MB
+ */
+@NamedParameter(doc = "Driver RAM allocation in MB", default_value = "256")
+public final class DriverMemory implements Name<Integer> {
+  private DriverMemory() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverRestartCompletedHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverRestartCompletedHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverRestartCompletedHandlers.java
new file mode 100644
index 0000000..341f9e4
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverRestartCompletedHandlers.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.runtime.common.DriverRestartCompleted;
+import org.apache.reef.runtime.common.driver.defaults.DefaultDriverRestartCompletedHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Handler for event that all evaluators have checked back in after driver restart and that the restart is completed
+ */
+@NamedParameter(doc = "Handler for event of driver restart completion", default_classes = DefaultDriverRestartCompletedHandler.class)
+public final class DriverRestartCompletedHandlers implements Name<Set<EventHandler<DriverRestartCompleted>>> {
+  private DriverRestartCompletedHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverRestartContextActiveHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverRestartContextActiveHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverRestartContextActiveHandlers.java
new file mode 100644
index 0000000..e06e5d9
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverRestartContextActiveHandlers.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.runtime.common.driver.defaults.DefaultDriverRestartContextActiveHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Handler for ActiveContext during a driver restart
+ */
+@NamedParameter(doc = "Handler for ActiveContext received during a driver restart", default_classes = DefaultDriverRestartContextActiveHandler.class)
+public final class DriverRestartContextActiveHandlers implements Name<Set<EventHandler<ActiveContext>>> {
+  private DriverRestartContextActiveHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverRestartHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverRestartHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverRestartHandler.java
new file mode 100644
index 0000000..b67974c
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverRestartHandler.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+/**
+ * The StartTime event is routed to this EventHandler if there is a restart, instead of to DriverStartHandler.
+ */
+@NamedParameter(doc = "The StartTime event is routed to this EventHandler if there is a restart, instead of to DriverStartHandler.")
+public final class DriverRestartHandler implements Name<EventHandler<StartTime>> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverRestartTaskRunningHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverRestartTaskRunningHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverRestartTaskRunningHandlers.java
new file mode 100644
index 0000000..3fd1732
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverRestartTaskRunningHandlers.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.task.RunningTask;
+import org.apache.reef.runtime.common.driver.defaults.DefaultDriverRestartTaskRunningHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Handler for RunningTask events during a Driver restart.
+ */
+@NamedParameter(doc = "Handler for RunningTask events during a Driver restart.", default_classes = DefaultDriverRestartTaskRunningHandler.class)
+public final class DriverRestartTaskRunningHandlers implements Name<Set<EventHandler<RunningTask>>> {
+  private DriverRestartTaskRunningHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverStartHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverStartHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverStartHandler.java
new file mode 100644
index 0000000..eeb1afa
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/DriverStartHandler.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import java.util.Set;
+
+/**
+ * Called once the Driver is completely setup.
+ */
+@NamedParameter(doc = "Called once the Driver is completely setup")
+public final class DriverStartHandler implements Name<Set<EventHandler<StartTime>>> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/EvaluatorAllocatedHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/EvaluatorAllocatedHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/EvaluatorAllocatedHandlers.java
new file mode 100644
index 0000000..7ac4c80
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/EvaluatorAllocatedHandlers.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.runtime.common.driver.defaults.DefaultEvaluatorAllocationHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Called when an allocated evaluator is given to the client.
+ */
+@NamedParameter(doc = "Called when an allocated evaluator is given to the client.", default_classes = DefaultEvaluatorAllocationHandler.class)
+public final class EvaluatorAllocatedHandlers implements Name<Set<EventHandler<AllocatedEvaluator>>> {
+  private EvaluatorAllocatedHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/EvaluatorCompletedHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/EvaluatorCompletedHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/EvaluatorCompletedHandlers.java
new file mode 100644
index 0000000..893460f
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/EvaluatorCompletedHandlers.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.evaluator.CompletedEvaluator;
+import org.apache.reef.runtime.common.driver.defaults.DefaultEvaluatorCompletionHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Called when an exception occurs on a running evaluator.
+ */
+@NamedParameter(doc = "Called when an exception occurs on a running evaluator.", default_classes = DefaultEvaluatorCompletionHandler.class)
+public final class EvaluatorCompletedHandlers implements Name<Set<EventHandler<CompletedEvaluator>>> {
+  private EvaluatorCompletedHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/EvaluatorDispatcherThreads.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/EvaluatorDispatcherThreads.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/EvaluatorDispatcherThreads.java
new file mode 100644
index 0000000..731461a
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/EvaluatorDispatcherThreads.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * Number of threads allocated per evaluator to dispatch events from that Evaluator.
+ */
+@NamedParameter(
+    doc = "Number of threads allocated per evaluator to dispatch events from that Evaluator.",
+    default_value = "1")
+public final class EvaluatorDispatcherThreads implements Name<Integer> {
+  private EvaluatorDispatcherThreads() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/EvaluatorFailedHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/EvaluatorFailedHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/EvaluatorFailedHandlers.java
new file mode 100644
index 0000000..774248c
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/EvaluatorFailedHandlers.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.evaluator.FailedEvaluator;
+import org.apache.reef.runtime.common.driver.defaults.DefaultEvaluatorFailureHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Called when an exception occurs on a running evaluator.
+ */
+@NamedParameter(doc = "Called when an exception occurs on a running evaluator.", default_classes = DefaultEvaluatorFailureHandler.class)
+public final class EvaluatorFailedHandlers implements Name<Set<EventHandler<FailedEvaluator>>> {
+  private EvaluatorFailedHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/JobGlobalFiles.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/JobGlobalFiles.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/JobGlobalFiles.java
new file mode 100644
index 0000000..1cd188f
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/JobGlobalFiles.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+import java.util.Set;
+
+/**
+ * Files to be made accessible on the Driver and all Evaluators.
+ */
+@NamedParameter(doc = "Files to be made accessible on the Driver and all Evaluators.")
+public final class JobGlobalFiles implements Name<Set<String>> {
+  private JobGlobalFiles() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/JobGlobalLibraries.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/JobGlobalLibraries.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/JobGlobalLibraries.java
new file mode 100644
index 0000000..e2db582
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/JobGlobalLibraries.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+import java.util.Set;
+
+/**
+ * Libraries to be made accessible on the Driver and all Evaluators.
+ */
+@NamedParameter(doc = "Libraries to be made accessible on the Driver and all Evaluators.")
+public final class JobGlobalLibraries implements Name<Set<String>> {
+  private JobGlobalLibraries() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceContextActiveHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceContextActiveHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceContextActiveHandlers.java
new file mode 100644
index 0000000..716b7b9
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceContextActiveHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Handler for ActiveContext
+ */
+@NamedParameter(doc = "Handler for ActiveContext")
+public final class ServiceContextActiveHandlers implements Name<Set<EventHandler<ActiveContext>>> {
+  private ServiceContextActiveHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceContextClosedHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceContextClosedHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceContextClosedHandlers.java
new file mode 100644
index 0000000..21c4c7f
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceContextClosedHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.context.ClosedContext;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Handler for ClosedContext.
+ */
+@NamedParameter(doc = "Handler for ClosedContext")
+public final class ServiceContextClosedHandlers implements Name<Set<EventHandler<ClosedContext>>> {
+  private ServiceContextClosedHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceContextFailedHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceContextFailedHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceContextFailedHandlers.java
new file mode 100644
index 0000000..b7acf0c
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceContextFailedHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Handler for FailedContext
+ */
+@NamedParameter(doc = "Handler for FailedContext")
+public final class ServiceContextFailedHandlers implements Name<Set<EventHandler<FailedContext>>> {
+  private ServiceContextFailedHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceContextMessageHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceContextMessageHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceContextMessageHandlers.java
new file mode 100644
index 0000000..aa26a78
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceContextMessageHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.context.ContextMessage;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Context message handler.
+ */
+@NamedParameter(doc = "Context message handler.")
+public final class ServiceContextMessageHandlers implements Name<Set<EventHandler<ContextMessage>>> {
+  private ServiceContextMessageHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceDriverRestartCompletedHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceDriverRestartCompletedHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceDriverRestartCompletedHandlers.java
new file mode 100644
index 0000000..106783a
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceDriverRestartCompletedHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.runtime.common.DriverRestartCompleted;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Service handler for driver restart completed event
+ */
+@NamedParameter(doc = "Handler for driver restart completed event")
+public final class ServiceDriverRestartCompletedHandlers implements Name<Set<EventHandler<DriverRestartCompleted>>> {
+  private ServiceDriverRestartCompletedHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceDriverRestartContextActiveHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceDriverRestartContextActiveHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceDriverRestartContextActiveHandlers.java
new file mode 100644
index 0000000..eb7debf
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceDriverRestartContextActiveHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Handler for ActiveContext received during driver restart
+ */
+@NamedParameter(doc = "Handler for ActiveContext received during driver restart")
+public final class ServiceDriverRestartContextActiveHandlers implements Name<Set<EventHandler<ActiveContext>>> {
+  private ServiceDriverRestartContextActiveHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceDriverRestartTaskRunningHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceDriverRestartTaskRunningHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceDriverRestartTaskRunningHandlers.java
new file mode 100644
index 0000000..4f0b6b6
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceDriverRestartTaskRunningHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.task.RunningTask;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Running task handler during driver restart.
+ */
+@NamedParameter(doc = "Running task handler during driver restart.")
+public final class ServiceDriverRestartTaskRunningHandlers implements Name<Set<EventHandler<RunningTask>>> {
+  private ServiceDriverRestartTaskRunningHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceEvaluatorAllocatedHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceEvaluatorAllocatedHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceEvaluatorAllocatedHandlers.java
new file mode 100644
index 0000000..17748b9
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceEvaluatorAllocatedHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Called when an allocated evaluator is given to the client.
+ */
+@NamedParameter(doc = "Called when an allocated evaluator is given to the client.")
+public final class ServiceEvaluatorAllocatedHandlers implements Name<Set<EventHandler<AllocatedEvaluator>>> {
+  private ServiceEvaluatorAllocatedHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceEvaluatorCompletedHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceEvaluatorCompletedHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceEvaluatorCompletedHandlers.java
new file mode 100644
index 0000000..929af2a
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceEvaluatorCompletedHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.evaluator.CompletedEvaluator;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Called when an exception occurs on a running evaluator.
+ */
+@NamedParameter(doc = "Called when an exception occurs on a running evaluator.")
+public final class ServiceEvaluatorCompletedHandlers implements Name<Set<EventHandler<CompletedEvaluator>>> {
+  private ServiceEvaluatorCompletedHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceEvaluatorFailedHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceEvaluatorFailedHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceEvaluatorFailedHandlers.java
new file mode 100644
index 0000000..e182e2c
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceEvaluatorFailedHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.evaluator.FailedEvaluator;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Called when an exception occurs on a running evaluator.
+ */
+@NamedParameter(doc = "Called when an exception occurs on a running evaluator.")
+public final class ServiceEvaluatorFailedHandlers implements Name<Set<EventHandler<FailedEvaluator>>> {
+  private ServiceEvaluatorFailedHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskCompletedHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskCompletedHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskCompletedHandlers.java
new file mode 100644
index 0000000..71f6675
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskCompletedHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.task.CompletedTask;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Completed task handler.
+ */
+@NamedParameter(doc = "Completed task handler.")
+public final class ServiceTaskCompletedHandlers implements Name<Set<EventHandler<CompletedTask>>> {
+  private ServiceTaskCompletedHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskFailedHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskFailedHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskFailedHandlers.java
new file mode 100644
index 0000000..b549d55
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskFailedHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.task.FailedTask;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Task failure handler.
+ */
+@NamedParameter(doc = "Task failure handler.")
+public final class ServiceTaskFailedHandlers implements Name<Set<EventHandler<FailedTask>>> {
+  private ServiceTaskFailedHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskMessageHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskMessageHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskMessageHandlers.java
new file mode 100644
index 0000000..4dd94c0
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskMessageHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.task.TaskMessage;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Task message handler.
+ */
+@NamedParameter(doc = "Task message handler.")
+public final class ServiceTaskMessageHandlers implements Name<Set<EventHandler<TaskMessage>>> {
+  private ServiceTaskMessageHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskRunningHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskRunningHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskRunningHandlers.java
new file mode 100644
index 0000000..b1c513d
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskRunningHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.task.RunningTask;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Running task handler.
+ */
+@NamedParameter(doc = "Running task handler.")
+public final class ServiceTaskRunningHandlers implements Name<Set<EventHandler<RunningTask>>> {
+  private ServiceTaskRunningHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskSuspendedHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskSuspendedHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskSuspendedHandlers.java
new file mode 100644
index 0000000..735dc15
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ServiceTaskSuspendedHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.task.SuspendedTask;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Suspended task handler.
+ */
+@NamedParameter(doc = "Suspended task handler.")
+public final class ServiceTaskSuspendedHandlers implements Name<Set<EventHandler<SuspendedTask>>> {
+  private ServiceTaskSuspendedHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskCompletedHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskCompletedHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskCompletedHandlers.java
new file mode 100644
index 0000000..60297e3
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskCompletedHandlers.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.task.CompletedTask;
+import org.apache.reef.runtime.common.driver.defaults.DefaultTaskCompletionHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Completed task handler.
+ */
+@NamedParameter(doc = "Completed task handler.", default_classes = DefaultTaskCompletionHandler.class)
+public final class TaskCompletedHandlers implements Name<Set<EventHandler<CompletedTask>>> {
+  private TaskCompletedHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskFailedHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskFailedHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskFailedHandlers.java
new file mode 100644
index 0000000..21783fa
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskFailedHandlers.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.task.FailedTask;
+import org.apache.reef.runtime.common.driver.defaults.DefaultTaskFailureHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Task failure handler.
+ */
+@NamedParameter(doc = "Task failure handler.", default_classes = DefaultTaskFailureHandler.class)
+public final class TaskFailedHandlers implements Name<Set<EventHandler<FailedTask>>> {
+  private TaskFailedHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskMessageHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskMessageHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskMessageHandlers.java
new file mode 100644
index 0000000..16c4192
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskMessageHandlers.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.task.TaskMessage;
+import org.apache.reef.runtime.common.driver.defaults.DefaultTaskMessageHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Task message handler.
+ */
+@NamedParameter(doc = "Task message handler.", default_classes = DefaultTaskMessageHandler.class)
+public final class TaskMessageHandlers implements Name<Set<EventHandler<TaskMessage>>> {
+  private TaskMessageHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskRunningHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskRunningHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskRunningHandlers.java
new file mode 100644
index 0000000..61d9da5
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskRunningHandlers.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.task.RunningTask;
+import org.apache.reef.runtime.common.driver.defaults.DefaultTaskRunningHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Running task handler.
+ */
+@NamedParameter(doc = "Running task handler.", default_classes = DefaultTaskRunningHandler.class)
+public final class TaskRunningHandlers implements Name<Set<EventHandler<RunningTask>>> {
+  private TaskRunningHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskSuspendedHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskSuspendedHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskSuspendedHandlers.java
new file mode 100644
index 0000000..8105e76
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/TaskSuspendedHandlers.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.task.SuspendedTask;
+import org.apache.reef.runtime.common.driver.defaults.DefaultTaskSuspensionHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Suspended task handler.
+ */
+@NamedParameter(doc = "Suspended task handler.", default_classes = DefaultTaskSuspensionHandler.class)
+public final class TaskSuspendedHandlers implements Name<Set<EventHandler<SuspendedTask>>> {
+  private TaskSuspendedHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/package-info.java
new file mode 100644
index 0000000..87901e2
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Named parameters used by the Driver
+ */
+package org.apache.reef.driver.parameters;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/CompletedTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/CompletedTask.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/CompletedTask.java
new file mode 100644
index 0000000..8ae9c75
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/CompletedTask.java
@@ -0,0 +1,46 @@
+/**
+ * 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.reef.driver.task;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.io.Message;
+import org.apache.reef.io.naming.Identifiable;
+
+/**
+ * Represents a completed Task.
+ */
+@DriverSide
+@Public
+@Provided
+public interface CompletedTask extends Message, Identifiable {
+
+  /**
+   * @return the context the Task ran on.
+   */
+  public ActiveContext getActiveContext();
+
+  /**
+   * @return the id of the completed task.
+   */
+  @Override
+  public String getId();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/FailedTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/FailedTask.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/FailedTask.java
new file mode 100644
index 0000000..a1934e3
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/FailedTask.java
@@ -0,0 +1,75 @@
+/**
+ * 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.reef.driver.task;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.common.AbstractFailure;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.util.Optional;
+
+/**
+ * An error message that REEF Driver gets from a failed Task.
+ */
+@DriverSide
+@Provided
+@Public
+public final class FailedTask extends AbstractFailure {
+
+  /**
+   * (Optional) Context of the failed Task.
+   */
+  private final Optional<ActiveContext> context;
+
+  /**
+   * @param id          Identifier of the entity that produced the error. Cannot be null.
+   * @param message     One-line error message. Cannot be null.
+   * @param description Long error description. Can be null.
+   * @param cause       Java Exception that caused the error. Can be null.
+   * @param data        byte array that contains serialized version of the error. Can be null.
+   * @param context     the Context the Task failed on.
+   */
+  public FailedTask(final String id,
+                    final String message,
+                    final Optional<String> description,
+                    final Optional<Throwable> cause,
+                    final Optional<byte[]> data,
+                    final Optional<ActiveContext> context) {
+    super(id, message, description, cause, data);
+    this.context = context;
+  }
+
+
+  /**
+   * Access the context the task ran (and crashed) on, if it could be recovered.
+   * <p/>
+   * An ActiveContext is given when the task fails but the context remains alive.
+   * On context failure, the context also fails and is surfaced via the FailedContext event.
+   * <p/>
+   * Note that receiving an ActiveContext here is no guarantee that the context (and evaluator)
+   * are in a consistent state. Application developers need to investigate the reason available
+   * via getCause() to make that call.
+   *
+   * @return the context the Task ran on.
+   */
+  public Optional<ActiveContext> getActiveContext() {
+    return this.context;
+  }
+}


[04/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestRetainedEvaluators.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestRetainedEvaluators.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestRetainedEvaluators.java
new file mode 100644
index 0000000..36397f5
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestRetainedEvaluators.java
@@ -0,0 +1,81 @@
+/**
+ * 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.reef.tests.examples;
+
+import org.apache.reef.examples.library.Command;
+import org.apache.reef.examples.retained_eval.JobClient;
+import org.apache.reef.examples.retained_eval.Launch;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Configurations;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.LocalTestEnvironment;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * An integration test for retained evaluators: Run a simple `echo` on a couple of Evaluators a few times and make sure
+ * it comes back.
+ */
+public final class TestRetainedEvaluators {
+  /**
+   * Message to print in (remote) shells.
+   */
+  private static final String MESSAGE = "Hello REEF";
+
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  /**
+   * @return the Configuration for Launch for this test.
+   */
+  private static Configuration getLaunchConfiguration() {
+    return Tang.Factory.getTang().newConfigurationBuilder()
+        .bindNamedParameter(Launch.NumEval.class, "" + (LocalTestEnvironment.NUMBER_OF_THREADS - 1))
+        .bindNamedParameter(Launch.NumRuns.class, "2")
+        .bindNamedParameter(Command.class, "echo " + MESSAGE)
+        .build();
+  }
+
+  @Before
+  public void setUp() throws Exception {
+    this.testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  @Test
+  public void testRetainedEvaluators() throws InjectionException {
+    final Configuration clientConfiguration = Configurations.merge(
+        JobClient.getClientConfiguration(),        // The special job client.
+        getLaunchConfiguration(),                  // Specific configuration for this job
+        testEnvironment.getRuntimeConfiguration()  // The runtime we shall use
+    );
+
+    final String result = Launch.run(clientConfiguration);
+    Assert.assertNotNull(result);
+    Assert.assertTrue(result.contains(MESSAGE));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/package-info.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/package-info.java
new file mode 100644
index 0000000..526a0af
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Tests of the REEF Examples
+ */
+package org.apache.reef.tests.examples;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/DriverFailOnFailTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/DriverFailOnFailTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/DriverFailOnFailTest.java
new file mode 100644
index 0000000..060d04c
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/DriverFailOnFailTest.java
@@ -0,0 +1,71 @@
+/**
+ * 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.reef.tests.fail;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestDriverLauncher;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.tests.TestUtils;
+import org.apache.reef.tests.fail.driver.DriverFailOnFail;
+import org.apache.reef.tests.library.exceptions.SimulatedDriverFailure;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Run FailDriver with different types of failures.
+ */
+public final class DriverFailOnFailTest {
+
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  @Test
+  public void testDriverFailOnFail() throws BindException, InjectionException {
+
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    final Configuration driverConfig = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(this.getClass()))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "Fail2")
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, DriverFailOnFail.AllocatedEvaluatorHandler.class)
+        .set(DriverConfiguration.ON_TASK_FAILED, DriverFailOnFail.FailedTaskHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_STARTED, DriverFailOnFail.StartHandler.class)
+        .build();
+
+    TestUtils.assertLauncherFailure(
+        TestDriverLauncher.getLauncher(runtimeConfiguration).run(
+            driverConfig, this.testEnvironment.getTestTimeout()),
+        SimulatedDriverFailure.class);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/FailDriverDelayedMsgTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/FailDriverDelayedMsgTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/FailDriverDelayedMsgTest.java
new file mode 100644
index 0000000..125ceaf
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/FailDriverDelayedMsgTest.java
@@ -0,0 +1,73 @@
+/**
+ * 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.reef.tests.fail;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestDriverLauncher;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.tests.fail.driver.FailDriverDelayedMsg;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Run FailDriver with different types of failures.
+ */
+public class FailDriverDelayedMsgTest {
+
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  @Test
+  public void testFailDriverTestMessage() throws BindException, InjectionException {
+
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    final Configuration driverConfig = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(this.getClass()))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "FailDriverDelayedMsg")
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, FailDriverDelayedMsg.AllocatedEvaluatorHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_ACTIVE, FailDriverDelayedMsg.ActiveContextHandler.class)
+        .set(DriverConfiguration.ON_TASK_RUNNING, FailDriverDelayedMsg.RunningTaskHandler.class)
+        .set(DriverConfiguration.ON_TASK_MESSAGE, FailDriverDelayedMsg.TaskMessageHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_STARTED, FailDriverDelayedMsg.StartHandler.class)
+        .build();
+
+    final LauncherStatus status = TestDriverLauncher.getLauncher(runtimeConfiguration)
+        .run(driverConfig, this.testEnvironment.getTestTimeout());
+
+    Assert.assertEquals(LauncherStatus.COMPLETED, status);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/FailDriverTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/FailDriverTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/FailDriverTest.java
new file mode 100644
index 0000000..1539e23
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/FailDriverTest.java
@@ -0,0 +1,133 @@
+/**
+ * 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.reef.tests.fail;
+
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.CompletedEvaluator;
+import org.apache.reef.driver.task.CompletedTask;
+import org.apache.reef.driver.task.RunningTask;
+import org.apache.reef.driver.task.SuspendedTask;
+import org.apache.reef.driver.task.TaskMessage;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.tests.TestUtils;
+import org.apache.reef.tests.fail.driver.FailClient;
+import org.apache.reef.tests.fail.driver.FailDriver;
+import org.apache.reef.tests.library.exceptions.SimulatedDriverFailure;
+import org.apache.reef.wake.time.event.Alarm;
+import org.apache.reef.wake.time.event.StartTime;
+import org.apache.reef.wake.time.event.StopTime;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Run FailDriver with different types of failures.
+ */
+public class FailDriverTest {
+
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  private void failOn(final Class<?> clazz) throws BindException, InjectionException {
+    TestUtils.assertLauncherFailure(
+        FailClient.run(clazz,
+            this.testEnvironment.getRuntimeConfiguration(), this.testEnvironment.getTestTimeout()),
+        SimulatedDriverFailure.class);
+  }
+
+  @Test
+  public void testFailDriverConstructor() throws BindException, InjectionException {
+    failOn(FailDriver.class);
+  }
+
+  @Test
+  public void testFailDriverStart() throws BindException, InjectionException {
+    failOn(StartTime.class);
+  }
+
+  @Test
+  public void testFailDriverAllocatedEvaluator() throws BindException, InjectionException {
+    failOn(AllocatedEvaluator.class);
+  }
+
+  @Test
+  public void testFailDriverActiveContext() throws BindException, InjectionException {
+    failOn(ActiveContext.class);
+  }
+
+  @Test
+  public void testFailDriverRunningTask() throws BindException, InjectionException {
+    failOn(RunningTask.class);
+  }
+
+  @Test
+  public void testFailDriverTaskMessage() throws BindException, InjectionException {
+    failOn(TaskMessage.class);
+  }
+
+  @Test
+  public void testFailDriverSuspendedTask() throws BindException, InjectionException {
+    failOn(SuspendedTask.class);
+  }
+
+  @Test
+  public void testFailDriverCompletedTask() throws BindException, InjectionException {
+    failOn(CompletedTask.class);
+  }
+
+  @Test
+  public void testFailDriverCompletedEvaluator() throws BindException, InjectionException {
+    failOn(CompletedEvaluator.class);
+  }
+
+  @Test
+  public void testFailDriverAlarm() throws BindException, InjectionException {
+    failOn(Alarm.class);
+  }
+
+  @Test
+  public void testFailDriverStop() throws BindException, InjectionException {
+    failOn(StopTime.class);
+  }
+
+  @Test
+  public void testDriverCompleted() throws BindException, InjectionException {
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+    // FailDriverTest can be replaced with any other class never used in FailDriver
+    final LauncherStatus status = FailClient.run(
+        FailDriverTest.class, runtimeConfiguration, this.testEnvironment.getTestTimeout());
+    Assert.assertEquals(LauncherStatus.COMPLETED, status);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/FailTaskTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/FailTaskTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/FailTaskTest.java
new file mode 100644
index 0000000..41dd040
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/FailTaskTest.java
@@ -0,0 +1,93 @@
+/**
+ * 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.reef.tests.fail;
+
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.task.Task;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.tests.TestUtils;
+import org.apache.reef.tests.fail.task.*;
+import org.apache.reef.tests.library.exceptions.SimulatedTaskFailure;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Run Driver with different types of failures in the Task.
+ */
+public final class FailTaskTest {
+
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  private void failOn(
+      final Class<? extends Task> failTaskClass) throws BindException, InjectionException {
+    TestUtils.assertLauncherFailure(
+        Client.run(failTaskClass,
+            this.testEnvironment.getRuntimeConfiguration(),
+            this.testEnvironment.getTestTimeout()),
+        SimulatedTaskFailure.class);
+  }
+
+  @Test
+  public void testFailTask() throws BindException, InjectionException {
+    failOn(FailTask.class);
+  }
+
+  @Test
+  public void testFailTaskCall() throws BindException, InjectionException {
+    failOn(FailTaskCall.class);
+  }
+
+  @Test
+  public void testFailTaskMsg() throws BindException, InjectionException {
+    failOn(FailTaskMsg.class);
+  }
+
+  @Test
+  public void testFailTaskSuspend() throws BindException, InjectionException {
+    failOn(FailTaskSuspend.class);
+  }
+
+  @Test
+  public void testFailTaskStart() throws BindException, InjectionException {
+    failOn(FailTaskStart.class);
+  }
+
+  @Test
+  public void testFailTaskStop() throws BindException, InjectionException {
+    failOn(FailTaskStop.class);
+  }
+
+  @Test
+  public void testFailTaskClose() throws BindException, InjectionException {
+    failOn(FailTaskClose.class);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/FailTestSuite.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/FailTestSuite.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/FailTestSuite.java
new file mode 100644
index 0000000..eeddd9a
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/fail/FailTestSuite.java
@@ -0,0 +1,32 @@
+/**
+ * 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.reef.tests.fail;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+//    FailTaskTest.class,
+    FailDriverTest.class,
+    FailDriverDelayedMsgTest.class,
+    DriverFailOnFailTest.class
+})
+public final class FailTestSuite {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTest.java
new file mode 100644
index 0000000..1eab054
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTest.java
@@ -0,0 +1,144 @@
+/**
+ * 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.reef.tests.files;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.io.TempFileCreator;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Configurations;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Tests whether a set of files makes it to the Driver and from there to the Evaluator.
+ * <p/>
+ * The test is shallow: It only makes sure that files with the same (random) names exist. It doesn't check for file
+ * contents.
+ */
+public final class FileResourceTest {
+  private static final Logger LOG = Logger.getLogger(FileResourceTest.class.getName());
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+  /**
+   * The number of files to generate.
+   */
+  private final int nFiles = 3;
+
+  /**
+   * Assembles the driver configuration using the DriverConfiguration class.
+   *
+   * @param theFiles
+   * @return
+   * @throws BindException
+   */
+  private static Configuration getDriverConfiguration(final Set<File> theFiles) throws BindException {
+    ConfigurationModule driverConfigurationModule = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(FileResourceTestDriver.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_FileResourceTest")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, FileResourceTestDriver.StartHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, FileResourceTestDriver.EvaluatorAllocatedHandler.class);
+
+    for (final File f : theFiles) {
+      LOG.log(Level.FINEST, "Adding a file to the DriverConfiguration: " + f.getAbsolutePath());
+      driverConfigurationModule = driverConfigurationModule.set(DriverConfiguration.LOCAL_FILES, f.getAbsolutePath());
+    }
+    return driverConfigurationModule.build();
+  }
+
+  /**
+   * Assembles the configuration based on TestDriverConfiguration
+   *
+   * @param theFiles
+   * @return
+   * @throws BindException
+   * @throws IOException
+   */
+  private static Configuration getTestDriverConfiguration(final Set<File> theFiles) throws BindException, IOException {
+    ConfigurationModule testDriverConfigurationModule = FileResourceTestDriverConfiguration.CONF;
+    for (final File f : theFiles) {
+      LOG.log(Level.FINEST, "Adding a file to the TestDriverConfiguration: " + f.getName());
+      testDriverConfigurationModule = testDriverConfigurationModule.set(FileResourceTestDriverConfiguration.EXPECTED_FILE_NAME, f.getName());
+    }
+
+    final Configuration testDriverConfiguration = testDriverConfigurationModule.build();
+    return testDriverConfiguration;
+  }
+
+  /**
+   * Creates the given number of temp files.
+   *
+   * @param n
+   * @return
+   * @throws IOException
+   */
+  private Set<File> getTempFiles(final int n) throws IOException, InjectionException {
+    final TempFileCreator tempFileCreator = Tang.Factory.getTang()
+        .newInjector(testEnvironment.getRuntimeConfiguration())
+        .getInstance(TempFileCreator.class);
+    final Set<File> theFiles = new HashSet<>();
+    for (int i = 0; i < n; ++i) {
+      final File tempFile = tempFileCreator.createTempFile("REEF_TEST_", ".tmp");
+      tempFile.deleteOnExit();
+      theFiles.add(tempFile);
+    }
+    return theFiles;
+  }
+
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  @Test
+  public void testDriverFiles() throws IOException, BindException, InjectionException {
+
+    final Set<File> theFiles = getTempFiles(this.nFiles);
+    final Configuration finalDriverConfiguration = Configurations.merge(
+        getDriverConfiguration(theFiles), getTestDriverConfiguration(theFiles));
+
+    final LauncherStatus status = DriverLauncher
+        .getLauncher(this.testEnvironment.getRuntimeConfiguration())
+        .run(finalDriverConfiguration, testEnvironment.getTestTimeout());
+
+    Assert.assertTrue("Job state after execution: " + status, status.isSuccess());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTestDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTestDriver.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTestDriver.java
new file mode 100644
index 0000000..ba88573
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTestDriver.java
@@ -0,0 +1,127 @@
+/**
+ * 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.reef.tests.files;
+
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.runtime.common.files.REEFFileNames;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Configurations;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+final class FileResourceTestDriver {
+
+  private static final Logger LOG = Logger.getLogger(FileResourceTestDriver.class.getName());
+
+  private final Set<String> fileNamesToExpect;
+  private final EvaluatorRequestor requestor;
+  private final REEFFileNames fileNames;
+  private final File localFolder;
+
+  @Inject
+  public FileResourceTestDriver(@Parameter(FileResourceTestDriverConfiguration.FileNamesToExpect.class) final Set<String> fileNamesToExpect,
+                                final EvaluatorRequestor requestor,
+                                final REEFFileNames fileNames) {
+    this.fileNamesToExpect = fileNamesToExpect;
+    this.requestor = requestor;
+    this.fileNames = fileNames;
+    this.localFolder = fileNames.getLocalFolder();
+  }
+
+  /**
+   * Check that all given files are accesible.
+   */
+  final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime startTime) {
+      LOG.log(Level.INFO, "StartTime: {0} Number of files in the set: {1}",
+          new Object[]{startTime, FileResourceTestDriver.this.fileNamesToExpect.size()});
+
+      // Check whether the files made it
+      for (final String fileName : FileResourceTestDriver.this.fileNamesToExpect) {
+        final File file = new File(localFolder, fileName);
+        LOG.log(Level.INFO, "Testing file: " + file.getAbsolutePath());
+        if (!file.exists()) {
+          throw new DriverSideFailure("Cannot find file: " + fileName);
+        } else if (!file.isFile()) {
+          throw new DriverSideFailure("Not a file: " + fileName);
+        } else if (!file.canRead()) {
+          throw new DriverSideFailure("Can't read: " + fileName);
+        }
+      }
+
+      // Ask for a single evaluator.
+      FileResourceTestDriver.this.requestor.submit(EvaluatorRequest.newBuilder()
+          .setNumber(1).setMemory(64).setNumberOfCores(1).build());
+    }
+  }
+
+  /**
+   * Copy files to the Evaluator and submit a Task that checks that they made it.
+   */
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+
+    @Override
+    public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+      try {
+        // Add the files to the Evaluator.
+        for (final String fileName : FileResourceTestDriver.this.fileNamesToExpect) {
+          allocatedEvaluator.addFile(new File(localFolder, fileName));
+        }
+
+        // Filling out a TaskConfiguration
+        final Configuration taskConfiguration = TaskConfiguration.CONF
+            .set(TaskConfiguration.IDENTIFIER, "TestTask")
+            .set(TaskConfiguration.TASK, FileResourceTestTask.class)
+            .build();
+
+        // Adding the job-specific Configuration
+        ConfigurationModule testTaskConfigurationModule = FileResourceTestTaskConfiguration.CONF;
+        for (final String fileName : FileResourceTestDriver.this.fileNamesToExpect) {
+          testTaskConfigurationModule =
+              testTaskConfigurationModule.set(FileResourceTestTaskConfiguration.EXPECTED_FILE_NAME, fileName);
+        }
+
+        // Submit the context and the task config.
+        final Configuration finalTaskConfiguration =
+            Configurations.merge(taskConfiguration, testTaskConfigurationModule.build());
+
+        allocatedEvaluator.submitTask(finalTaskConfiguration);
+
+      } catch (final Exception e) {
+        // This fails the test.
+        throw new DriverSideFailure("Unable to submit context and task", e);
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTestDriverConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTestDriverConfiguration.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTestDriverConfiguration.java
new file mode 100644
index 0000000..e198693
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTestDriverConfiguration.java
@@ -0,0 +1,40 @@
+/**
+ * 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.reef.tests.files;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.RequiredParameter;
+
+import java.util.Set;
+
+public final class FileResourceTestDriverConfiguration extends ConfigurationModuleBuilder {
+
+  public static final RequiredParameter<String> EXPECTED_FILE_NAME = new RequiredParameter<>();
+  public static final ConfigurationModule CONF = new FileResourceTestDriverConfiguration()
+      .bindSetEntry(FileNamesToExpect.class, EXPECTED_FILE_NAME)
+      .build();
+
+  @NamedParameter(doc = "The names of the files to expect in the local filesystem.")
+  public static final class FileNamesToExpect implements Name<Set<String>> {
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTestTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTestTask.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTestTask.java
new file mode 100644
index 0000000..a7a62a7
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTestTask.java
@@ -0,0 +1,67 @@
+/**
+ * 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.reef.tests.files;
+
+import org.apache.reef.runtime.common.files.REEFFileNames;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.task.Task;
+import org.apache.reef.tests.library.exceptions.TaskSideFailure;
+import org.apache.reef.wake.time.Clock;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * An Task that checks the presence of a set of files and throws TaskSideFailure if they cannot be found or read.
+ */
+final class FileResourceTestTask implements Task {
+  private final Logger LOG = Logger.getLogger(FileResourceTestTask.class.getName());
+  private final Set<String> expectedFileNames;
+  private final Clock clock;
+  private final File localFolder;
+
+  @Inject
+  FileResourceTestTask(@Parameter(FileResourceTestTaskConfiguration.FileNamesToExpect.class) final Set<String> expectedFileNames,
+                       final Clock clock,
+                       final REEFFileNames fileNames) {
+    this.expectedFileNames = expectedFileNames;
+    this.clock = clock;
+    this.localFolder = fileNames.getLocalFolder();
+  }
+
+  @Override
+  public byte[] call(byte[] memento) throws Exception {
+    for (final String fileName : expectedFileNames) {
+      final File file = new File(localFolder, fileName);
+      LOG.log(Level.INFO, "Testing file: " + file.getAbsolutePath());
+      if (!file.exists()) {
+        throw new TaskSideFailure("Cannot find file: " + fileName);
+      } else if (!file.isFile()) {
+        throw new TaskSideFailure("Not a file: " + fileName);
+      } else if (!file.canRead()) {
+        throw new TaskSideFailure("Can't read: " + fileName);
+      }
+    }
+
+    return new byte[0];  //To change body of implemented methods use File | Settings | File Templates.
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTestTaskConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTestTaskConfiguration.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTestTaskConfiguration.java
new file mode 100644
index 0000000..fd6b9e6
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/FileResourceTestTaskConfiguration.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.tests.files;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.RequiredParameter;
+
+import java.util.Set;
+
+/**
+ * A ConfigurationModule for the TestTask.
+ */
+public final class FileResourceTestTaskConfiguration extends ConfigurationModuleBuilder {
+  /**
+   * the set of file names to expect present on the evaluator.
+   */
+  public static final RequiredParameter<String> EXPECTED_FILE_NAME = new RequiredParameter<>();
+  public static final ConfigurationModule CONF = new FileResourceTestTaskConfiguration()
+      .bindSetEntry(FileNamesToExpect.class, EXPECTED_FILE_NAME)
+      .build();
+
+  @NamedParameter(doc = "The names of the files to expect in the local filesystem.")
+  public static final class FileNamesToExpect implements Name<Set<String>> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/package-info.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/package-info.java
new file mode 100644
index 0000000..5e833fa
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/files/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Tests whether a set of files makes it to the Driver and from there to the Evaluator.
+ */
+package org.apache.reef.tests.files;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/messaging/driver/DriverMessagingTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/messaging/driver/DriverMessagingTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/messaging/driver/DriverMessagingTest.java
new file mode 100644
index 0000000..cf43a58
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/messaging/driver/DriverMessagingTest.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.reef.tests.messaging.driver;
+
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public final class DriverMessagingTest {
+
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  @Test
+  public void testDriverMessaging() throws BindException, InjectionException {
+    final LauncherStatus status = DriverMessaging.run(
+        this.testEnvironment.getRuntimeConfiguration(), this.testEnvironment.getTestTimeout());
+    Assert.assertTrue("Job state after execution: " + status, status.isSuccess());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/messaging/driver/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/messaging/driver/package-info.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/messaging/driver/package-info.java
new file mode 100644
index 0000000..b5016f5
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/messaging/driver/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Tests the messaging channel between client and driver.
+ */
+package org.apache.reef.tests.messaging.driver;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/messaging/task/TaskMessagingTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/messaging/task/TaskMessagingTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/messaging/task/TaskMessagingTest.java
new file mode 100644
index 0000000..4b656da
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/messaging/task/TaskMessagingTest.java
@@ -0,0 +1,72 @@
+/**
+ * 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.reef.tests.messaging.task;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.tests.library.driver.OnDriverStartedAllocateOne;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test message exchange between the Task and the Driver.
+ */
+public final class TaskMessagingTest {
+
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  @Test
+  public void testTaskMsg() throws BindException, InjectionException {
+
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    final Configuration driverConfig = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(this.getClass()))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "DriverTaskMsg")
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, TaskMessagingDriver.EvaluatorAllocatedHandler.class)
+        .set(DriverConfiguration.ON_TASK_RUNNING, TaskMessagingDriver.TaskRunningHandler.class)
+        .set(DriverConfiguration.ON_TASK_MESSAGE, TaskMessagingDriver.TaskMessageHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_STARTED, OnDriverStartedAllocateOne.class)
+        .build();
+
+    final LauncherStatus status = DriverLauncher.getLauncher(runtimeConfiguration)
+        .run(driverConfig, this.testEnvironment.getTestTimeout());
+
+    Assert.assertEquals(LauncherStatus.COMPLETED, status);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/messaging/task/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/messaging/task/package-info.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/messaging/task/package-info.java
new file mode 100644
index 0000000..c3b1c4b
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/messaging/task/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Tests the messaging channel between driver and task.
+ */
+package org.apache.reef.tests.messaging.task;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/ActiveContextHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/ActiveContextHandler.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/ActiveContextHandler.java
new file mode 100644
index 0000000..87b433f
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/ActiveContextHandler.java
@@ -0,0 +1,63 @@
+/**
+ * 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.reef.tests.multipleEventHandlerInstances;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The ActiveContext handler
+ */
+public final class ActiveContextHandler implements EventHandler<ActiveContext> {
+
+  private static final Logger LOG = Logger.getLogger(ActiveContextHandler.class.getName());
+
+  private static int countInstances = 0;
+
+  @Inject
+  public ActiveContextHandler() {
+    ++countInstances;
+    if (countInstances > 1) {
+      throw new DriverSideFailure("Expect ActiveContextHandler to be created only once");
+    }
+  }
+
+  @Override
+  public void onNext(ActiveContext activeContext) {
+    LOG.log(Level.FINEST, "ActiveContext received. Submitting empty task to it");
+    Configuration taskConfiguration;
+    try {
+      taskConfiguration = TaskConfiguration.CONF
+          .set(TaskConfiguration.IDENTIFIER, "EmptyREEFTask")
+          .set(TaskConfiguration.TASK, EmptyTask.class)
+          .build();
+    } catch (BindException e) {
+      throw new RuntimeException("Unable to setup Task configuration", e);
+    }
+    activeContext.submitTask(taskConfiguration);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/AllocatedEvaluatorHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/AllocatedEvaluatorHandler.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/AllocatedEvaluatorHandler.java
new file mode 100644
index 0000000..16ce4bb
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/AllocatedEvaluatorHandler.java
@@ -0,0 +1,60 @@
+/**
+ * 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.reef.tests.multipleEventHandlerInstances;
+
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The allocated evaluator handler
+ */
+public final class AllocatedEvaluatorHandler implements EventHandler<AllocatedEvaluator> {
+
+  private static final Logger LOG = Logger.getLogger(AllocatedEvaluatorHandler.class.getName());
+
+  private static int countInstances = 0;
+
+  @Inject
+  public AllocatedEvaluatorHandler() {
+    ++countInstances;
+    if (countInstances > 1)
+      throw new DriverSideFailure("Expect AllocatedEvaluatorHandler to be created only once");
+  }
+
+  @Override
+  public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+    LOG.log(Level.INFO, "Submitting empty context to AllocatedEvaluator: {0}", allocatedEvaluator);
+    try {
+      final Configuration contextConfiguration = ContextConfiguration.CONF
+          .set(ContextConfiguration.IDENTIFIER, "EmptyREEFContext")
+          .build();
+      allocatedEvaluator.submitContext(contextConfiguration);
+    } catch (final BindException ex) {
+      throw new RuntimeException("Unable to setup Task or Context configuration.", ex);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/Client.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/Client.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/Client.java
new file mode 100644
index 0000000..5345fe6
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/Client.java
@@ -0,0 +1,76 @@
+/**
+ * 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.reef.tests.multipleEventHandlerInstances;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.logging.Logger;
+
+/**
+ *
+ */
+public class Client {
+  private static final Logger LOG = Logger.getLogger(Client.class.getName());
+
+  /**
+   * Number of milliseconds to wait for the job to complete.
+   */
+  private static final int JOB_TIMEOUT = 300000; // 10 sec.
+
+  public static LauncherStatus runReefJob(final Configuration runtimeConf, final int timeOut)
+      throws BindException, InjectionException {
+
+    final Configuration driverConf = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(StartHandler.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "MultipleHandlerInstances")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, StartHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, AllocatedEvaluatorHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_ACTIVE, ActiveContextHandler.class)
+        .set(DriverConfiguration.ON_TASK_RUNNING, RunningTaskHandler.class)
+        .set(DriverConfiguration.ON_TASK_COMPLETED, CompletedTaskHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_CLOSED, ClosedContextHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_COMPLETED, CompletedEvaluatorHandler.class)
+        .build();
+
+    return DriverLauncher.getLauncher(runtimeConf).run(driverConf, timeOut);
+  }
+
+  /**
+   * @param args command line parameters.
+   * @throws BindException      configuration error.
+   * @throws InjectionException configuration error.
+   */
+  @Test
+  public void testMultipleInstances() throws BindException, InjectionException {
+    final Configuration runtimeConfiguration = LocalRuntimeConfiguration.CONF
+        .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, 2)
+        .build();
+    final LauncherStatus status = runReefJob(runtimeConfiguration, JOB_TIMEOUT);
+    Assert.assertTrue("Reef Job MultipleHandlerInstances failed: " + status, status.isSuccess());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/ClosedContextHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/ClosedContextHandler.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/ClosedContextHandler.java
new file mode 100644
index 0000000..1e245e9
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/ClosedContextHandler.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.reef.tests.multipleEventHandlerInstances;
+
+import org.apache.reef.driver.context.ClosedContext;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ */
+public class ClosedContextHandler implements EventHandler<ClosedContext> {
+
+  private static final Logger LOG = Logger.getLogger(ClosedContextHandler.class.getName());
+
+  private static int countInstances = 0;
+
+  @Inject
+  public ClosedContextHandler() {
+    ++countInstances;
+    if (countInstances > 1) {
+      throw new DriverSideFailure("Expect ClosedContextHandler to be created only once");
+    }
+  }
+
+  @Override
+  public void onNext(ClosedContext closedContext) {
+    LOG.log(Level.FINEST, "Received a closed context");
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/CompletedEvaluatorHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/CompletedEvaluatorHandler.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/CompletedEvaluatorHandler.java
new file mode 100644
index 0000000..59c5134
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/CompletedEvaluatorHandler.java
@@ -0,0 +1,52 @@
+/**
+ * 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.reef.tests.multipleEventHandlerInstances;
+
+import org.apache.reef.driver.evaluator.CompletedEvaluator;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ */
+public class CompletedEvaluatorHandler implements
+    EventHandler<CompletedEvaluator> {
+
+  private static final Logger LOG = Logger.getLogger(CompletedEvaluatorHandler.class.getName());
+
+  private static int countInstances = 0;
+
+  @Inject
+  public CompletedEvaluatorHandler() {
+    ++countInstances;
+    if (countInstances > 1) {
+      throw new DriverSideFailure("Expect CompletedEvaluatorHandler to be created only once");
+    }
+  }
+
+  @Override
+  public void onNext(CompletedEvaluator completedEvaluator) {
+    LOG.log(Level.FINEST, "Received a completed evaluator");
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/CompletedTaskHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/CompletedTaskHandler.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/CompletedTaskHandler.java
new file mode 100644
index 0000000..a85d48e
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/CompletedTaskHandler.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.reef.tests.multipleEventHandlerInstances;
+
+import org.apache.reef.driver.task.CompletedTask;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ */
+public class CompletedTaskHandler implements EventHandler<CompletedTask> {
+
+  private static final Logger LOG = Logger.getLogger(CompletedTaskHandler.class.getName());
+
+  private static int countInstances = 0;
+
+  @Inject
+  public CompletedTaskHandler() {
+    ++countInstances;
+    if (countInstances > 1)
+      throw new DriverSideFailure("Expect CompletedTaskHandler to be created only once");
+  }
+
+  @Override
+  public void onNext(CompletedTask completedTask) {
+    LOG.log(Level.FINEST, "Received a completed task");
+    completedTask.getActiveContext().close();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/EmptyTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/EmptyTask.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/EmptyTask.java
new file mode 100644
index 0000000..d1a62d9
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/EmptyTask.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.tests.multipleEventHandlerInstances;
+
+import org.apache.reef.task.Task;
+
+import javax.inject.Inject;
+
+/**
+ *
+ */
+public class EmptyTask implements Task {
+
+  @Inject
+  public EmptyTask() {
+  }
+
+  @Override
+  public byte[] call(byte[] memento) throws Exception {
+    return null;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/RunningTaskHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/RunningTaskHandler.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/RunningTaskHandler.java
new file mode 100644
index 0000000..3995ad2
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/RunningTaskHandler.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.reef.tests.multipleEventHandlerInstances;
+
+import org.apache.reef.driver.task.RunningTask;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ */
+public class RunningTaskHandler implements EventHandler<RunningTask> {
+
+  private static final Logger LOG = Logger.getLogger(RunningTaskHandler.class.getName());
+
+  private static int countInstances = 0;
+
+  @Inject
+  public RunningTaskHandler() {
+    ++countInstances;
+    if (countInstances > 1) {
+      throw new DriverSideFailure("Expect RunningTaskHandler to be created only once");
+    }
+  }
+
+  @Override
+  public void onNext(RunningTask runningTask) {
+    LOG.log(Level.FINEST, "Received a running task");
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/StartHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/StartHandler.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/StartHandler.java
new file mode 100644
index 0000000..ab0f779
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/multipleEventHandlerInstances/StartHandler.java
@@ -0,0 +1,62 @@
+/**
+ * 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.reef.tests.multipleEventHandlerInstances;
+
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The start handler
+ */
+public final class StartHandler implements EventHandler<StartTime> {
+
+  private static final Logger LOG = Logger.getLogger(StartHandler.class.getName());
+  private static int countInstances = 0;
+  private final EvaluatorRequestor requestor;
+
+  /**
+   * Job driver constructor - instantiated via TANG.
+   *
+   * @param requestor evaluator requestor object used to create new evaluator containers.
+   */
+  @Inject
+  public StartHandler(final EvaluatorRequestor requestor) {
+    this.requestor = requestor;
+    ++countInstances;
+    if (countInstances > 1)
+      throw new DriverSideFailure("Expect StartHandler be created only once");
+  }
+
+  @Override
+  public void onNext(StartTime startTime) {
+    LOG.log(Level.INFO, "StartTime: ", startTime);
+    StartHandler.this.requestor.submit(EvaluatorRequest.newBuilder()
+        .setNumber(5)
+        .setMemory(64)
+        .setNumberOfCores(1)
+        .build());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/roguethread/RogueThreadDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/roguethread/RogueThreadDriver.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/roguethread/RogueThreadDriver.java
new file mode 100644
index 0000000..52f4d2f
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/roguethread/RogueThreadDriver.java
@@ -0,0 +1,50 @@
+/**
+ * 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.reef.tests.roguethread;
+
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+
+@Unit
+final class RogueThreadDriver {
+
+
+  @Inject
+  RogueThreadDriver() {
+  }
+
+
+  final class EvaluatorAllocationHandler implements EventHandler<AllocatedEvaluator> {
+
+    @Override
+    public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+      final Configuration taskConfiguration = TaskConfiguration.CONF
+          .set(TaskConfiguration.IDENTIFIER, "RogueThreadTestTask")
+          .set(TaskConfiguration.TASK, RogueThreadTask.class)
+          .build();
+      allocatedEvaluator.submitTask(taskConfiguration);
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/roguethread/RogueThreadTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/roguethread/RogueThreadTask.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/roguethread/RogueThreadTask.java
new file mode 100644
index 0000000..b3a9f05
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/roguethread/RogueThreadTask.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.tests.roguethread;
+
+import org.apache.reef.task.Task;
+import org.apache.reef.tests.library.exceptions.ExpectedTaskException;
+
+import javax.inject.Inject;
+
+/**
+ * Spawns a thread that immediately throws a ExpectedTaskException.
+ */
+final class RogueThreadTask implements Task {
+  @Inject
+  RogueThreadTask() {
+  }
+
+  @Override
+  public byte[] call(final byte[] memento) throws Exception {
+    new Thread(new Runnable() {
+      @Override
+      public void run() {
+        throw new ExpectedTaskException("Exception from a Thread spawned by the Task.");
+      }
+    }).run();
+    return null;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/roguethread/RogueThreadTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/roguethread/RogueThreadTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/roguethread/RogueThreadTest.java
new file mode 100644
index 0000000..5799df9
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/roguethread/RogueThreadTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.reef.tests.roguethread;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.tests.library.driver.ExpectedTaskFailureHandler;
+import org.apache.reef.tests.library.driver.OnDriverStartedAllocateOne;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests whether an exception thrown by a thread spawned by Task.call() triggers a FailedTask in the Driver.
+ */
+public final class RogueThreadTest {
+
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    this.testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  @Test
+  public void testRogueThread() throws InjectionException {
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+    final Configuration driverConfiguration = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(this.getClass()))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "Test_RogueThreadTest")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, OnDriverStartedAllocateOne.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, RogueThreadDriver.EvaluatorAllocationHandler.class)
+        .set(DriverConfiguration.ON_TASK_FAILED, ExpectedTaskFailureHandler.class)
+        .build();
+    final LauncherStatus state = DriverLauncher.getLauncher(runtimeConfiguration)
+        .run(driverConfiguration, this.testEnvironment.getTestTimeout());
+
+    Assert.assertTrue("Job state after execution: " + state, state.isSuccess());
+
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/roguethread/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/roguethread/package-info.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/roguethread/package-info.java
new file mode 100644
index 0000000..83bee40
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/roguethread/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Tests whether an exception thrown by a thread spawned by Task.call() triggers a FailedTask in the Driver.
+ */
+package org.apache.reef.tests.roguethread;
\ No newline at end of file


[08/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/implementation/TestClassHierarchy.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/implementation/TestClassHierarchy.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/implementation/TestClassHierarchy.java
new file mode 100644
index 0000000..4c4c2cd
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/implementation/TestClassHierarchy.java
@@ -0,0 +1,642 @@
+/**
+ * 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.reef.tang.implementation;
+
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.*;
+import org.apache.reef.tang.exceptions.ClassHierarchyException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.exceptions.NameResolutionException;
+import org.apache.reef.tang.types.ClassNode;
+import org.apache.reef.tang.types.ConstructorDef;
+import org.apache.reef.tang.types.Node;
+import org.apache.reef.tang.util.ReflectionUtilities;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import javax.inject.Inject;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+@DefaultImplementation(String.class)
+interface BadIfaceDefault {
+}
+
+interface I1 {
+}
+
+public class TestClassHierarchy {
+  public ClassHierarchy ns;
+
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  @Before
+  public void setUp() throws Exception {
+    TangImpl.reset();
+    ns = Tang.Factory.getTang().getDefaultClassHierarchy();
+  }
+
+  public String s(Class<?> c) {
+    return ReflectionUtilities.getFullName(c);
+  }
+
+  @Test
+  public void testJavaString() throws NameResolutionException {
+    ns.getNode(ReflectionUtilities.getFullName(String.class));
+    Node n = null;
+    try {
+      n = ns.getNode("java");
+    } catch (NameResolutionException e) {
+    }
+    Assert.assertNull(n);
+    try {
+      n = ns.getNode("java.lang");
+    } catch (NameResolutionException e) {
+    }
+    Assert.assertNull(n);
+    Assert.assertNotNull(ns.getNode("java.lang.String"));
+    try {
+      ns.getNode("com.microsoft");
+      Assert.fail("Didn't get expected exception");
+    } catch (NameResolutionException e) {
+
+    }
+  }
+
+  @Test
+  public void testSimpleConstructors() throws NameResolutionException {
+    ClassNode<?> cls = (ClassNode<?>) ns.getNode(s(SimpleConstructors.class));
+    Assert.assertTrue(cls.getChildren().size() == 0);
+    ConstructorDef<?> def[] = cls.getInjectableConstructors();
+    Assert.assertEquals(3, def.length);
+  }
+
+  @Test
+  public void testNamedParameterConstructors() throws NameResolutionException {
+    ns.getNode(s(NamedParameterConstructors.class));
+  }
+
+  @Test
+  public void testArray() throws NameResolutionException {
+    thrown.expect(UnsupportedOperationException.class);
+    thrown.expectMessage("No support for arrays, etc.  Name was: [Ljava.lang.String;");
+    ns.getNode(s(new String[0].getClass()));
+  }
+
+  @Test
+  public void testRepeatConstructorArg() throws NameResolutionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("Repeated constructor parameter detected.  Cannot inject constructor org.apache.reef.tang.implementation.RepeatConstructorArg(int,int)");
+    ns.getNode(s(RepeatConstructorArg.class));
+  }
+
+  @Test
+  public void testRepeatConstructorArgClasses() throws NameResolutionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("Repeated constructor parameter detected.  Cannot inject constructor org.apache.reef.tang.implementation.RepeatConstructorArgClasses(org.apache.reef.tang.implementation.A,org.apache.reef.tang.implementation.A)");
+    ns.getNode(s(RepeatConstructorArgClasses.class));
+  }
+
+  @Test
+  public void testLeafRepeatedConstructorArgClasses() throws NameResolutionException {
+    ns.getNode(s(LeafRepeatedConstructorArgClasses.class));
+  }
+
+  @Test
+  public void testNamedRepeatConstructorArgClasses() throws NameResolutionException {
+    ns.getNode(s(NamedRepeatConstructorArgClasses.class));
+  }
+
+  @Test
+  public void testResolveDependencies() throws NameResolutionException {
+    ns.getNode(s(SimpleConstructors.class));
+    Assert.assertNotNull(ns.getNode(ReflectionUtilities
+        .getFullName(String.class)));
+  }
+
+  @Test
+  public void testDocumentedLocalNamedParameter() throws NameResolutionException {
+    ns.getNode(s(DocumentedLocalNamedParameter.class));
+  }
+
+  @Test
+  public void testNamedParameterTypeMismatch() throws NameResolutionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("Named parameter type mismatch in org.apache.reef.tang.implementation.NamedParameterTypeMismatch.  Constructor expects a java.lang.String but Foo is a java.lang.Integer");
+    ns.getNode(s(NamedParameterTypeMismatch.class));
+  }
+
+  @Test
+  public void testUnannotatedName() throws NameResolutionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("Named parameter org.apache.reef.tang.implementation.UnannotatedName is missing its @NamedParameter annotation.");
+    ns.getNode(s(UnannotatedName.class));
+  }
+
+  // TODO: The next three error messages should be more specific about the underlying cause of the failure.
+  @Test
+  public void testAnnotatedNotName() throws NameResolutionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("Found illegal @NamedParameter org.apache.reef.tang.implementation.AnnotatedNotName does not implement Name<?>");
+    ns.getNode(s(AnnotatedNotName.class));
+  }
+
+  @Test
+  public void testAnnotatedNameWrongInterface() throws NameResolutionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("Found illegal @NamedParameter org.apache.reef.tang.implementation.AnnotatedNameWrongInterface does not implement Name<?>");
+    ns.getNode(s(AnnotatedNameWrongInterface.class));
+  }
+
+  @Test
+  public void testAnnotatedNameNotGenericInterface() throws NameResolutionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("Found illegal @NamedParameter org.apache.reef.tang.implementation.AnnotatedNameNotGenericInterface does not implement Name<?>");
+    ns.getNode(s(AnnotatedNameNotGenericInterface.class));
+  }
+
+  @Test
+  public void testAnnotatedNameMultipleInterfaces() throws NameResolutionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("Named parameter org.apache.reef.tang.implementation.AnnotatedNameMultipleInterfaces implements multiple interfaces.  It is only allowed to implement Name<T>");
+    ns.getNode(s(AnnotatedNameMultipleInterfaces.class));
+  }
+
+  @Test
+  public void testUnAnnotatedNameMultipleInterfaces() throws NameResolutionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("Named parameter org.apache.reef.tang.implementation.UnAnnotatedNameMultipleInterfaces is missing its @NamedParameter annotation.");
+    ns.getNode(s(UnAnnotatedNameMultipleInterfaces.class));
+  }
+
+  @Test
+  public void testNameWithConstructor() throws NameResolutionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("Named parameter org.apache.reef.tang.implementation.NameWithConstructor has a constructor.  Named parameters must not declare any constructors.");
+    ns.getNode(s(NameWithConstructor.class));
+  }
+
+  @Test
+  public void testNameWithZeroArgInject() throws NameResolutionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("Named parameter org.apache.reef.tang.implementation.NameWithZeroArgInject has an injectable constructor.  Named parameters must not declare any constructors.");
+    ns.getNode(s(NameWithZeroArgInject.class));
+  }
+
+  @Test
+  public void testGenericTorture1() throws NameResolutionException {
+    ns.getNode(s(GenericTorture1.class));
+  }
+
+  @Test
+  public void testGenericTorture2() throws NameResolutionException {
+    ns.getNode(s(GenericTorture2.class));
+  }
+
+  @Test
+  public void testGenericTorture3() throws NameResolutionException {
+    ns.getNode(s(GenericTorture3.class));
+  }
+
+  @Test
+  public void testGenericTorture4() throws NameResolutionException {
+    ns.getNode(s(GenericTorture4.class));
+  }
+
+  @Test
+  public void testGenericTorture5() throws NameResolutionException {
+    ns.getNode(s(GenericTorture5.class));
+  }
+
+  @Test
+  public void testGenericTorture6() throws NameResolutionException {
+    ns.getNode(s(GenericTorture6.class));
+  }
+
+  @Test
+  public void testGenericTorture7() throws NameResolutionException {
+    ns.getNode(s(GenericTorture7.class));
+  }
+
+  @Test
+  public void testGenericTorture8() throws NameResolutionException {
+    ns.getNode(s(GenericTorture8.class));
+  }
+
+  @Test
+  public void testGenericTorture9() throws NameResolutionException {
+    ns.getNode(s(GenericTorture9.class));
+  }
+
+  @Test
+  public void testGenericTorture10() throws NameResolutionException {
+    ns.getNode(s(GenericTorture10.class));
+  }
+
+  @Test
+  public void testGenericTorture11() throws NameResolutionException {
+    ns.getNode(s(GenericTorture11.class));
+  }
+
+  @Test
+  public void testGenericTorture12() throws NameResolutionException {
+    ns.getNode(s(GenericTorture12.class));
+  }
+
+  @Test
+  public void testInjectNonStaticLocalArgClass() throws NameResolutionException {
+    ns.getNode(s(InjectNonStaticLocalArgClass.class));
+  }
+
+  @Test(expected = ClassHierarchyException.class)
+  public void testInjectNonStaticLocalType() throws NameResolutionException {
+    ns.getNode(s(InjectNonStaticLocalType.class));
+  }
+
+  @Test(expected = ClassHierarchyException.class)
+  public void testConflictingShortNames() throws NameResolutionException {
+    ns.getNode(s(ShortNameFooA.class));
+    ns.getNode(s(ShortNameFooB.class));
+  }
+
+  @Test
+  public void testOKShortNames() throws NameResolutionException {
+    ns.getNode(s(ShortNameFooA.class));
+  }
+
+  @Test
+  public void testRoundTripInnerClassNames() throws ClassNotFoundException, NameResolutionException {
+    Node n = ns.getNode(s(Nested.Inner.class));
+    Class.forName(n.getFullName());
+  }
+
+  @Test
+  public void testRoundTripAnonInnerClassNames() throws ClassNotFoundException, NameResolutionException {
+    Node n = ns.getNode(s(AnonNested.x.getClass()));
+    Node m = ns.getNode(s(AnonNested.y.getClass()));
+    Assert.assertNotSame(n.getFullName(), m.getFullName());
+    Class<?> c = Class.forName(n.getFullName());
+    Class<?> d = Class.forName(m.getFullName());
+    Assert.assertNotSame(c, d);
+  }
+
+  @Test
+  public void testUnitIsInjectable() throws InjectionException, NameResolutionException {
+    ClassNode<?> n = (ClassNode<?>) ns.getNode(s(OuterUnitTH.class));
+    Assert.assertTrue(n.isUnit());
+    Assert.assertTrue(n.isInjectionCandidate());
+  }
+
+  @Test
+  public void testBadUnitDecl() throws NameResolutionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("Detected explicit constructor in class enclosed in @Unit org.apache.reef.tang.implementation.OuterUnitBad$InA  Such constructors are disallowed.");
+
+    ns.getNode(s(OuterUnitBad.class));
+  }
+
+  @Test
+  public void nameCantBindWrongSubclassAsDefault() throws NameResolutionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("class org.apache.reef.tang.implementation.BadName defines a default class java.lang.Integer with a raw type that does not extend of its target's raw type class java.lang.String");
+
+    ns.getNode(s(BadName.class));
+  }
+
+  @Test
+  public void ifaceCantBindWrongImplAsDefault() throws NameResolutionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("interface org.apache.reef.tang.implementation.BadIfaceDefault declares its default implementation to be non-subclass class java.lang.String");
+    ns.getNode(s(BadIfaceDefault.class));
+  }
+
+  @Test
+  public void testParseableDefaultClassNotOK() throws NameResolutionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("Named parameter org.apache.reef.tang.implementation.BadParsableDefaultClass defines default implementation for parsable type java.lang.String");
+    ns.getNode(s(BadParsableDefaultClass.class));
+  }
+
+  @Test
+  public void testDanglingUnit() throws NameResolutionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("Class org.apache.reef.tang.implementation.DanglingUnit has an @Unit annotation, but no non-static inner classes.  Such @Unit annotations would have no effect, and are therefore disallowed.");
+
+    ns.getNode(s(DanglingUnit.class));
+
+  }
+
+  @Test
+  public void testNonInjectableParam() throws NameResolutionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("public org.apache.reef.tang.implementation.NonInjectableParam(int) is not injectable, but it has an @Parameter annotation.");
+    ns.getNode(s(NonInjectableParam.class));
+  }
+
+}
+
+@NamedParameter(default_class = String.class)
+class BadParsableDefaultClass implements Name<String> {
+}
+
+@NamedParameter(default_class = Integer.class)
+class BadName implements Name<String> {
+}
+
+class SimpleConstructors {
+
+  @Inject
+  public SimpleConstructors() {
+  }
+
+  @Inject
+  public SimpleConstructors(int x) {
+  }
+
+  public SimpleConstructors(String x) {
+  }
+
+  @Inject
+  public SimpleConstructors(int x, String y) {
+  }
+}
+
+class NamedParameterConstructors {
+
+  @Inject
+  public NamedParameterConstructors(String x, @Parameter(X.class) String y) {
+  }
+
+  ;
+
+  @NamedParameter()
+  class X implements Name<String> {
+  }
+}
+
+class RepeatConstructorArg {
+  public
+  @Inject
+  RepeatConstructorArg(int x, int y) {
+  }
+}
+
+class A {
+}
+
+class RepeatConstructorArgClasses {
+  public
+  @Inject
+  RepeatConstructorArgClasses(A x, A y) {
+  }
+}
+
+class LeafRepeatedConstructorArgClasses {
+
+  static class A {
+    class AA {
+    }
+  }
+
+  static class B {
+    class AA {
+    }
+  }
+
+  static class C {
+    @Inject
+    C(A.AA a, B.AA b) {
+    }
+  }
+}
+
+@NamedParameter()
+class AA implements Name<A> {
+}
+
+@NamedParameter()
+class BB implements Name<A> {
+}
+
+class NamedRepeatConstructorArgClasses {
+  public
+  @Inject
+  NamedRepeatConstructorArgClasses(@Parameter(AA.class) A x,
+                                   @Parameter(BB.class) A y) {
+  }
+}
+
+class DocumentedLocalNamedParameter {
+
+  @Inject
+  public DocumentedLocalNamedParameter(@Parameter(Foo.class) String s) {
+  }
+
+  @NamedParameter(doc = "doc stuff", default_value = "some value")
+  final class Foo implements Name<String> {
+  }
+}
+
+class NamedParameterTypeMismatch {
+
+  @Inject
+  public NamedParameterTypeMismatch(@Parameter(Foo.class) String s) {
+  }
+
+  @NamedParameter(doc = "doc.stuff", default_value = "1")
+  final class Foo implements Name<Integer> {
+  }
+}
+
+class UnannotatedName implements Name<String> {
+}
+
+@NamedParameter(doc = "c")
+class AnnotatedNotName {
+}
+
+@NamedParameter(doc = "c")
+class AnnotatedNameWrongInterface implements I1 {
+}
+
+@SuppressWarnings("rawtypes")
+@NamedParameter(doc = "c")
+class AnnotatedNameNotGenericInterface implements Name {
+}
+
+class UnAnnotatedNameMultipleInterfaces implements Name<Object>, I1 {
+}
+
+@NamedParameter(doc = "c")
+class AnnotatedNameMultipleInterfaces implements Name<Object>, I1 {
+}
+
+@NamedParameter()
+class NameWithConstructor implements Name<Object> {
+  private NameWithConstructor(int i) {
+  }
+}
+
+@NamedParameter()
+class NameWithZeroArgInject implements Name<Object> {
+  @Inject
+  public NameWithZeroArgInject() {
+  }
+}
+
+@NamedParameter()
+class GenericTorture1 implements Name<Set<String>> {
+}
+
+@NamedParameter()
+class GenericTorture2 implements Name<Set<?>> {
+}
+
+@NamedParameter()
+class GenericTorture3 implements Name<Set<Set<String>>> {
+}
+
+@SuppressWarnings("rawtypes")
+@NamedParameter()
+class GenericTorture4 implements Name<Set<Set>> {
+}
+
+@NamedParameter()
+class GenericTorture5 implements Name<Map<Set<String>, Set<String>>> {
+}
+
+@SuppressWarnings("rawtypes")
+@NamedParameter()
+class GenericTorture6 implements Name<Map<Set, Set<String>>> {
+}
+
+@SuppressWarnings("rawtypes")
+@NamedParameter()
+class GenericTorture7 implements Name<Map<Set<String>, Set>> {
+}
+
+@NamedParameter()
+class GenericTorture8 implements Name<Map<String, String>> {
+}
+
+@SuppressWarnings("rawtypes")
+@NamedParameter()
+class GenericTorture9 implements Name<Map<Set, Set>> {
+}
+
+@NamedParameter()
+class GenericTorture10 implements Name<List<String>> {
+}
+
+@NamedParameter()
+class GenericTorture11 implements Name<List<?>> {
+}
+
+@NamedParameter()
+class GenericTorture12 implements Name<List<List<String>>> {
+}
+
+class InjectNonStaticLocalArgClass {
+  @Inject
+  InjectNonStaticLocalArgClass(NonStaticLocal x) {
+  }
+
+  class NonStaticLocal {
+  }
+}
+
+class InjectNonStaticLocalType {
+  class NonStaticLocal {
+    @Inject
+    NonStaticLocal(NonStaticLocal x) {
+    }
+  }
+}
+
+@NamedParameter(short_name = "foo")
+class ShortNameFooA implements Name<String> {
+}
+
+@NamedParameter(short_name = "foo")
+class ShortNameFooB implements Name<Integer> {
+}
+
+class Nested {
+  class Inner {
+  }
+}
+
+class AnonNested {
+  static X x = new X() {
+    @SuppressWarnings("unused")
+    int i;
+  };
+  static X y = new X() {
+    @SuppressWarnings("unused")
+    int j;
+  };
+
+  static interface X {
+  }
+}
+
+@Unit
+class OuterUnitBad {
+  class InA {
+    @Inject
+    InA() {
+    }
+  }
+
+  class InB {
+  }
+}
+
+@Unit
+class OuterUnitTH {
+  class InA {
+  }
+
+  class InB {
+  }
+}
+
+@Unit
+class DanglingUnit {
+  @Inject
+  DanglingUnit() {
+  }
+
+  static class DoesntCount {
+  }
+}
+
+class SomeName implements Name<Integer> {
+}
+
+class NonInjectableParam {
+  public NonInjectableParam(@Parameter(SomeName.class) int i) {
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/implementation/java/TestConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/implementation/java/TestConfigurationBuilder.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/implementation/java/TestConfigurationBuilder.java
new file mode 100644
index 0000000..7a65cd3
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/implementation/java/TestConfigurationBuilder.java
@@ -0,0 +1,60 @@
+/**
+ * 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.reef.tang.implementation.java;
+
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import javax.inject.Inject;
+
+/**
+ * TestConfigurationBuilder
+ */
+public class TestConfigurationBuilder {
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  @Test
+  public void nullStringVaueTest() {
+    thrown.expect(IllegalStateException.class);
+    thrown.expectMessage("The value null set to the named parameter is illegal: class org.apache.reef.tang.implementation.java.TestConfigurationBuilder$NamedParamterNoDefault$NamedString");
+
+    Tang.Factory.getTang().newConfigurationBuilder()
+        .bindNamedParameter(NamedParamterNoDefault.NamedString.class, (String) null)
+        .build();
+  }
+
+  static class NamedParamterNoDefault {
+    final private String str;
+
+    @Inject
+    NamedParamterNoDefault(@Parameter(NamedString.class) String str) {
+      this.str = str;
+    }
+
+    @NamedParameter()
+    class NamedString implements Name<String> {
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/implementation/java/TestParameterParser.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/implementation/java/TestParameterParser.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/implementation/java/TestParameterParser.java
new file mode 100644
index 0000000..0425920
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/implementation/java/TestParameterParser.java
@@ -0,0 +1,245 @@
+/**
+ * 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.reef.tang.implementation.java;
+
+import org.apache.reef.tang.ExternalConstructor;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.ParameterParser;
+import org.apache.reef.tang.util.ReflectionUtilities;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import javax.inject.Inject;
+
+public class TestParameterParser {
+
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  @Test
+  public void testParameterParser() throws BindException {
+    ParameterParser p = new ParameterParser();
+    p.addParser(FooParser.class);
+    Foo f = p.parse(Foo.class, "woot");
+    Assert.assertEquals(f.s, "woot");
+  }
+
+  @Test
+  public void testUnregisteredParameterParser() throws BindException {
+    thrown.expect(UnsupportedOperationException.class);
+    thrown.expectMessage("Don't know how to parse a org.apache.reef.tang.implementation.java.TestParameterParser$Foo");
+    ParameterParser p = new ParameterParser();
+    //p.addParser(FooParser.class);
+    Foo f = p.parse(Foo.class, "woot");
+    Assert.assertEquals(f.s, "woot");
+  }
+
+  @Test
+  public void testReturnSubclass() throws BindException {
+    ParameterParser p = new ParameterParser();
+    p.addParser(BarParser.class);
+    Bar f = (Bar) p.parse(Foo.class, "woot");
+    Assert.assertEquals(f.s, "woot");
+
+  }
+
+  @Test
+  public void testGoodMerge() throws BindException {
+    ParameterParser old = new ParameterParser();
+    old.addParser(BarParser.class);
+    ParameterParser nw = new ParameterParser();
+    nw.mergeIn(old);
+    nw.parse(Foo.class, "woot");
+  }
+
+  @Test
+  public void testGoodMerge2() throws BindException {
+    ParameterParser old = new ParameterParser();
+    old.addParser(BarParser.class);
+    ParameterParser nw = new ParameterParser();
+    nw.addParser(BarParser.class);
+    nw.mergeIn(old);
+    nw.parse(Foo.class, "woot");
+  }
+
+  @Test
+  public void testBadMerge() throws BindException {
+    thrown.expect(IllegalArgumentException.class);
+    thrown.expectMessage("Conflict detected when merging parameter parsers! To parse org.apache.reef.tang.implementation.java.TestParameterParser$Foo I have a: org.apache.reef.tang.implementation.java.TestParameterParser$FooParser the other instance has a: org.apache.reef.tang.implementation.java.TestParameterParser$BarParser");
+    ParameterParser old = new ParameterParser();
+    old.addParser(BarParser.class);
+    ParameterParser nw = new ParameterParser();
+    nw.addParser(FooParser.class);
+    nw.mergeIn(old);
+  }
+
+  @SuppressWarnings("unchecked")
+  @Test
+  public void testEndToEnd() throws BindException, InjectionException {
+    Tang tang = Tang.Factory.getTang();
+    JavaConfigurationBuilder cb = tang.newConfigurationBuilder(BarParser.class);
+    cb.bindNamedParameter(SomeNamedFoo.class, "hdfs://woot");
+    ILikeBars ilb = tang.newInjector(cb.build()).getInstance(ILikeBars.class);
+    Assert.assertNotNull(ilb);
+  }
+
+  @SuppressWarnings("unchecked")
+  @Test
+  public void testDelegatingParser() throws BindException, InjectionException, ClassNotFoundException {
+    Tang tang = Tang.Factory.getTang();
+    JavaConfigurationBuilder cb = tang.newConfigurationBuilder(TypeParser.class);
+
+    JavaConfigurationBuilder cb2 = tang.newConfigurationBuilder(cb.build());
+
+    cb2.bind(ReflectionUtilities.getFullName(ParseName.class), "a");
+
+    ParseableType t = tang.newInjector(cb2.build()).getNamedInstance(ParseName.class);
+    Assert.assertTrue(t instanceof ParseTypeA);
+
+    cb2 = tang.newConfigurationBuilder(cb.build());
+
+    cb2.bind(ReflectionUtilities.getFullName(ParseNameB.class), "b");
+    cb2.bindNamedParameter(ParseNameA.class, "a");
+    tang.newInjector(cb2.build()).getInstance(NeedsA.class);
+    tang.newInjector(cb2.build()).getInstance(NeedsB.class);
+
+  }
+
+  private static class FooParser implements ExternalConstructor<Foo> {
+    private final Foo foo;
+
+    @Inject
+    public FooParser(String s) {
+      this.foo = new Foo(s);
+    }
+
+    @Override
+    public Foo newInstance() {
+      return foo;
+    }
+  }
+
+  private static class BarParser implements ExternalConstructor<Foo> {
+    private final Bar bar;
+
+    @Inject
+    public BarParser(String s) {
+      this.bar = new Bar(s);
+    }
+
+    @Override
+    public Bar newInstance() {
+      return bar;
+    }
+  }
+
+  private static class Foo {
+    public final String s;
+
+    public Foo(String s) {
+      this.s = s;
+    }
+  }
+
+  private static class Bar extends Foo {
+    public Bar(String s) {
+      super(s);
+    }
+  }
+
+  @NamedParameter
+  private static class SomeNamedFoo implements Name<Foo> {
+  }
+
+  private static class ILikeBars {
+    @Inject
+    ILikeBars(@Parameter(SomeNamedFoo.class) Foo bar) {
+      Bar b = (Bar) bar;
+      Assert.assertEquals(b.s, "hdfs://woot");
+    }
+  }
+
+  private static class ParseableType {
+  }
+
+  private static class ParseTypeA extends ParseableType {
+
+  }
+
+  private static class ParseTypeB extends ParseableType {
+
+  }
+
+  private static class TypeParser implements ExternalConstructor<ParseableType> {
+    ParseableType instance;
+
+    @Inject
+    public TypeParser(String s) {
+      if (s.equals("a")) {
+        instance = new ParseTypeA();
+      }
+      if (s.equals("b")) {
+        instance = new ParseTypeB();
+      }
+
+    }
+
+    @Override
+    public ParseableType newInstance() {
+      return instance;
+    }
+  }
+
+  @NamedParameter()
+  private static class ParseName implements Name<ParseableType> {
+
+  }
+
+  @NamedParameter()
+  private static class ParseNameA implements Name<ParseableType> {
+
+  }
+
+  @NamedParameter()
+  private static class ParseNameB implements Name<ParseTypeB> {
+
+  }
+
+  private static class NeedsA {
+    @Inject
+    public NeedsA(@Parameter(ParseNameA.class) ParseableType a) {
+      Assert.assertTrue(a instanceof ParseTypeA);
+    }
+  }
+
+  private static class NeedsB {
+    @Inject
+    public NeedsB(@Parameter(ParseNameB.class) ParseTypeB b) {
+      Assert.assertTrue(b instanceof ParseTypeB);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/implementation/protobuf/TestClassHierarchyRoundTrip.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/implementation/protobuf/TestClassHierarchyRoundTrip.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/implementation/protobuf/TestClassHierarchyRoundTrip.java
new file mode 100644
index 0000000..238f979
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/implementation/protobuf/TestClassHierarchyRoundTrip.java
@@ -0,0 +1,401 @@
+/**
+ * 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.reef.tang.implementation.protobuf;
+
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.exceptions.NameResolutionException;
+import org.apache.reef.tang.implementation.TangImpl;
+import org.apache.reef.tang.implementation.TestClassHierarchy;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+
+public class TestClassHierarchyRoundTrip extends TestClassHierarchy {
+
+  private void setup1() {
+    TangImpl.reset();
+    ns = Tang.Factory.getTang().getDefaultClassHierarchy();
+  }
+
+  private void setup2() {
+    TangImpl.reset();
+    ns = new ProtocolBufferClassHierarchy(ProtocolBufferClassHierarchy.serialize(ns));
+  }
+
+  private void setup3() {
+    TangImpl.reset();
+    try {
+      final File file = java.io.File.createTempFile("testProto", "bin");
+      ProtocolBufferClassHierarchy.serialize(file, ns);
+      ns = ProtocolBufferClassHierarchy.deserialize(file);
+      file.delete();
+    } catch (IOException e) {
+      Assert.fail(String.format("IOException when serialize/deserialize proto buffer file ", e));
+    }
+  }
+
+  @Test
+  @Override
+  public void testJavaString() throws NameResolutionException {
+    setup1();
+    super.testJavaString();
+    setup2();
+    super.testJavaString();
+    setup3();
+    super.testJavaString();
+  }
+
+  @Test
+  @Override
+  public void testSimpleConstructors() throws NameResolutionException {
+    setup1();
+    super.testSimpleConstructors();
+    setup2();
+    super.testSimpleConstructors();
+    setup3();
+    super.testSimpleConstructors();
+  }
+
+  @Test
+  @Override
+  public void testNamedParameterConstructors() throws NameResolutionException {
+    setup1();
+    super.testNamedParameterConstructors();
+    setup2();
+    super.testNamedParameterConstructors();
+    setup3();
+    super.testNamedParameterConstructors();
+  }
+
+  @Test
+  @Override
+  public void testArray() throws NameResolutionException {
+    setup1();
+    super.testArray();
+    setup2();
+    super.testArray();
+    setup3();
+    super.testArray();
+  }
+
+  @Test
+  @Override
+  public void testRepeatConstructorArg() throws NameResolutionException {
+    setup1();
+    super.testRepeatConstructorArg();
+    setup2();
+    super.testRepeatConstructorArg();
+    setup3();
+    super.testRepeatConstructorArg();
+  }
+
+  @Test
+  @Override
+  public void testRepeatConstructorArgClasses() throws NameResolutionException {
+    setup1();
+    super.testRepeatConstructorArgClasses();
+    setup2();
+    super.testRepeatConstructorArgClasses();
+    setup3();
+    super.testRepeatConstructorArgClasses();
+  }
+
+  @Test
+  @Override
+  public void testLeafRepeatedConstructorArgClasses() throws NameResolutionException {
+    setup1();
+    super.testLeafRepeatedConstructorArgClasses();
+    setup2();
+    super.testLeafRepeatedConstructorArgClasses();
+    setup3();
+    super.testLeafRepeatedConstructorArgClasses();
+  }
+
+  @Test
+  @Override
+  public void testNamedRepeatConstructorArgClasses() throws NameResolutionException {
+    setup1();
+    super.testNamedRepeatConstructorArgClasses();
+    setup2();
+    super.testNamedRepeatConstructorArgClasses();
+    setup3();
+    super.testNamedRepeatConstructorArgClasses();
+  }
+
+  @Test
+  @Override
+  public void testResolveDependencies() throws NameResolutionException {
+    setup1();
+    super.testResolveDependencies();
+    setup2();
+    super.testResolveDependencies();
+    setup3();
+    super.testResolveDependencies();
+  }
+
+  @Test
+  @Override
+  public void testDocumentedLocalNamedParameter() throws NameResolutionException {
+    setup1();
+    super.testDocumentedLocalNamedParameter();
+    setup2();
+    super.testDocumentedLocalNamedParameter();
+    setup3();
+    super.testDocumentedLocalNamedParameter();
+  }
+
+  @Test
+  @Override
+  public void testNamedParameterTypeMismatch() throws NameResolutionException {
+    setup1();
+    super.testNamedParameterTypeMismatch();
+    setup2();
+    super.testNamedParameterTypeMismatch();
+    setup3();
+    super.testNamedParameterTypeMismatch();
+  }
+
+  @Test
+  @Override
+  public void testUnannotatedName() throws NameResolutionException {
+    setup1();
+    super.testUnannotatedName();
+    setup2();
+    super.testUnannotatedName();
+    setup3();
+    super.testUnannotatedName();
+  }
+
+  @Test
+  @Override
+  public void testAnnotatedNotName() throws NameResolutionException {
+    setup1();
+    super.testAnnotatedNotName();
+    setup2();
+    super.testAnnotatedNotName();
+    setup3();
+    super.testAnnotatedNotName();
+  }
+
+  @Test
+  @Override
+  public void testGenericTorture1() throws NameResolutionException {
+    setup1();
+    super.testGenericTorture1();
+    setup2();
+    super.testGenericTorture1();
+    setup3();
+    super.testGenericTorture1();
+  }
+
+  @Test
+  @Override
+  public void testGenericTorture2() throws NameResolutionException {
+    setup1();
+    super.testGenericTorture2();
+    setup2();
+    super.testGenericTorture2();
+    setup3();
+    super.testGenericTorture2();
+  }
+
+  @Test
+  @Override
+  public void testGenericTorture3() throws NameResolutionException {
+    setup1();
+    super.testGenericTorture3();
+    setup2();
+    super.testGenericTorture3();
+    setup3();
+    super.testGenericTorture3();
+  }
+
+  @Test
+  @Override
+  public void testGenericTorture4() throws NameResolutionException {
+    setup1();
+    super.testGenericTorture4();
+    setup2();
+    super.testGenericTorture4();
+    setup3();
+    super.testGenericTorture4();
+  }
+
+  @Test
+  @Override
+  public void testGenericTorture5() throws NameResolutionException {
+    setup1();
+    super.testGenericTorture5();
+    setup2();
+    super.testGenericTorture5();
+    setup3();
+    super.testGenericTorture5();
+  }
+
+  @Test
+  @Override
+  public void testGenericTorture6() throws NameResolutionException {
+    setup1();
+    super.testGenericTorture6();
+    setup2();
+    super.testGenericTorture6();
+    setup3();
+    super.testGenericTorture6();
+  }
+
+  @Test
+  @Override
+  public void testGenericTorture7() throws NameResolutionException {
+    setup1();
+    super.testGenericTorture7();
+    setup2();
+    super.testGenericTorture7();
+    setup3();
+    super.testGenericTorture7();
+  }
+
+  @Test
+  @Override
+  public void testGenericTorture8() throws NameResolutionException {
+    setup1();
+    super.testGenericTorture8();
+    setup2();
+    super.testGenericTorture8();
+    setup3();
+    super.testGenericTorture8();
+  }
+
+  @Test
+  @Override
+  public void testGenericTorture9() throws NameResolutionException {
+    setup1();
+    super.testGenericTorture9();
+    setup2();
+    super.testGenericTorture9();
+    setup3();
+    super.testGenericTorture9();
+  }
+
+  @Test
+  @Override
+  public void testGenericTorture10() throws NameResolutionException {
+    setup1();
+    super.testGenericTorture10();
+    setup2();
+    super.testGenericTorture10();
+  }
+
+  @Test
+  @Override
+  public void testGenericTorture11() throws NameResolutionException {
+    setup1();
+    super.testGenericTorture11();
+    setup2();
+    super.testGenericTorture11();
+  }
+
+  @Test
+  @Override
+  public void testGenericTorture12() throws NameResolutionException {
+    setup1();
+    super.testGenericTorture12();
+    setup2();
+    super.testGenericTorture12();
+  }
+
+  @Test
+  @Override
+  public void testInjectNonStaticLocalArgClass() throws NameResolutionException {
+    setup1();
+    super.testInjectNonStaticLocalArgClass();
+    setup2();
+    super.testInjectNonStaticLocalArgClass();
+    setup3();
+    super.testInjectNonStaticLocalArgClass();
+  }
+
+  @Test
+  @Override
+  public void testOKShortNames() throws NameResolutionException {
+    setup1();
+    super.testOKShortNames();
+    setup2();
+    super.testOKShortNames();
+    setup3();
+    super.testOKShortNames();
+  }
+
+  @Test
+  @Override
+  public void testRoundTripInnerClassNames() throws NameResolutionException, ClassNotFoundException {
+    setup1();
+    super.testRoundTripInnerClassNames();
+    setup2();
+    super.testRoundTripInnerClassNames();
+    setup3();
+    super.testRoundTripInnerClassNames();
+  }
+
+  @Test
+  @Override
+  public void testUnitIsInjectable() throws NameResolutionException, InjectionException {
+    setup1();
+    super.testUnitIsInjectable();
+    setup2();
+    super.testUnitIsInjectable();
+    setup3();
+    super.testUnitIsInjectable();
+  }
+
+  @Test
+  @Override
+  public void testBadUnitDecl() throws NameResolutionException {
+    setup1();
+    super.testBadUnitDecl();
+    setup2();
+    super.testBadUnitDecl();
+    setup3();
+    super.testBadUnitDecl();
+  }
+
+  @Test
+  @Override
+  public void nameCantBindWrongSubclassAsDefault() throws NameResolutionException {
+    setup1();
+    super.nameCantBindWrongSubclassAsDefault();
+    setup2();
+    super.nameCantBindWrongSubclassAsDefault();
+    setup3();
+    super.nameCantBindWrongSubclassAsDefault();
+  }
+
+  @Test
+  @Override
+  public void ifaceCantBindWrongImplAsDefault() throws NameResolutionException {
+    setup1();
+    super.ifaceCantBindWrongImplAsDefault();
+    setup2();
+    super.ifaceCantBindWrongImplAsDefault();
+    setup3();
+    super.ifaceCantBindWrongImplAsDefault();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/AnInterface.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/AnInterface.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/AnInterface.java
new file mode 100644
index 0000000..6d6b6d6
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/AnInterface.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.tang.test;
+
+import org.apache.reef.tang.annotations.DefaultImplementation;
+
+/**
+ * An interface with a default implementation
+ */
+@DefaultImplementation(AnInterfaceImplementation.class)
+interface AnInterface {
+  void aMethod();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/AnInterfaceImplementation.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/AnInterfaceImplementation.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/AnInterfaceImplementation.java
new file mode 100644
index 0000000..d932b37
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/AnInterfaceImplementation.java
@@ -0,0 +1,52 @@
+/**
+ * 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.reef.tang.test;
+
+import javax.inject.Inject;
+
+final class AnInterfaceImplementation implements AnInterface {
+  private final int aMagicNumber;
+
+  @Inject
+  AnInterfaceImplementation() {
+    this.aMagicNumber = 42;
+  }
+
+  @Override
+  public void aMethod() {
+
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    AnInterfaceImplementation that = (AnInterfaceImplementation) o;
+
+    if (aMagicNumber != that.aMagicNumber) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return aMagicNumber;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/CyclicDependency.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/CyclicDependency.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/CyclicDependency.java
new file mode 100644
index 0000000..ca48643
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/CyclicDependency.java
@@ -0,0 +1,56 @@
+/**
+ * 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.reef.tang.test;
+
+import javax.inject.Inject;
+
+/**
+ * Part of a cyclic dependency
+ */
+final class CyclicDependency {
+  private final CyclicDependencyClassOne one;
+  private final CyclicDependencyClassTwo two;
+
+  @Inject
+  CyclicDependency(final CyclicDependencyClassOne one,
+                   final CyclicDependencyClassTwo two) {
+    this.one = one;
+    this.two = two;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    CyclicDependency that = (CyclicDependency) o;
+
+    if (!one.equals(that.one)) return false;
+    if (!two.equals(that.two)) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = one.hashCode();
+    result = 31 * result + two.hashCode();
+    return result;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/CyclicDependencyClassOne.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/CyclicDependencyClassOne.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/CyclicDependencyClassOne.java
new file mode 100644
index 0000000..513a854
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/CyclicDependencyClassOne.java
@@ -0,0 +1,50 @@
+/**
+ * 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.reef.tang.test;
+
+import javax.inject.Inject;
+
+/**
+ * Part of a cyclic dependency
+ */
+final class CyclicDependencyClassOne {
+  private final CyclicDependencyClassTwo other;
+
+  @Inject
+  CyclicDependencyClassOne(final CyclicDependencyClassTwo other) {
+    this.other = other;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    CyclicDependencyClassOne that = (CyclicDependencyClassOne) o;
+
+    if (!other.equals(that.other)) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return other.hashCode();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/CyclicDependencyClassTwo.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/CyclicDependencyClassTwo.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/CyclicDependencyClassTwo.java
new file mode 100644
index 0000000..bfceb55
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/CyclicDependencyClassTwo.java
@@ -0,0 +1,48 @@
+/**
+ * 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.reef.tang.test;
+
+import org.apache.reef.tang.InjectionFuture;
+
+import javax.inject.Inject;
+
+/**
+ * Part of a cyclic dependency.
+ */
+final class CyclicDependencyClassTwo {
+  private final InjectionFuture<CyclicDependencyClassOne> other;
+
+  @Inject
+  CyclicDependencyClassTwo(InjectionFuture<CyclicDependencyClassOne> other) {
+    this.other = other;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return other.hashCode();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/Handler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/Handler.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/Handler.java
new file mode 100644
index 0000000..864b362
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/Handler.java
@@ -0,0 +1,30 @@
+/**
+ * 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.reef.tang.test;
+
+/**
+ * An interface with a type parameter. This can be found e.g. in REEF EventHandlers.
+ *
+ * @param <T>
+ */
+interface Handler<T> {
+
+  public void process(final T value);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/InjectableClass.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/InjectableClass.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/InjectableClass.java
new file mode 100644
index 0000000..a8accb8
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/InjectableClass.java
@@ -0,0 +1,47 @@
+/**
+ * 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.reef.tang.test;
+
+import javax.inject.Inject;
+
+final class InjectableClass {
+
+  private final int magicNumber = -42;
+
+  @Inject
+  InjectableClass() {
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    InjectableClass that = (InjectableClass) o;
+
+    if (magicNumber != that.magicNumber) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return magicNumber;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListInterface.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListInterface.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListInterface.java
new file mode 100644
index 0000000..4e8c1a0
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListInterface.java
@@ -0,0 +1,23 @@
+/**
+ * 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.reef.tang.test;
+
+public interface ListInterface {
+  void bMethod();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListInterfaceImplOne.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListInterfaceImplOne.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListInterfaceImplOne.java
new file mode 100644
index 0000000..3adad54
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListInterfaceImplOne.java
@@ -0,0 +1,55 @@
+/**
+ * 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.reef.tang.test;
+
+import javax.inject.Inject;
+
+public class ListInterfaceImplOne implements ListInterface {
+
+  private final int magicNumber;
+
+  @Inject
+  ListInterfaceImplOne() {
+    magicNumber = 31;
+  }
+
+  @Override
+  public void bMethod() {
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj) {
+      return true;
+    } else if (obj == null || obj.getClass() != getClass()) {
+      return false;
+    } else {
+      ListInterfaceImplOne one = (ListInterfaceImplOne) obj;
+      if (one.magicNumber != magicNumber) {
+        return false;
+      }
+      return true;
+    }
+  }
+
+  @Override
+  public int hashCode() {
+    return magicNumber;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListInterfaceImplTwo.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListInterfaceImplTwo.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListInterfaceImplTwo.java
new file mode 100644
index 0000000..1513f82
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListInterfaceImplTwo.java
@@ -0,0 +1,55 @@
+/**
+ * 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.reef.tang.test;
+
+import javax.inject.Inject;
+
+public class ListInterfaceImplTwo implements ListInterface {
+  private final double magicNumber;
+
+  @Inject
+  ListInterfaceImplTwo() {
+    magicNumber = 31.0;
+  }
+
+  @Override
+  public void bMethod() {
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj) {
+      return true;
+    } else if (obj == null || obj.getClass() != getClass()) {
+      return false;
+    } else {
+      ListInterfaceImplTwo two = (ListInterfaceImplTwo) obj;
+      if (Double.compare(two.magicNumber, magicNumber) != 0) {
+        return false;
+      }
+      return true;
+    }
+  }
+
+  @Override
+  public int hashCode() {
+    long temp = Double.doubleToLongBits(magicNumber);
+    return (int) (temp ^ (temp >>> 32));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListOfBaseTypes.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListOfBaseTypes.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListOfBaseTypes.java
new file mode 100644
index 0000000..76d0a26
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListOfBaseTypes.java
@@ -0,0 +1,82 @@
+/**
+ * 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.reef.tang.test;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+import java.util.List;
+
+final class ListOfBaseTypes {
+  private final List<Integer> integers;
+  private final List<Double> doubles;
+  private final List<String> strings;
+  private final List<Integer> moreIntegers;
+
+  @Inject
+  ListOfBaseTypes(@Parameter(Integers.class) final List<Integer> integers,
+                  @Parameter(Doubles.class) final List<Double> doubles,
+                  @Parameter(Strings.class) final List<String> strings,
+                  @Parameter(MoreIntegers.class) final List<Integer> moreIntegers) {
+    this.integers = integers;
+    this.doubles = doubles;
+    this.strings = strings;
+    this.moreIntegers = moreIntegers;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ListOfBaseTypes that = (ListOfBaseTypes) o;
+
+    if (!doubles.equals(that.doubles)) return false;
+    if (!integers.equals(that.integers)) return false;
+    if (!strings.equals(that.strings)) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = integers.hashCode();
+    result = 31 * result + doubles.hashCode();
+    result = 31 * result + strings.hashCode();
+    return result;
+  }
+
+  @NamedParameter
+  public static class Integers implements Name<List<Integer>> {
+  }
+
+  @NamedParameter(default_values = {"1", "2", "3"})
+  public static class MoreIntegers implements Name<List<Integer>> {
+  }
+
+  @NamedParameter
+  public static class Doubles implements Name<List<Double>> {
+  }
+
+  @NamedParameter
+  public static class Strings implements Name<List<String>> {
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListOfImplementations.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListOfImplementations.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListOfImplementations.java
new file mode 100644
index 0000000..c1fc103
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ListOfImplementations.java
@@ -0,0 +1,55 @@
+/**
+ * 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.reef.tang.test;
+
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+import java.util.List;
+
+public class ListOfImplementations {
+
+  private final List<ListInterface> theInstances;
+
+  @Inject
+  ListOfImplementations(@Parameter(TestConfiguration.ListOfInstances.class) final List<ListInterface> theInstances) {
+    this.theInstances = theInstances;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ListOfImplementations that = (ListOfImplementations) o;
+
+    if (!theInstances.equals(that.theInstances)) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return theInstances.hashCode();
+  }
+
+  public boolean isValid() {
+    return this.theInstances.size() == 2;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ObjectTreeTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ObjectTreeTest.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ObjectTreeTest.java
new file mode 100644
index 0000000..53fb0ec
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/ObjectTreeTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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.reef.tang.test;
+
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ObjectTreeTest {
+
+  public static Configuration getConfiguration() throws BindException {
+    return TestConfiguration.CONF
+        .set(TestConfiguration.OPTIONAL_STRING, TestConfiguration.OPTIONAL_STRING_VALUE)
+        .set(TestConfiguration.REQUIRED_STRING, TestConfiguration.REQUIRED_STRING_VALUE)
+        .build();
+  }
+
+  /**
+   * Configuration getter for TestConfigurationWithoutList.
+   */
+  public static Configuration getConfigurationWithoutList() throws BindException {
+    // TODO: Remove this method after #192 is fixed
+    return TestConfigurationWithoutList.CONF
+        .set(TestConfigurationWithoutList.OPTIONAL_STRING, TestConfigurationWithoutList.OPTIONAL_STRING_VALUE)
+        .set(TestConfigurationWithoutList.REQUIRED_STRING, TestConfigurationWithoutList.REQUIRED_STRING_VALUE)
+        .build();
+  }
+
+  @Test
+  public void testInstantiation() throws BindException, InjectionException {
+    final RootInterface root = Tang.Factory.getTang().newInjector(getConfiguration()).getInstance(RootInterface.class);
+    Assert.assertTrue("Object instantiation left us in an inconsistent state.", root.isValid());
+  }
+
+  @Test
+  public void testTwoInstantiations() throws BindException, InjectionException {
+    final RootInterface firstRoot = Tang.Factory.getTang().newInjector(getConfiguration()).getInstance(RootInterface.class);
+    final RootInterface secondRoot = Tang.Factory.getTang().newInjector(getConfiguration()).getInstance(RootInterface.class);
+    Assert.assertNotSame("Two instantiations of the object tree should not be the same", firstRoot, secondRoot);
+    Assert.assertEquals("Two instantiations of the object tree should be equal", firstRoot, secondRoot);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/RootImplementation.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/RootImplementation.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/RootImplementation.java
new file mode 100644
index 0000000..161eb67
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/RootImplementation.java
@@ -0,0 +1,166 @@
+/**
+ * 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.reef.tang.test;
+
+
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+
+/**
+ * The root of the object graph instantiated.
+ */
+final class RootImplementation implements RootInterface {
+
+  private final String requiredString;
+  private final String optionalString;
+  private final UnitClass unit;
+  private final Handler<String> stringHandler;
+  private final Handler<Integer> integerHandler;
+  private final AnInterface anInterface;
+  private final int anInt;
+  private final double aDouble;
+  private final InjectableClass injectableClass;
+  private final SetOfImplementations setOfImplementations;
+  private final SetOfBaseTypes setOfBaseTypes;
+  private final ListOfImplementations listOfImplementations;
+  private final ListOfBaseTypes listOfBaseTypes;
+  private final CyclicDependency cyclicDependency;
+
+  @Inject
+  public RootImplementation(@Parameter(TestConfiguration.RequiredString.class) final String requiredString,
+                            @Parameter(TestConfiguration.OptionalString.class) final String optionalString,
+                            @Parameter(TestConfiguration.StringHandler.class) final Handler<String> stringHandler,
+                            @Parameter(TestConfiguration.IntegerHandler.class) final Handler<Integer> integerHandler,
+                            @Parameter(TestConfiguration.NamedParameterInteger.class) final int anInt,
+                            @Parameter(TestConfiguration.NamedParameterDouble.class) double aDouble,
+                            final UnitClass unit,
+                            final AnInterface anInterface,
+                            final InjectableClass injectableClass,
+                            final SetOfImplementations setOfImplementations,
+                            final SetOfBaseTypes setOfBaseTypes,
+                            final ListOfImplementations listOfImplementations,
+                            final ListOfBaseTypes listOfBaseTypes,
+                            CyclicDependency cyclicDependency) {
+    this.requiredString = requiredString;
+    this.optionalString = optionalString;
+    this.unit = unit;
+    this.stringHandler = stringHandler;
+    this.integerHandler = integerHandler;
+    this.anInterface = anInterface;
+    this.anInt = anInt;
+    this.aDouble = aDouble;
+    this.injectableClass = injectableClass;
+    this.setOfImplementations = setOfImplementations;
+    this.setOfBaseTypes = setOfBaseTypes;
+    this.listOfImplementations = listOfImplementations;
+    this.listOfBaseTypes = listOfBaseTypes;
+    this.cyclicDependency = cyclicDependency;
+  }
+
+  @Override
+  public boolean isValid() {
+    if (!this.setOfImplementations.isValid()) {
+      return false;
+    }
+    if (!this.listOfImplementations.isValid()) {
+      return false;
+    }
+    if (!this.requiredString.equals(TestConfiguration.REQUIRED_STRING_VALUE)) {
+      return false;
+    }
+
+    if (!this.optionalString.equals(TestConfiguration.OPTIONAL_STRING_VALUE)) {
+      return false;
+    }
+
+    this.integerHandler.process(3);
+    this.stringHandler.process("three");
+    if (this.unit.getIntValue() != 3) {
+      return false;
+    }
+    if (!this.unit.getStringValue().equals("three")) {
+      return false;
+    }
+    if (this.anInterface == null) {
+      return false;
+    }
+
+    if (this.aDouble != TestConfiguration.NAMED_PARAMETER_DOUBLE_VALUE) {
+      return false;
+    }
+    if (this.anInt != TestConfiguration.NAMED_PARAMETER_INTEGER_VALUE) {
+      return false;
+    }
+
+    return true;
+  }
+
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    RootImplementation that = (RootImplementation) o;
+
+    if (Double.compare(that.aDouble, aDouble) != 0) return false;
+    if (anInt != that.anInt) return false;
+    if (anInterface != null ? !anInterface.equals(that.anInterface) : that.anInterface != null) return false;
+    if (integerHandler != null ? !integerHandler.equals(that.integerHandler) : that.integerHandler != null)
+      return false;
+    if (optionalString != null ? !optionalString.equals(that.optionalString) : that.optionalString != null)
+      return false;
+    if (requiredString != null ? !requiredString.equals(that.requiredString) : that.requiredString != null)
+      return false;
+    if (stringHandler != null ? !stringHandler.equals(that.stringHandler) : that.stringHandler != null) return false;
+    if (unit != null ? !unit.equals(that.unit) : that.unit != null) return false;
+    if (injectableClass != null ? !injectableClass.equals(that.injectableClass) : that.injectableClass != null)
+      return false;
+    if (setOfImplementations != null ? !setOfImplementations.equals(that.setOfImplementations) : that.setOfImplementations != null)
+      return false;
+    if (setOfBaseTypes != null ? !setOfBaseTypes.equals(that.setOfBaseTypes) : that.setOfBaseTypes != null)
+      return false;
+    if (listOfImplementations != null ? !listOfImplementations.equals(that.listOfImplementations) : that
+        .listOfImplementations != null)
+      return false;
+    if (listOfBaseTypes != null ? !listOfBaseTypes.equals(that.listOfBaseTypes) : that.listOfBaseTypes != null)
+      return false;
+    if (cyclicDependency != null ? !cyclicDependency.equals(that.cyclicDependency) : that.cyclicDependency != null)
+      return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result;
+    long temp;
+    result = requiredString != null ? requiredString.hashCode() : 0;
+    result = 31 * result + (optionalString != null ? optionalString.hashCode() : 0);
+    result = 31 * result + (unit != null ? unit.hashCode() : 0);
+    result = 31 * result + (stringHandler != null ? stringHandler.hashCode() : 0);
+    result = 31 * result + (integerHandler != null ? integerHandler.hashCode() : 0);
+    result = 31 * result + (anInterface != null ? anInterface.hashCode() : 0);
+    result = 31 * result + anInt;
+    temp = Double.doubleToLongBits(aDouble);
+    result = 31 * result + (int) (temp ^ (temp >>> 32));
+    return result;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/RootImplementationWithoutList.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/RootImplementationWithoutList.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/RootImplementationWithoutList.java
new file mode 100644
index 0000000..6569b19
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/RootImplementationWithoutList.java
@@ -0,0 +1,155 @@
+/**
+ * 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.reef.tang.test;
+
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+
+/**
+ * The root of the object graph without list
+ *
+ * @see org.apache.reef.tang.test.RootImplementation
+ */
+public class RootImplementationWithoutList implements RootInterface {
+  // TODO: Remove this class after #192 is fixed
+  private final String requiredString;
+  private final String optionalString;
+  private final UnitClass unit;
+  private final Handler<String> stringHandler;
+  private final Handler<Integer> integerHandler;
+  private final AnInterface anInterface;
+  private final int anInt;
+  private final double aDouble;
+  private final InjectableClass injectableClass;
+  private final SetOfImplementations setOfImplementations;
+  private final SetOfBaseTypes setOfBaseTypes;
+  private final CyclicDependency cyclicDependency;
+
+  @Inject
+  public RootImplementationWithoutList(
+      @Parameter(TestConfigurationWithoutList.RequiredString.class) final String requiredString,
+      @Parameter(TestConfigurationWithoutList.OptionalString.class) final String optionalString,
+      @Parameter(TestConfigurationWithoutList.StringHandler.class) final Handler<String> stringHandler,
+      @Parameter(TestConfigurationWithoutList.IntegerHandler.class) final Handler<Integer> integerHandler,
+      @Parameter(TestConfigurationWithoutList.NamedParameterInteger.class) final int anInt,
+      @Parameter(TestConfigurationWithoutList.NamedParameterDouble.class) double aDouble,
+      final UnitClass unit,
+      final AnInterface anInterface,
+      final InjectableClass injectableClass,
+      final SetOfImplementations setOfImplementations,
+      final SetOfBaseTypes setOfBaseTypes,
+      CyclicDependency cyclicDependency) {
+
+    this.requiredString = requiredString;
+    this.optionalString = optionalString;
+    this.unit = unit;
+    this.stringHandler = stringHandler;
+    this.integerHandler = integerHandler;
+    this.anInterface = anInterface;
+    this.anInt = anInt;
+    this.aDouble = aDouble;
+    this.injectableClass = injectableClass;
+    this.setOfImplementations = setOfImplementations;
+    this.setOfBaseTypes = setOfBaseTypes;
+    this.cyclicDependency = cyclicDependency;
+  }
+
+  @Override
+  public boolean isValid() {
+    if (!this.setOfImplementations.isValid()) {
+      return false;
+    }
+    if (!this.requiredString.equals(TestConfiguration.REQUIRED_STRING_VALUE)) {
+      return false;
+    }
+
+    if (!this.optionalString.equals(TestConfiguration.OPTIONAL_STRING_VALUE)) {
+      return false;
+    }
+
+    this.integerHandler.process(3);
+    this.stringHandler.process("three");
+    if (this.unit.getIntValue() != 3) {
+      return false;
+    }
+    if (!this.unit.getStringValue().equals("three")) {
+      return false;
+    }
+    if (this.anInterface == null) {
+      return false;
+    }
+
+    if (this.aDouble != TestConfiguration.NAMED_PARAMETER_DOUBLE_VALUE) {
+      return false;
+    }
+    if (this.anInt != TestConfiguration.NAMED_PARAMETER_INTEGER_VALUE) {
+      return false;
+    }
+
+    return true;
+  }
+
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    RootImplementationWithoutList that = (RootImplementationWithoutList) o;
+
+    if (Double.compare(that.aDouble, aDouble) != 0) return false;
+    if (anInt != that.anInt) return false;
+    if (anInterface != null ? !anInterface.equals(that.anInterface) : that.anInterface != null) return false;
+    if (integerHandler != null ? !integerHandler.equals(that.integerHandler) : that.integerHandler != null)
+      return false;
+    if (optionalString != null ? !optionalString.equals(that.optionalString) : that.optionalString != null)
+      return false;
+    if (requiredString != null ? !requiredString.equals(that.requiredString) : that.requiredString != null)
+      return false;
+    if (stringHandler != null ? !stringHandler.equals(that.stringHandler) : that.stringHandler != null) return false;
+    if (unit != null ? !unit.equals(that.unit) : that.unit != null) return false;
+    if (injectableClass != null ? !injectableClass.equals(that.injectableClass) : that.injectableClass != null)
+      return false;
+    if (setOfImplementations != null ? !setOfImplementations.equals(that.setOfImplementations) : that.setOfImplementations != null)
+      return false;
+    if (setOfBaseTypes != null ? !setOfBaseTypes.equals(that.setOfBaseTypes) : that.setOfBaseTypes != null)
+      return false;
+    if (cyclicDependency != null ? !cyclicDependency.equals(that.cyclicDependency) : that.cyclicDependency != null)
+      return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result;
+    long temp;
+    result = requiredString != null ? requiredString.hashCode() : 0;
+    result = 31 * result + (optionalString != null ? optionalString.hashCode() : 0);
+    result = 31 * result + (unit != null ? unit.hashCode() : 0);
+    result = 31 * result + (stringHandler != null ? stringHandler.hashCode() : 0);
+    result = 31 * result + (integerHandler != null ? integerHandler.hashCode() : 0);
+    result = 31 * result + (anInterface != null ? anInterface.hashCode() : 0);
+    result = 31 * result + anInt;
+    temp = Double.doubleToLongBits(aDouble);
+    result = 31 * result + (int) (temp ^ (temp >>> 32));
+    return result;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/RootInterface.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/RootInterface.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/RootInterface.java
new file mode 100644
index 0000000..210726b
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/RootInterface.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.tang.test;
+
+/**
+ * The interface for the root of the test object graph instantiated.
+ */
+public interface RootInterface {
+
+  /**
+   * @return true, if the object graph has been instantiated correctly, false otherwise.
+   */
+  public boolean isValid();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/RoundTripTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/RoundTripTest.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/RoundTripTest.java
new file mode 100644
index 0000000..9f012e5
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/RoundTripTest.java
@@ -0,0 +1,56 @@
+/**
+ * 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.reef.tang.test;
+
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.implementation.protobuf.ProtocolBufferClassHierarchy;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Base class for roundtrip tests. The idea is that serializers implement roundTrip() and then get tested by the tests
+ * in this class.
+ */
+public abstract class RoundTripTest {
+
+  public abstract Configuration roundTrip(final Configuration configuration) throws Exception;
+
+  public abstract Configuration roundTrip(final Configuration configuration, final ClassHierarchy classHierarchy) throws Exception;
+
+  @Test
+  public void testRoundTrip() throws Exception {
+    // TODO: use 'getConfiguration' instead of 'getConfigurationWithoutList' after #192 is fixed
+    final Configuration conf = ObjectTreeTest.getConfigurationWithoutList();
+    final RootInterface before = Tang.Factory.getTang().newInjector(conf).getInstance(RootInterface.class);
+    final RootInterface after = Tang.Factory.getTang().newInjector(roundTrip(conf)).getInstance(RootInterface.class);
+    Assert.assertEquals("Configuration conversion to and from Avro datatypes failed.", before, after);
+  }
+
+  @Test
+  public void testRoundTripWithClassHierarchy() throws Exception {
+    // TODO: use 'getConfiguration' instead of 'getConfigurationWithoutList' after #192 is fixed
+    final Configuration confBefore = ObjectTreeTest.getConfigurationWithoutList();
+    final ClassHierarchy c = new ProtocolBufferClassHierarchy(ProtocolBufferClassHierarchy.serialize(confBefore.getClassHierarchy()));
+    final Configuration confAfter = roundTrip(confBefore, c);
+    Assert.assertEquals(confBefore.getNamedParameters().size(), confAfter.getNamedParameters().size());
+    //For now, we cannot use ProtocolBufferClassHierarchy to do injection
+  }
+}


[12/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/AbstractNode.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/AbstractNode.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/AbstractNode.java
new file mode 100644
index 0000000..fb34bbb
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/AbstractNode.java
@@ -0,0 +1,127 @@
+/**
+ * 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.reef.tang.implementation.types;
+
+import org.apache.reef.tang.types.Node;
+import org.apache.reef.tang.util.MonotonicTreeMap;
+
+import java.util.Collection;
+import java.util.Map;
+
+public abstract class AbstractNode implements Node {
+  protected final Map<String, Node> children = new MonotonicTreeMap<>();
+  private final Node parent;
+  private final String name;
+  private final String fullName;
+
+  public AbstractNode(Node parent, String name, String fullName) {
+    this.parent = parent;
+    this.name = name;
+    this.fullName = fullName;
+    if (parent != null) {
+      if (name.length() == 0) {
+        throw new IllegalArgumentException(
+            "Zero length child name means bad news");
+      }
+      parent.put(this);
+    }
+  }
+
+  @Override
+  public Collection<Node> getChildren() {
+    return children.values();
+  }
+
+  @Override
+  public String getFullName() {
+    return fullName;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (o == null) return false;
+    if (o == this) return true;
+
+    AbstractNode n = (AbstractNode) o;
+    final boolean parentsEqual;
+    if (n.parent == this.parent) {
+      parentsEqual = true;
+    } else if (n.parent == null) {
+      parentsEqual = false;
+    } else if (this.parent == null) {
+      parentsEqual = false;
+    } else {
+      parentsEqual = n.parent.equals(this.parent);
+    }
+    if (!parentsEqual) {
+      return false;
+    }
+    return this.name.equals(n.name);
+  }
+
+  @Override
+  public Node getParent() {
+    return parent;
+  }
+
+  @Override
+  public boolean contains(String key) {
+    return children.containsKey(key);
+  }
+
+  @Override
+  public Node get(String key) {
+    return children.get(key);
+  }
+
+  @Override
+  public void put(Node n) {
+    children.put(n.getName(), n);
+  }
+
+  @SuppressWarnings("unused")
+  private String toIndentedString(int level) {
+    StringBuilder sb = new StringBuilder();
+    for (int i = 0; i < level; i++) {
+      sb.append("\t");
+    }
+    sb.append(toString() + "\n");
+    if (children != null) {
+      for (Node n : children.values()) {
+        sb.append(((AbstractNode) n).toIndentedString(level + 1));
+      }
+    }
+    return sb.toString();
+  }
+
+  @Override
+  public String toString() {
+    return "[" + this.getClass().getSimpleName() + " '" + getFullName() + "']";
+  }
+
+  @Override
+  public String getName() {
+    return name;
+  }
+
+  @Override
+  public int compareTo(Node n) {
+    return getFullName().compareTo(n.getFullName());
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/ClassNodeImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/ClassNodeImpl.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/ClassNodeImpl.java
new file mode 100644
index 0000000..672f37a
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/ClassNodeImpl.java
@@ -0,0 +1,141 @@
+/**
+ * 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.reef.tang.implementation.types;
+
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.types.ClassNode;
+import org.apache.reef.tang.types.ConstructorDef;
+import org.apache.reef.tang.types.Node;
+import org.apache.reef.tang.util.MonotonicSet;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+public class ClassNodeImpl<T> extends AbstractNode implements ClassNode<T> {
+  private final boolean injectable;
+  private final boolean unit;
+  private final boolean externalConstructor;
+  private final ConstructorDef<T>[] injectableConstructors;
+  private final ConstructorDef<T>[] allConstructors;
+  private final MonotonicSet<ClassNode<T>> knownImpls;
+  private final String defaultImpl;
+
+  public ClassNodeImpl(Node parent, String simpleName, String fullName,
+                       boolean unit, boolean injectable, boolean externalConstructor,
+                       ConstructorDef<T>[] injectableConstructors,
+                       ConstructorDef<T>[] allConstructors,
+                       String defaultImplementation) {
+    super(parent, simpleName, fullName);
+    this.unit = unit;
+    this.injectable = injectable;
+    this.externalConstructor = externalConstructor;
+    this.injectableConstructors = injectableConstructors;
+    this.allConstructors = allConstructors;
+    this.knownImpls = new MonotonicSet<>();
+    this.defaultImpl = defaultImplementation;
+  }
+
+  @Override
+  public ConstructorDef<T>[] getInjectableConstructors() {
+    return injectableConstructors;
+  }
+
+  @Override
+  public ConstructorDef<T>[] getAllConstructors() {
+    return allConstructors;
+  }
+
+  @Override
+  public boolean isInjectionCandidate() {
+    return injectable;
+  }
+
+  @Override
+  public boolean isExternalConstructor() {
+    return externalConstructor;
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder(super.toString() + ": ");
+    if (getInjectableConstructors() != null) {
+      for (ConstructorDef<T> c : getInjectableConstructors()) {
+        sb.append(c.toString() + ", ");
+      }
+    } else {
+      sb.append("OBJECT BUILD IN PROGRESS!  BAD NEWS!");
+    }
+    return sb.toString();
+  }
+
+  public ConstructorDef<T> getConstructorDef(ClassNode<?>... paramTypes)
+      throws BindException {
+    if (!isInjectionCandidate()) {
+      throw new BindException("Cannot @Inject non-static member/local class: "
+          + getFullName());
+    }
+    for (ConstructorDef<T> c : getAllConstructors()) {
+      if (c.takesParameters(paramTypes)) {
+        return c;
+      }
+    }
+    throw new BindException("Could not find requested constructor for class "
+        + getFullName());
+  }
+
+  @Override
+  public void putImpl(ClassNode<T> impl) {
+    knownImpls.add(impl);
+  }
+
+  @Override
+  public Set<ClassNode<T>> getKnownImplementations() {
+    return new MonotonicSet<>(knownImpls);
+  }
+
+  @Override
+  public boolean isUnit() {
+    return unit;
+  }
+
+  @Override
+  public boolean isImplementationOf(ClassNode<?> inter) {
+    List<ClassNode<?>> worklist = new ArrayList<>();
+    if (this.equals(inter)) {
+      return true;
+    }
+    worklist.add(inter);
+    while (!worklist.isEmpty()) {
+      ClassNode<?> cn = worklist.remove(worklist.size() - 1);
+      @SuppressWarnings({"rawtypes", "unchecked"})
+      Set<ClassNode<?>> impls = (Set) cn.getKnownImplementations();
+      if (impls.contains(this)) {
+        return true;
+      }
+      worklist.addAll(impls);
+    }
+    return false;
+  }
+
+  @Override
+  public String getDefaultImplementation() {
+    return defaultImpl;
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/ConstructorArgImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/ConstructorArgImpl.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/ConstructorArgImpl.java
new file mode 100644
index 0000000..8232339
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/ConstructorArgImpl.java
@@ -0,0 +1,77 @@
+/**
+ * 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.reef.tang.implementation.types;
+
+import org.apache.reef.tang.types.ConstructorArg;
+
+public class ConstructorArgImpl implements ConstructorArg {
+  private final String type;
+  private final String name;
+  private final boolean isInjectionFuture;
+
+  public ConstructorArgImpl(String type, String namedParameterName, boolean isInjectionFuture) {
+    this.type = type;
+    this.name = namedParameterName;
+    this.isInjectionFuture = isInjectionFuture;
+  }
+
+  @Override
+  public String getName() {
+    return name == null ? type : name;
+  }
+
+  @Override
+  public String getNamedParameterName() {
+    return name;
+  }
+
+  @Override
+  public String getType() {
+    return type;
+  }
+
+  @Override
+  public String toString() {
+    return name == null ? type : type + " " + name;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    ConstructorArgImpl arg = (ConstructorArgImpl) o;
+    if (!type.equals(arg.type)) {
+      return false;
+    }
+    if (name == null && arg.name == null) {
+      return true;
+    }
+    if (name == null && arg.name != null) {
+      return false;
+    }
+    if (name != null && arg.name == null) {
+      return false;
+    }
+    return name.equals(arg.name);
+
+  }
+
+  @Override
+  public boolean isInjectionFuture() {
+    return isInjectionFuture;
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/ConstructorDefImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/ConstructorDefImpl.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/ConstructorDefImpl.java
new file mode 100644
index 0000000..2c27eb1
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/ConstructorDefImpl.java
@@ -0,0 +1,150 @@
+/**
+ * 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.reef.tang.implementation.types;
+
+import org.apache.reef.tang.exceptions.ClassHierarchyException;
+import org.apache.reef.tang.types.ClassNode;
+import org.apache.reef.tang.types.ConstructorArg;
+import org.apache.reef.tang.types.ConstructorDef;
+
+public class ConstructorDefImpl<T> implements ConstructorDef<T> {
+  private final ConstructorArg[] args;
+  private final String className;
+
+  public ConstructorDefImpl(String className, ConstructorArg[] args,
+                            boolean injectable) throws ClassHierarchyException {
+    this.className = className;
+    this.args = args;
+    if (injectable) {
+      for (int i = 0; i < this.getArgs().length; i++) {
+        for (int j = i + 1; j < this.getArgs().length; j++) {
+          if (this.getArgs()[i].equals(this.getArgs()[j])) {
+            throw new ClassHierarchyException(
+                "Repeated constructor parameter detected.  "
+                    + "Cannot inject constructor " + toString());
+          }
+        }
+      }
+    }
+  }
+
+  @Override
+  public ConstructorArg[] getArgs() {
+    return args;
+  }
+
+  @Override
+  public String getClassName() {
+    return className;
+  }
+
+  private String join(String sep, Object[] vals) {
+    if (vals.length != 0) {
+      StringBuilder sb = new StringBuilder(vals[0].toString());
+      for (int i = 1; i < vals.length; i++) {
+        sb.append(sep + vals[i]);
+      }
+      return sb.toString();
+    } else {
+      return "";
+    }
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder(className);
+    sb.append("(");
+    sb.append(join(",", args));
+    sb.append(")");
+    return sb.toString();
+  }
+
+  @Override
+  public boolean takesParameters(ClassNode<?>[] paramTypes) {
+    if (paramTypes.length != args.length) {
+      return false;
+    }
+    for (int i = 0; i < paramTypes.length; i++) {
+      if (!args[i].getType().equals(paramTypes[i].getFullName())) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  /**
+   * Check to see if two boundConstructors take indistinguishable arguments. If
+   * so (and they are in the same class), then this would lead to ambiguous
+   * injection targets, and we want to fail fast.
+   * <p/>
+   * TODO could be faster. Currently O(n^2) in number of parameters.
+   *
+   * @param def
+   * @return
+   */
+  private boolean equalsIgnoreOrder(ConstructorDef<?> def) {
+    if (getArgs().length != def.getArgs().length) {
+      return false;
+    }
+    for (int i = 0; i < getArgs().length; i++) {
+      boolean found = false;
+      for (int j = 0; j < def.getArgs().length; j++) {
+        if (getArgs()[i].getName().equals(def.getArgs()[j].getName())) {
+          found = true;
+        }
+      }
+      if (!found) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    return equalsIgnoreOrder((ConstructorDef<?>) o);
+  }
+
+  @Override
+  public boolean isMoreSpecificThan(ConstructorDef<?> def) {
+    // Return true if our list of args is a superset of those in def.
+
+    // Is everything in def also in this?
+    for (int i = 0; i < def.getArgs().length; i++) {
+      boolean found = false;
+      for (int j = 0; j < this.getArgs().length; j++) {
+        if (getArgs()[j].equals(def.getArgs()[i])) {
+          found = true;
+          break;
+        }
+      }
+      // If not, then argument j from def is not in our list.  Return false.
+      if (found == false)
+        return false;
+    }
+    // Everything in def's arg list is in ours.  Do we have at least one extra
+    // argument?
+    return getArgs().length > def.getArgs().length;
+  }
+
+  @Override
+  public int compareTo(ConstructorDef<?> o) {
+    return toString().compareTo(o.toString());
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/NamedParameterNodeImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/NamedParameterNodeImpl.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/NamedParameterNodeImpl.java
new file mode 100644
index 0000000..f2e796d
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/NamedParameterNodeImpl.java
@@ -0,0 +1,86 @@
+/**
+ * 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.reef.tang.implementation.types;
+
+import org.apache.reef.tang.types.NamedParameterNode;
+import org.apache.reef.tang.types.Node;
+
+public class NamedParameterNodeImpl<T> extends AbstractNode implements
+    NamedParameterNode<T> {
+  private final String fullArgName;
+  private final String simpleArgName;
+  private final String documentation;
+  private final String shortName;
+  private final String[] defaultInstanceAsStrings;
+  private final boolean isSet;
+  private final boolean isList;
+
+  public NamedParameterNodeImpl(Node parent, String simpleName,
+                                String fullName, String fullArgName, String simpleArgName, boolean isSet, boolean isList,
+                                String documentation, String shortName, String[] defaultInstanceAsStrings) {
+    super(parent, simpleName, fullName);
+    this.fullArgName = fullArgName;
+    this.simpleArgName = simpleArgName;
+    this.isSet = isSet;
+    this.isList = isList;
+    this.documentation = documentation;
+    this.shortName = shortName;
+    this.defaultInstanceAsStrings = defaultInstanceAsStrings;
+  }
+
+  @Override
+  public String toString() {
+    return getSimpleArgName() + " " + getName();
+  }
+
+  @Override
+  public String getSimpleArgName() {
+    return simpleArgName;
+  }
+
+  @Override
+  public String getFullArgName() {
+    return fullArgName;
+  }
+
+  @Override
+  public String getDocumentation() {
+    return documentation;
+  }
+
+  @Override
+  public String getShortName() {
+    return shortName;
+  }
+
+  @Override
+  public String[] getDefaultInstanceAsStrings() {
+    return defaultInstanceAsStrings;
+  }
+
+  @Override
+  public boolean isSet() {
+    return isSet;
+  }
+
+  @Override
+  public boolean isList() {
+    return isList;
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/PackageNodeImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/PackageNodeImpl.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/PackageNodeImpl.java
new file mode 100644
index 0000000..16ee0aa
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/PackageNodeImpl.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.tang.implementation.types;
+
+import org.apache.reef.tang.types.Node;
+import org.apache.reef.tang.types.PackageNode;
+
+public class PackageNodeImpl extends AbstractNode implements PackageNode {
+  public PackageNodeImpl(Node parent, String name, String fullName) {
+    super(parent, name, fullName);
+  }
+
+  public PackageNodeImpl() {
+    this(null, "", "[root node]");
+  }
+
+  /**
+   * Unlike normal nodes, the root node needs to take the package name of its
+   * children into account.  Therefore, we use the full name as the key when
+   * we insert nodes into the root.
+   */
+  @Override
+  public void put(Node n) {
+    super.children.put(n.getFullName(), n);
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/package-info.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/package-info.java
new file mode 100644
index 0000000..9b0f605
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/types/package-info.java
@@ -0,0 +1,26 @@
+/**
+ * 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.
+ */
+/**
+ * Implementations of the ClassHierarchy type system.  These classes encode
+ * language independent data.  Java specializations of these types are in
+ * org.apache.reef.tang.implementation.java.
+ */
+
+package org.apache.reef.tang.implementation.types;
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/package-info.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/package-info.java
new file mode 100644
index 0000000..23b203f
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/package-info.java
@@ -0,0 +1,27 @@
+/**
+ * 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.
+ */
+/**
+ * Public interfaces and factories for Tang's core API.
+ *
+ * Other packages that are of interest to typical Tang use-cases are
+ * org.apache.reef.tang.annotations which contains Java annotations that encode
+ * Tang configuration metadata, and org.apache.reef.tang.formats, which
+ * contains classes that import and export data from Tang in various formats.
+ */
+package org.apache.reef.tang;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/ClassNode.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/ClassNode.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/ClassNode.java
new file mode 100644
index 0000000..8c5c19b
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/ClassNode.java
@@ -0,0 +1,47 @@
+/**
+ * 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.reef.tang.types;
+
+import org.apache.reef.tang.exceptions.BindException;
+
+import java.util.Set;
+
+public interface ClassNode<T> extends Node {
+
+  public ConstructorDef<T>[] getInjectableConstructors();
+
+  public ConstructorDef<T> getConstructorDef(ClassNode<?>... args)
+      throws BindException;
+
+  public ConstructorDef<T>[] getAllConstructors();
+
+  public void putImpl(ClassNode<T> impl);
+
+  public Set<ClassNode<T>> getKnownImplementations();
+
+  public String getDefaultImplementation();
+
+  public boolean isUnit();
+
+  public boolean isInjectionCandidate();
+
+  public boolean isExternalConstructor();
+
+  public boolean isImplementationOf(ClassNode<?> inter);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/ConstructorArg.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/ConstructorArg.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/ConstructorArg.java
new file mode 100644
index 0000000..811af9e
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/ConstructorArg.java
@@ -0,0 +1,30 @@
+/**
+ * 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.reef.tang.types;
+
+public interface ConstructorArg {
+
+  public String getName();
+
+  public String getType();
+
+  public boolean isInjectionFuture();
+
+  public String getNamedParameterName();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/ConstructorDef.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/ConstructorDef.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/ConstructorDef.java
new file mode 100644
index 0000000..92922c7
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/ConstructorDef.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.tang.types;
+
+public interface ConstructorDef<T> extends Comparable<ConstructorDef<?>> {
+  public String getClassName();
+
+  public ConstructorArg[] getArgs();
+
+  public boolean isMoreSpecificThan(ConstructorDef<?> def);
+
+  public boolean takesParameters(ClassNode<?>[] paramTypes);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/NamedParameterNode.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/NamedParameterNode.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/NamedParameterNode.java
new file mode 100644
index 0000000..94d0f9c
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/NamedParameterNode.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.tang.types;
+
+public interface NamedParameterNode<T> extends Node {
+
+  public String getDocumentation();
+
+  public String getShortName();
+
+  public String[] getDefaultInstanceAsStrings();
+
+  public String getSimpleArgName();
+
+  public String getFullArgName();
+
+  public boolean isSet();
+
+  public boolean isList();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/Node.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/Node.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/Node.java
new file mode 100644
index 0000000..53d5ac5
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/Node.java
@@ -0,0 +1,42 @@
+/**
+ * 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.reef.tang.types;
+
+import java.util.Collection;
+
+public interface Node extends Comparable<Node>, Traversable<Node> {
+
+  String getName();
+
+  String getFullName();
+
+  boolean contains(String key);
+
+  Node get(String key);
+
+  Node getParent();
+
+  void put(Node node);
+
+  @Override
+  Collection<Node> getChildren();
+
+  @Override
+  String toString();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/PackageNode.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/PackageNode.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/PackageNode.java
new file mode 100644
index 0000000..5e7f20d
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/PackageNode.java
@@ -0,0 +1,23 @@
+/**
+ * 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.reef.tang.types;
+
+public interface PackageNode extends Node {
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/Traversable.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/Traversable.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/Traversable.java
new file mode 100644
index 0000000..445435c
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/Traversable.java
@@ -0,0 +1,26 @@
+/**
+ * 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.reef.tang.types;
+
+import java.util.Collection;
+
+public interface Traversable<T extends Traversable<T>> {
+
+  Collection<T> getChildren();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/package-info.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/package-info.java
new file mode 100644
index 0000000..c76fe0e
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/types/package-info.java
@@ -0,0 +1,26 @@
+/**
+ * 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.
+ */
+/**
+ * The interfaces that define Tang's ClassHierarchy objects.  ClassHierarchies
+ * can be thought of as read-only caches of the reflection data that is
+ * produced when applications are compiled.
+ */
+
+package org.apache.reef.tang.types;
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/AbstractMonotonicMultiMap.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/AbstractMonotonicMultiMap.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/AbstractMonotonicMultiMap.java
new file mode 100644
index 0000000..31c023d
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/AbstractMonotonicMultiMap.java
@@ -0,0 +1,206 @@
+/**
+ * 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.reef.tang.util;
+
+import java.util.*;
+import java.util.Map.Entry;
+
+public abstract class AbstractMonotonicMultiMap<K, V> implements Collection<Entry<K, V>> {
+  protected Map<K, Set<V>> map;
+  private int size = 0;
+
+  public AbstractMonotonicMultiMap(Map<K, Set<V>> map) {
+    this.map = map;
+  }
+
+  public void put(K key, V v) {
+    Set<V> vals = map.get(key);
+    if (vals == null) {
+      vals = new MonotonicHashSet<V>();
+      map.put(key, vals);
+    }
+    vals.add(v);
+    size++;
+  }
+
+  public Set<K> keySet() {
+    return map.keySet();
+  }
+
+  public Set<V> getValuesForKey(K key) {
+    Set<V> ret = map.get(key);
+    if (ret == null) {
+      return new MonotonicHashSet<V>();
+    } else {
+      return ret;
+    }
+  }
+
+  public boolean contains(K key, V v) {
+    Set<V> vals = map.get(key);
+    if (vals != null) {
+      return vals.contains(v);
+    }
+    return false;
+  }
+
+  @Override
+  public boolean add(Entry<K, V> e) {
+    put(e.getKey(), e.getValue());
+    return true;
+  }
+
+  @Override
+  public boolean addAll(Collection<? extends Entry<K, V>> c) {
+    boolean ret = false;
+    for (Entry<K, V> e : c) {
+      add(e);
+      ret = true;
+    }
+    return ret;
+  }
+
+  @Override
+  public void clear() {
+    throw new UnsupportedOperationException("MonotonicMultiMap cannot be cleared!");
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public boolean contains(Object o) {
+    Entry<?, ?> e = (Entry<?, ?>) o;
+    return contains((K) e.getKey(), (V) e.getValue());
+  }
+
+  @Override
+  public boolean containsAll(Collection<?> c) {
+    for (Object o : c) {
+      if (!contains(o)) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  @Override
+  public boolean isEmpty() {
+    return size == 0;
+  }
+
+  @Override
+  public Iterator<Entry<K, V>> iterator() {
+    final Iterator<Entry<K, Set<V>>> it = map.entrySet().iterator();
+    return new Iterator<Entry<K, V>>() {
+      Iterator<V> cur;
+      K curKey;
+
+      @Override
+      public boolean hasNext() {
+        return it.hasNext() || (cur != null && cur.hasNext());
+      }
+
+      @Override
+      public Entry<K, V> next() {
+        if (cur == null) {
+          if (it.hasNext()) {
+            Entry<K, Set<V>> e = it.next();
+            curKey = e.getKey();
+            cur = e.getValue().iterator();
+          }
+        }
+        final K k = curKey;
+        final V v = cur.next();
+        if (!cur.hasNext()) {
+          cur = null;
+        }
+
+        return new Entry<K, V>() {
+
+          @Override
+          public K getKey() {
+            return k;
+          }
+
+          @Override
+          public V getValue() {
+            return v;
+          }
+
+          @Override
+          public V setValue(V value) {
+            throw new UnsupportedOperationException();
+          }
+
+        };
+      }
+
+      @Override
+      public void remove() {
+        throw new UnsupportedOperationException();
+      }
+
+    };
+  }
+
+  public Set<V> values() {
+    Set<V> s = new HashSet<>();
+    for (Entry<K, V> e : this) {
+      s.add(e.getValue());
+    }
+    return s;
+  }
+
+  @Override
+  public boolean remove(Object o) {
+    throw new UnsupportedOperationException("MonotonicMultiMap does not support non-monotonic method remove!");
+  }
+
+  @Override
+  public boolean removeAll(Collection<?> c) {
+    throw new UnsupportedOperationException("MonotonicMultiMap does not support non-monotonic method removeAll!");
+  }
+
+  @Override
+  public boolean retainAll(Collection<?> c) {
+    throw new UnsupportedOperationException("MonotonicMultiMap does not support non-monotonic method retainAll!");
+  }
+
+  @Override
+  public int size() {
+    return size;
+  }
+
+  @Override
+  public Entry<K, V>[] toArray() {
+    throw new UnsupportedOperationException("No toArray() for MonotonicMulitMap (yet)");
+  }
+
+  @Override
+  public <T> T[] toArray(T[] a) {
+    throw new UnsupportedOperationException("No toArray() for MonotonicMulitMap (yet)");
+  }
+
+  public boolean containsKey(K k) {
+    if (map.containsKey(k)) {
+      return !getValuesForKey(k).isEmpty();
+    } else {
+      return false;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicHashMap.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicHashMap.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicHashMap.java
new file mode 100644
index 0000000..8c5cc6d
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicHashMap.java
@@ -0,0 +1,58 @@
+/**
+ * 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.reef.tang.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class MonotonicHashMap<T, U> extends HashMap<T, U> {
+  private static final long serialVersionUID = 1L;
+
+  @Override
+  public U put(T key, U value) {
+    U old = super.get(key);
+    if (old != null) {
+      throw new IllegalArgumentException("Attempt to re-add: [" + key
+          + "] old value: " + old + " new value " + value);
+    }
+    return super.put(key, value);
+  }
+
+  @Override
+  public void putAll(Map<? extends T, ? extends U> m) {
+    for (T t : m.keySet()) {
+      if (containsKey(t)) {
+        put(t, m.get(t)); // guaranteed to throw.
+      }
+    }
+    for (T t : m.keySet()) {
+      put(t, m.get(t));
+    }
+  }
+
+  @Override
+  public void clear() {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public U remove(Object o) {
+    throw new UnsupportedOperationException();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicHashSet.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicHashSet.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicHashSet.java
new file mode 100644
index 0000000..aa9b12e
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicHashSet.java
@@ -0,0 +1,91 @@
+/**
+ * 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.reef.tang.util;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+
+public class MonotonicHashSet<T> extends HashSet<T> {
+  private static final long serialVersionUID = 1L;
+
+  public MonotonicHashSet() {
+    super();
+  }
+
+  public MonotonicHashSet(Collection<T> c) {
+    super(c);
+  }
+
+  @SafeVarargs
+  public MonotonicHashSet(T... c) {
+    super(Arrays.asList(c));
+  }
+
+  @Override
+  public boolean add(T e) {
+    if (super.contains(e)) {
+      throw new IllegalArgumentException("Attempt to re-add " + e
+          + " to MonotonicSet!");
+    }
+    return super.add(e);
+  }
+
+  @Override
+  public void clear() {
+    throw new UnsupportedOperationException("Attempt to clear MonotonicSet!");
+  }
+
+  @Override
+  public boolean remove(Object o) {
+    throw new UnsupportedOperationException("Attempt to remove " + o
+        + " from MonotonicSet!");
+  }
+
+  @Override
+  public boolean removeAll(Collection<?> c) {
+    throw new UnsupportedOperationException(
+        "removeAll() doesn't make sense for MonotonicSet!");
+  }
+
+  @Override
+  public boolean retainAll(Collection<?> c) {
+    throw new UnsupportedOperationException(
+        "retainAll() doesn't make sense for MonotonicSet!");
+  }
+
+  @Override
+  public boolean addAll(Collection<? extends T> c) {
+    for (T t : c) {
+      add(t);
+    }
+    return c.size() != 0;
+  }
+
+  public boolean addAllIgnoreDuplicates(Collection<? extends T> c) {
+    boolean ret = false;
+    for (T t : c) {
+      if (!contains(t)) {
+        add(t);
+        ret = true;
+      }
+    }
+    return ret;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicMultiHashMap.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicMultiHashMap.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicMultiHashMap.java
new file mode 100644
index 0000000..34cdeea
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicMultiHashMap.java
@@ -0,0 +1,25 @@
+/**
+ * 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.reef.tang.util;
+
+public class MonotonicMultiHashMap<K, V> extends AbstractMonotonicMultiMap<K, V> {
+  public MonotonicMultiHashMap() {
+    super(new MonotonicHashMap<K, java.util.Set<V>>());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicMultiMap.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicMultiMap.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicMultiMap.java
new file mode 100644
index 0000000..3eb7ecb
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicMultiMap.java
@@ -0,0 +1,25 @@
+/**
+ * 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.reef.tang.util;
+
+public class MonotonicMultiMap<K, V> extends AbstractMonotonicMultiMap<K, V> {
+  public MonotonicMultiMap() {
+    super(new MonotonicTreeMap<K, java.util.Set<V>>());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicSet.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicSet.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicSet.java
new file mode 100644
index 0000000..c272e4f
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicSet.java
@@ -0,0 +1,91 @@
+/**
+ * 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.reef.tang.util;
+
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.TreeSet;
+
+public class MonotonicSet<T> extends TreeSet<T> {
+  private static final long serialVersionUID = 1L;
+
+  public MonotonicSet() {
+    super();
+  }
+
+  public MonotonicSet(TreeSet<T> c) {
+    super(c.comparator());
+    addAll(c);
+  }
+
+  public MonotonicSet(Comparator<T> c) {
+    super(c);
+  }
+
+  @Override
+  public boolean add(T e) {
+    if (super.contains(e)) {
+      throw new IllegalArgumentException("Attempt to re-add " + e
+          + " to MonotonicSet!");
+    }
+    return super.add(e);
+  }
+
+  @Override
+  public void clear() {
+    throw new UnsupportedOperationException("Attempt to clear MonotonicSet!");
+  }
+
+  @Override
+  public boolean remove(Object o) {
+    throw new UnsupportedOperationException("Attempt to remove " + o
+        + " from MonotonicSet!");
+  }
+
+  @Override
+  public boolean removeAll(Collection<?> c) {
+    throw new UnsupportedOperationException(
+        "removeAll() doesn't make sense for MonotonicSet!");
+  }
+
+  @Override
+  public boolean retainAll(Collection<?> c) {
+    throw new UnsupportedOperationException(
+        "retainAll() doesn't make sense for MonotonicSet!");
+  }
+
+  @Override
+  public boolean addAll(Collection<? extends T> c) {
+    for (T t : c) {
+      add(t);
+    }
+    return c.size() != 0;
+  }
+
+  public boolean addAllIgnoreDuplicates(Collection<? extends T> c) {
+    boolean ret = false;
+    for (T t : c) {
+      if (!contains(t)) {
+        add(t);
+        ret = true;
+      }
+    }
+    return ret;
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicTreeMap.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicTreeMap.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicTreeMap.java
new file mode 100644
index 0000000..3b84311
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/MonotonicTreeMap.java
@@ -0,0 +1,119 @@
+/**
+ * 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.reef.tang.util;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+public final class MonotonicTreeMap<T, U> implements Map<T, U> {
+  private static final long serialVersionUID = 1L;
+
+  private final TreeMap<T, U> innerMap = new TreeMap<>();
+
+
+  @Override
+  public int size() {
+    return innerMap.size();
+  }
+
+  @Override
+  public boolean isEmpty() {
+    return innerMap.isEmpty();
+  }
+
+  @Override
+  public boolean containsKey(final Object o) {
+    return innerMap.containsKey(o);
+  }
+
+  @Override
+  public boolean containsValue(final Object o) {
+    return innerMap.containsValue(o);
+  }
+
+  @Override
+  public U get(final Object o) {
+    return innerMap.get(o);
+  }
+
+  @Override
+  public U put(T key, U value) {
+    U old = innerMap.get(key);
+    if (old != null) {
+      throw new IllegalArgumentException("Attempt to re-add: [" + key
+          + "]\n old value: " + old + " new value " + value);
+    }
+    return innerMap.put(key, value);
+  }
+
+  @Override
+  public void putAll(Map<? extends T, ? extends U> m) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public void clear() {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public Set<T> keySet() {
+    return innerMap.keySet();
+  }
+
+  @Override
+  public Collection<U> values() {
+    return innerMap.values();
+  }
+
+  @Override
+  public Set<Entry<T, U>> entrySet() {
+    return innerMap.entrySet();
+  }
+
+  @Override
+  public U remove(Object o) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) {
+      return true;
+    }
+    if (o == null || getClass() != o.getClass()) {
+      return false;
+    }
+
+    final MonotonicTreeMap that = (MonotonicTreeMap) o;
+
+    if (!innerMap.equals(that.innerMap)) {
+      return false;
+    }
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return innerMap.hashCode();
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/ReflectionUtilities.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/ReflectionUtilities.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/ReflectionUtilities.java
new file mode 100644
index 0000000..3157ba8
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/ReflectionUtilities.java
@@ -0,0 +1,397 @@
+/**
+ * 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.reef.tang.util;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.ClassHierarchyException;
+
+import javax.inject.Inject;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.*;
+import java.util.*;
+
+public class ReflectionUtilities {
+  /**
+   * This is used to split Java classnames.  Currently, we split on . and on $
+   */
+  public final static String regexp = "[\\.\\$]";
+  /**
+   * A map from numeric classes to the number of bits used by their representations.
+   */
+  private final static Map<Class<?>, Integer> sizeof = new HashMap<>();
+
+  static {
+    sizeof.put(Byte.class, Byte.SIZE);
+    sizeof.put(Short.class, Short.SIZE);
+    sizeof.put(Integer.class, Integer.SIZE);
+    sizeof.put(Long.class, Long.SIZE);
+    sizeof.put(Float.class, Float.SIZE);
+    sizeof.put(Double.class, Double.SIZE);
+  }
+
+  /**
+   * Given a primitive type, return its boxed representation.
+   * <p/>
+   * Examples:
+   * boxClass(int.class) -> Integer.class
+   * boxClass(String.class) -> String.class
+   *
+   * @param c The class to be boxed.
+   * @return The boxed version of c, or c if it is not a primitive type.
+   */
+  public static Class<?> boxClass(Class<?> c) {
+    if (c.isPrimitive() && c != Class.class) {
+      if (c == boolean.class) {
+        return Boolean.class;
+      } else if (c == byte.class) {
+        return Byte.class;
+      } else if (c == char.class) {
+        return Character.class;
+      } else if (c == short.class) {
+        return Short.class;
+      } else if (c == int.class) {
+        return Integer.class;
+      } else if (c == long.class) {
+        return Long.class;
+      } else if (c == float.class) {
+        return Float.class;
+      } else if (c == double.class) {
+        return Double.class;
+      } else if (c == void.class) {
+        return Void.class;
+      } else {
+        throw new UnsupportedOperationException(
+            "Encountered unknown primitive type!");
+      }
+    } else {
+      return c;
+    }
+  }
+
+  /**
+   * Given a Type, return all of the classes it extends and interfaces it implements (including the class itself).
+   * <p/>
+   * Examples:
+   * Integer.class -> {Integer.class, Number.class, Object.class}
+   * T -> Object
+   * ? -> Object
+   * HashSet<T> -> {HashSet<T>, Set<T>, Collection<T>, Object}
+   * FooEventHandler -> {FooEventHandler, EventHandler<Foo>, Object}
+   */
+  public static Iterable<Type> classAndAncestors(Type c) {
+    List<Type> workQueue = new ArrayList<>();
+
+    workQueue.add(c);
+    if (getRawClass(c).isInterface()) {
+      workQueue.add(Object.class);
+    }
+    for (int i = 0; i < workQueue.size(); i++) {
+      c = workQueue.get(i);
+
+      if (c instanceof Class) {
+        Class<?> clz = (Class<?>) c;
+        final Type sc = clz.getSuperclass();
+        if (sc != null) workQueue.add(sc); //c.getSuperclass());
+        workQueue.addAll(Arrays.asList(clz.getGenericInterfaces()));
+      } else if (c instanceof ParameterizedType) {
+        ParameterizedType pt = (ParameterizedType) c;
+        Class<?> rawPt = (Class<?>) pt.getRawType();
+        final Type sc = rawPt.getSuperclass();
+//        workQueue.add(pt);
+//        workQueue.add(rawPt);
+        if (sc != null) workQueue.add(sc);
+        workQueue.addAll(Arrays.asList(rawPt.getGenericInterfaces()));
+      } else if (c instanceof WildcardType) {
+        workQueue.add(Object.class); // XXX not really correct, but close enough?
+      } else if (c instanceof TypeVariable) {
+        workQueue.add(Object.class); // XXX not really correct, but close enough?
+      } else {
+        throw new RuntimeException(c.getClass() + " " + c + " is of unknown type!");
+      }
+    }
+    return workQueue;
+  }
+
+  /**
+   * Check to see if one class can be coerced into another.  A class is
+   * coercable to another if, once both are boxed, the target class is a
+   * superclass or implemented interface of the source class.
+   * <p/>
+   * If both classes are numeric types, then this method returns true iff
+   * the conversion will not result in a loss of precision.
+   * <p/>
+   * TODO: Float and double are currently coercible to int and long.  This is a bug.
+   */
+  public static boolean isCoercable(Class<?> to, Class<?> from) {
+    to = boxClass(to);
+    from = boxClass(from);
+    if (Number.class.isAssignableFrom(to)
+        && Number.class.isAssignableFrom(from)) {
+      return sizeof.get(from) <= sizeof.get(to);
+    }
+    return to.isAssignableFrom(from);
+  }
+
+  /**
+   * Lookup the provided name using the provided classloader. This method
+   * includes special handling for primitive types, which can be looked up
+   * by short name (all other types need to be looked up by long name).
+   *
+   * @throws ClassNotFoundException
+   */
+  public static Class<?> classForName(String name, ClassLoader loader)
+      throws ClassNotFoundException {
+    if (name.startsWith("[")) {
+      throw new UnsupportedOperationException("No support for arrays, etc.  Name was: " + name);
+    } else if (name.equals("boolean")) {
+      return boolean.class;
+    } else if (name.equals("byte")) {
+      return byte.class;
+    } else if (name.equals("char")) {
+      return char.class;
+    } else if (name.equals("short")) {
+      return short.class;
+    } else if (name.equals("int")) {
+      return int.class;
+    } else if (name.equals("long")) {
+      return long.class;
+    } else if (name.equals("float")) {
+      return float.class;
+    } else if (name.equals("double")) {
+      return double.class;
+    } else if (name.equals("void")) {
+      return void.class;
+    } else {
+      return loader.loadClass(name);
+    }
+  }
+
+  /**
+   * Get the simple name of the class. This varies from the one in Class, in
+   * that it returns "1" for Classes like java.lang.String$1 In contrast,
+   * String.class.getSimpleName() returns "", which is not unique if
+   * java.lang.String$2 exists, causing all sorts of strange bugs.
+   *
+   * @param name
+   * @return
+   */
+  public static String getSimpleName(Type name) {
+    final Class<?> clazz = getRawClass(name);
+    final String[] nameArray = clazz.getName().split(regexp);
+    final String ret = nameArray[nameArray.length - 1];
+    if (ret.length() == 0) {
+      throw new IllegalArgumentException("Class " + name + " has zero-length simple name.  Can't happen?!?");
+    }
+    return ret;
+  }
+
+  /**
+   * Return the full name of the raw type of the provided Type.
+   * <p/>
+   * Examples:
+   * <p/>
+   * java.lang.String.class -> "java.lang.String"
+   * Set<String> -> "java.util.Set"  // such types can occur as constructor arguments, for example
+   *
+   * @param name
+   * @return
+   */
+  public static String getFullName(Type name) {
+    return getRawClass(name).getName();
+  }
+
+  /**
+   * Return the full name of the provided field.  This will be globally
+   * unique.  Following Java semantics, the full name will have all the
+   * generic parameters stripped out of it.
+   * <p/>
+   * Example:
+   * <p/>
+   * Set<X> { int size; } -> java.util.Set.size
+   */
+  public static String getFullName(Field f) {
+    return getFullName(f.getDeclaringClass()) + "." + f.getName();
+  }
+
+  /**
+   * This method takes a class called clazz that *directly* implements a generic interface or generic class, iface.
+   * Iface should take a single parameter, which this method will return.
+   * <p/>
+   * TODO This is only tested for interfaces, and the type parameters associated with method arguments.
+   * TODO Not sure what we should do in the face of deeply nested generics (eg: Set<Set<String>)
+   * TODO Recurse up the class hierarchy in case there are intermediate interfaces
+   *
+   * @param iface A generic interface; we're looking up it's first (and only) parameter.
+   * @param type  A type that is more specific than clazz, or clazz if no such type is available.
+   * @return The class implemented by the interface, or null(?) if the instantiation was not generic.
+   * @throws IllegalArgumentException if clazz does not directly implement iface.
+   */
+  static public Type getInterfaceTarget(final Class<?> iface, final Type type) throws IllegalArgumentException {
+    if (type instanceof ParameterizedType) {
+      final ParameterizedType pt = (ParameterizedType) type;
+      if (iface.isAssignableFrom((Class<?>) pt.getRawType())) {
+        Type t = pt.getActualTypeArguments()[0];
+        return t;
+      } else {
+        throw new IllegalArgumentException("Parameterized type " + type + " does not extend " + iface);
+      }
+    } else if (type instanceof Class) {
+      final Class<?> clazz = (Class<?>) type;
+
+      if (!clazz.equals(type)) {
+        throw new IllegalArgumentException();
+      }
+
+      ArrayList<Type> al = new ArrayList<>();
+      al.addAll(Arrays.asList(clazz.getGenericInterfaces()));
+      Type sc = clazz.getGenericSuperclass();
+      if (sc != null) al.add(sc);
+
+      final Type[] interfaces = al.toArray(new Type[0]);
+
+      for (Type genericNameType : interfaces) {
+        if (genericNameType instanceof ParameterizedType) {
+          ParameterizedType ptype = (ParameterizedType) genericNameType;
+          if (ptype.getRawType().equals(iface)) {
+            Type t = ptype.getActualTypeArguments()[0];
+            return t;
+          }
+        }
+      }
+      throw new IllegalArgumentException(clazz + " does not directly implement " + iface);
+    } else {
+      throw new UnsupportedOperationException("Do not know how to get interface target of " + type);
+    }
+  }
+
+  /**
+   * @param clazz
+   * @return T if clazz implements Name<T>, null otherwise
+   * @throws BindException If clazz's definition incorrectly uses Name or @NamedParameter
+   */
+  static public Type getNamedParameterTargetOrNull(Class<?> clazz)
+      throws ClassHierarchyException {
+    Annotation npAnnotation = clazz.getAnnotation(NamedParameter.class);
+    boolean hasSuperClass = (clazz.getSuperclass() != Object.class);
+
+    boolean isInjectable = false;
+    boolean hasConstructor = false;
+    // TODO Figure out how to properly differentiate between default and
+    // non-default zero-arg constructors?
+    Constructor<?>[] constructors = clazz.getDeclaredConstructors();
+    if (constructors.length > 1) {
+      hasConstructor = true;
+    }
+    if (constructors.length == 1) {
+      Constructor<?> c = constructors[0];
+      Class<?>[] p = c.getParameterTypes();
+      if (p.length > 1) {
+        // Multiple args. Definitely not implicit.
+        hasConstructor = true;
+      } else if (p.length == 1) {
+        // One arg. Could be an inner class, in which case the compiler
+        // included an implicit one parameter constructor that takes the
+        // enclosing type.
+        if (p[0] != clazz.getEnclosingClass()) {
+          hasConstructor = true;
+        }
+      }
+    }
+    for (Constructor<?> c : constructors) {
+      for (Annotation a : c.getDeclaredAnnotations()) {
+        if (a instanceof Inject) {
+          isInjectable = true;
+        }
+      }
+    }
+
+    Class<?>[] allInterfaces = clazz.getInterfaces();
+
+    boolean hasMultipleInterfaces = (allInterfaces.length > 1);
+    boolean implementsName;
+    Type parameterClass = null;
+    try {
+      parameterClass = getInterfaceTarget(Name.class, clazz);
+      implementsName = true;
+    } catch (IllegalArgumentException e) {
+      implementsName = false;
+    }
+
+    if (npAnnotation == null) {
+      if (implementsName) {
+        throw new ClassHierarchyException("Named parameter " + getFullName(clazz)
+            + " is missing its @NamedParameter annotation.");
+      } else {
+        return null;
+      }
+    } else {
+      if (!implementsName) {
+        throw new ClassHierarchyException("Found illegal @NamedParameter " + getFullName(clazz)
+            + " does not implement Name<?>");
+      }
+      if (hasSuperClass) {
+        throw new ClassHierarchyException("Named parameter " + getFullName(clazz)
+            + " has a superclass other than Object.");
+      }
+      if (hasConstructor || isInjectable) {
+        throw new ClassHierarchyException("Named parameter " + getFullName(clazz) + " has "
+            + (isInjectable ? "an injectable" : "a") + " constructor. "
+            + " Named parameters must not declare any constructors.");
+      }
+      if (hasMultipleInterfaces) {
+        throw new ClassHierarchyException("Named parameter " + getFullName(clazz) + " implements "
+            + "multiple interfaces.  It is only allowed to implement Name<T>");
+      }
+      if (parameterClass == null) {
+        throw new ClassHierarchyException(
+            "Missing type parameter in named parameter declaration.  " + getFullName(clazz)
+                + " implements raw type Name, but must implement"
+                + " generic type Name<T>.");
+      }
+      return parameterClass;
+    }
+  }
+
+  /**
+   * Coerce a Type into a Class.  This strips out any generic paramters, and
+   * resolves wildcards and free parameters to Object.
+   * <p/>
+   * Examples:
+   * java.util.Set<String> -> java.util.Set
+   * ? extends T -> Object
+   * T -> Object
+   * ? -> Object
+   */
+  public static Class<?> getRawClass(Type clazz) {
+    if (clazz instanceof Class) {
+      return (Class<?>) clazz;
+    } else if (clazz instanceof ParameterizedType) {
+      return (Class<?>) ((ParameterizedType) clazz).getRawType();
+    } else if (clazz instanceof WildcardType) {
+      return Object.class; // XXX not really correct, but close enough?
+    } else if (clazz instanceof TypeVariable) {
+      return Object.class; // XXX not really correct, but close enough?
+    } else {
+      System.err.println("Can't getRawClass for " + clazz + " of unknown type " + clazz.getClass());
+      throw new IllegalArgumentException("Can't getRawClass for " + clazz + " of unknown type " + clazz.getClass());
+    }
+  }
+}


[39/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/JobMessageObserverImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/JobMessageObserverImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/JobMessageObserverImpl.java
new file mode 100644
index 0000000..5d5d659
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/JobMessageObserverImpl.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.runtime.common.driver.client;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.driver.client.JobMessageObserver;
+
+import javax.inject.Inject;
+
+/**
+ * An implementation of JobMessageObserver.
+ */
+@DriverSide
+public final class JobMessageObserverImpl implements JobMessageObserver {
+
+  private final ClientConnection clientConnection;
+
+  @Inject
+  public JobMessageObserverImpl(final ClientConnection clientConnection) {
+    this.clientConnection = clientConnection;
+  }
+
+  @Override
+  public void sendMessageToClient(final byte[] message) {
+    this.clientConnection.sendMessage(message);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/LoggingJobStatusHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/LoggingJobStatusHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/LoggingJobStatusHandler.java
new file mode 100644
index 0000000..0f12f0a
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/LoggingJobStatusHandler.java
@@ -0,0 +1,42 @@
+/**
+ * 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.reef.runtime.common.driver.client;
+
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A handler for job status messages that just logs them.
+ */
+final class LoggingJobStatusHandler implements EventHandler<ReefServiceProtos.JobStatusProto> {
+  private static final Logger LOG = Logger.getLogger(LoggingJobStatusHandler.class.getName());
+
+  @Inject
+  LoggingJobStatusHandler() {
+  }
+
+  @Override
+  public void onNext(final ReefServiceProtos.JobStatusProto jobStatusProto) {
+    LOG.log(Level.INFO, "Received a JobStatus message that can't be sent:\n" + jobStatusProto.toString());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/package-info.java
new file mode 100644
index 0000000..832ac2b
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/package-info.java
@@ -0,0 +1,25 @@
+/**
+ * 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.
+ */
+/**
+ * Objects representing the Client on the Driver.
+ */
+
+@DriverSide package org.apache.reef.runtime.common.driver.client;
+
+import org.apache.reef.annotations.audience.DriverSide;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ClosedContextImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ClosedContextImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ClosedContextImpl.java
new file mode 100644
index 0000000..599cd0c
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ClosedContextImpl.java
@@ -0,0 +1,88 @@
+/**
+ * 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.reef.runtime.common.driver.context;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ClosedContext;
+import org.apache.reef.driver.evaluator.EvaluatorDescriptor;
+import org.apache.reef.util.Optional;
+
+/**
+ * Driver side representation of a closed context.
+ */
+@DriverSide
+@Private
+public final class ClosedContextImpl implements ClosedContext {
+
+
+  private final ActiveContext parentContext;
+  private final String contextID;
+  private final String evaluatorId;
+  private final EvaluatorDescriptor evaluatorDescriptor;
+
+  /**
+   * @param parentContext       the parent context.
+   * @param contextID           the id of the closed context
+   * @param evaluatorId         the id of the evaluator on which the context was closed
+   * @param evaluatorDescriptor the descriptor of the evaluator on which the context was closed.
+   */
+  public ClosedContextImpl(final ActiveContext parentContext,
+                           final String contextID,
+                           final String evaluatorId,
+                           final EvaluatorDescriptor evaluatorDescriptor) {
+    this.parentContext = parentContext;
+    this.contextID = contextID;
+    this.evaluatorId = evaluatorId;
+    this.evaluatorDescriptor = evaluatorDescriptor;
+  }
+
+  @Override
+  public ActiveContext getParentContext() {
+    return parentContext;
+  }
+
+  @Override
+  public String getId() {
+    return this.contextID;
+  }
+
+  @Override
+  public String getEvaluatorId() {
+    return this.evaluatorId;
+  }
+
+  @Override
+  public Optional<String> getParentId() {
+    return Optional.of(this.parentContext.getId());
+  }
+
+  @Override
+  public EvaluatorDescriptor getEvaluatorDescriptor() {
+    return this.evaluatorDescriptor;
+  }
+
+  @Override
+  public String toString() {
+    return "ClosedContext{" +
+        "contextID='" + contextID + '\'' +
+        '}';
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ContextControlHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ContextControlHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ContextControlHandler.java
new file mode 100644
index 0000000..b79d17d
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ContextControlHandler.java
@@ -0,0 +1,62 @@
+/**
+ * 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.reef.runtime.common.driver.context;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.EvaluatorRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.evaluator.EvaluatorControlHandler;
+import org.apache.reef.runtime.common.driver.evaluator.EvaluatorManager;
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Handles context control messages.
+ */
+@DriverSide
+@Private
+public class ContextControlHandler {
+  private static final Logger LOG = Logger.getLogger(ContextControlHandler.class.getName());
+  private final EvaluatorControlHandler evaluatorControlHandler;
+  private final String evaluatorId;
+
+  /**
+   * @param evaluatorControlHandler used to send the actual evaluator control messages.
+   * @param evaluatorId             the ID of the evaluator this ContextControlHandler communicates with.
+   */
+  @Inject
+  ContextControlHandler(final EvaluatorControlHandler evaluatorControlHandler,
+                        final @Parameter(EvaluatorManager.EvaluatorIdentifier.class) String evaluatorId) {
+    this.evaluatorControlHandler = evaluatorControlHandler;
+    this.evaluatorId = evaluatorId;
+    LOG.log(Level.FINE, "Instantiated 'ContextControlHandler'");
+  }
+
+  public synchronized void send(final EvaluatorRuntimeProtocol.ContextControlProto contextControlProto) {
+    final EvaluatorRuntimeProtocol.EvaluatorControlProto evaluatorControlProto =
+        EvaluatorRuntimeProtocol.EvaluatorControlProto.newBuilder()
+            .setTimestamp(System.currentTimeMillis())
+            .setIdentifier(evaluatorId)
+            .setContextControl(contextControlProto).build();
+    this.evaluatorControlHandler.send(evaluatorControlProto);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ContextFactory.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ContextFactory.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ContextFactory.java
new file mode 100644
index 0000000..2ac1e29
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ContextFactory.java
@@ -0,0 +1,97 @@
+/**
+ * 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.reef.runtime.common.driver.context;
+
+import net.jcip.annotations.GuardedBy;
+import net.jcip.annotations.ThreadSafe;
+import org.apache.reef.driver.evaluator.EvaluatorDescriptor;
+import org.apache.reef.runtime.common.driver.evaluator.EvaluatorManager;
+import org.apache.reef.runtime.common.driver.evaluator.EvaluatorMessageDispatcher;
+import org.apache.reef.runtime.common.utils.ExceptionCodec;
+import org.apache.reef.tang.InjectionFuture;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.formats.ConfigurationSerializer;
+import org.apache.reef.util.Optional;
+
+import javax.inject.Inject;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Helper class to generate EvaluatorContext instances. Used in ContextRepresenters.
+ */
+@ThreadSafe
+final class ContextFactory {
+
+  private final String evaluatorId;
+  private final EvaluatorDescriptor evaluatorDescriptor;
+  private final ConfigurationSerializer configurationSerializer;
+  private final ExceptionCodec exceptionCodec;
+  private final EvaluatorMessageDispatcher messageDispatcher;
+  private final ContextControlHandler contextControlHandler;
+  private final InjectionFuture<ContextRepresenters> contextRepresenters;
+
+
+  @GuardedBy("this.priorIds")
+  private final Set<String> priorIds = new HashSet<>();
+
+
+  @Inject
+  ContextFactory(final @Parameter(EvaluatorManager.EvaluatorIdentifier.class) String evaluatorId,
+                 final @Parameter(EvaluatorManager.EvaluatorDescriptorName.class) EvaluatorDescriptor evaluatorDescriptor,
+                 final ConfigurationSerializer configurationSerializer,
+                 final ExceptionCodec exceptionCodec,
+                 final EvaluatorMessageDispatcher messageDispatcher,
+                 final ContextControlHandler contextControlHandler,
+                 final InjectionFuture<ContextRepresenters> contextRepresenters) {
+    this.evaluatorId = evaluatorId;
+    this.evaluatorDescriptor = evaluatorDescriptor;
+    this.configurationSerializer = configurationSerializer;
+    this.exceptionCodec = exceptionCodec;
+    this.messageDispatcher = messageDispatcher;
+    this.contextControlHandler = contextControlHandler;
+    this.contextRepresenters = contextRepresenters;
+  }
+
+  /**
+   * Instantiate a new Context representer with the given id and parent id.
+   *
+   * @param contextId
+   * @param parentID
+   * @return a new Context representer with the given id and parent id.
+   */
+  public final EvaluatorContext newContext(final String contextId, final Optional<String> parentID) {
+    synchronized (this.priorIds) {
+      if (this.priorIds.contains(contextId)) {
+        throw new IllegalStateException("Creating second EvaluatorContext instance for id " + contextId);
+      }
+      this.priorIds.add(contextId);
+    }
+    return new EvaluatorContext(contextId,
+        this.evaluatorId,
+        this.evaluatorDescriptor,
+        parentID,
+        this.configurationSerializer,
+        this.contextControlHandler,
+        this.messageDispatcher,
+        this.exceptionCodec,
+        this.contextRepresenters.get());
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ContextMessageImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ContextMessageImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ContextMessageImpl.java
new file mode 100644
index 0000000..675ee53
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ContextMessageImpl.java
@@ -0,0 +1,55 @@
+/**
+ * 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.reef.runtime.common.driver.context;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.context.ContextMessage;
+
+/**
+ * Driver-side representation of a context message.
+ */
+@Private
+@DriverSide
+public final class ContextMessageImpl implements ContextMessage {
+  private final byte[] theMessage;
+  private final String theContextID;
+  private final String theMessageSourceId;
+
+  public ContextMessageImpl(final byte[] theMessage, final String theContextID, final String theMessageSourceId) {
+    this.theMessage = theMessage;
+    this.theContextID = theContextID;
+    this.theMessageSourceId = theMessageSourceId;
+  }
+
+  @Override
+  public byte[] get() {
+    return this.theMessage;
+  }
+
+  @Override
+  public String getId() {
+    return this.theContextID;
+  }
+
+  @Override
+  public final String getMessageSourceID() {
+    return this.theMessageSourceId;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ContextRepresenters.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ContextRepresenters.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ContextRepresenters.java
new file mode 100644
index 0000000..a8b8606
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/ContextRepresenters.java
@@ -0,0 +1,247 @@
+/**
+ * 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.reef.runtime.common.driver.context;
+
+import net.jcip.annotations.GuardedBy;
+import net.jcip.annotations.ThreadSafe;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.driver.evaluator.EvaluatorMessageDispatcher;
+import org.apache.reef.util.Optional;
+
+import javax.inject.Inject;
+import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Driver-Side representation of all contexts on an Evaluator.
+ */
+@ThreadSafe
+@DriverSide
+@Private
+public final class ContextRepresenters {
+  private static final Logger LOG = Logger.getLogger(ContextRepresenters.class.getName());
+
+  private final EvaluatorMessageDispatcher messageDispatcher;
+  private final ContextFactory contextFactory;
+
+  // Mutable fields
+  @GuardedBy("this")
+  private final List<EvaluatorContext> contextStack = new ArrayList<>();
+  @GuardedBy("this")
+  private final Set<String> contextIds = new HashSet<>();
+
+  @Inject
+  private ContextRepresenters(final EvaluatorMessageDispatcher messageDispatcher,
+                              final ContextFactory contextFactory) {
+    this.messageDispatcher = messageDispatcher;
+    this.contextFactory = contextFactory;
+  }
+
+  /**
+   * Fetch the context with the given ID.
+   *
+   * @param contextId
+   * @return
+   */
+  public synchronized EvaluatorContext getContext(final String contextId) {
+    for (final EvaluatorContext context : this.contextStack) {
+      if (context.getId().equals(contextId)) return context;
+    }
+    throw new RuntimeException("Unknown evaluator context " + contextId);
+  }
+
+  /**
+   * Create the failed contexts for a FailedEvaluator event.
+   *
+   * @return
+   */
+  public synchronized List<FailedContext> getFailedContextsForEvaluatorFailure() {
+    final List<FailedContext> failedContextList = new ArrayList<>();
+    final List<EvaluatorContext> activeContexts = new ArrayList<>(this.contextStack);
+    Collections.reverse(activeContexts);
+
+    for (final EvaluatorContext context : activeContexts) {
+      failedContextList.add(context.getFailedContextForEvaluatorFailure());
+    }
+    return failedContextList;
+  }
+
+  /**
+   * Process heartbeats from the contexts on an Evaluator.
+   *
+   * @param contextStatusProto
+   * @param notifyClientOnNewActiveContext
+   */
+  public synchronized void onContextStatusMessages(final Iterable<ReefServiceProtos.ContextStatusProto> contextStatusProtos,
+                                                   final boolean notifyClientOnNewActiveContext) {
+    for (final ReefServiceProtos.ContextStatusProto contextStatusProto : contextStatusProtos) {
+      this.onContextStatusMessage(contextStatusProto, notifyClientOnNewActiveContext);
+    }
+  }
+
+
+  /**
+   * Process a heartbeat from a context
+   *
+   * @param contextStatusProto
+   * @param notifyClientOnNewActiveContext
+   */
+  private synchronized void onContextStatusMessage(final ReefServiceProtos.ContextStatusProto contextStatusProto,
+                                                   final boolean notifyClientOnNewActiveContext) {
+
+    LOG.log(Level.FINER, "Processing context status message for context {0}", contextStatusProto.getContextId());
+    switch (contextStatusProto.getContextState()) {
+      case READY:
+        this.onContextReady(contextStatusProto, notifyClientOnNewActiveContext);
+        break;
+      case FAIL:
+        this.onContextFailed(contextStatusProto);
+        break;
+      case DONE:
+        this.onContextDone(contextStatusProto);
+        break;
+      default:
+        this.onUnknownContextStatus(contextStatusProto);
+        break;
+    }
+    LOG.log(Level.FINER, "Done processing context status message for context {0}", contextStatusProto.getContextId());
+
+  }
+
+
+  private synchronized void onUnknownContextStatus(final ReefServiceProtos.ContextStatusProto contextStatusProto) {
+    LOG.log(Level.WARNING, "Received unexpected context status: {0}", contextStatusProto);
+    throw new RuntimeException("Received unexpected context status: " + contextStatusProto.getContextState());
+  }
+
+  private synchronized void onContextFailed(final ReefServiceProtos.ContextStatusProto contextStatusProto) {
+    assert (ReefServiceProtos.ContextStatusProto.State.FAIL == contextStatusProto.getContextState());
+    final String contextID = contextStatusProto.getContextId();
+    LOG.log(Level.FINE, "Context {0} failed", contextID);
+    // It could have failed right away.
+    if (this.isUnknownContextId(contextID)) {
+      this.onNewContext(contextStatusProto, false);
+    }
+    final EvaluatorContext context = getContext(contextID);
+    this.removeContext(context);
+    this.messageDispatcher.onContextFailed(context.getFailedContext(contextStatusProto));
+  }
+
+  private synchronized void onContextDone(final ReefServiceProtos.ContextStatusProto contextStatusProto) {
+    assert (ReefServiceProtos.ContextStatusProto.State.DONE == contextStatusProto.getContextState());
+    final String contextID = contextStatusProto.getContextId();
+    if (isUnknownContextId(contextID)) {
+      throw new RuntimeException("Received DONE for context " + contextID + " which is unknown.");
+    } else {
+      LOG.log(Level.FINE, "Context {0} is DONE.", contextID);
+      final EvaluatorContext context = getContext(contextID);
+      removeContext(context);
+
+      if (context.isRootContext()) {
+        LOG.log(Level.FINE, "Root context {0} closed. Evaluator closed will trigger final shutdown.", contextID);
+      } else {
+        final EvaluatorContext parentContext = this.getContext(context.getParentId().get());
+        this.messageDispatcher.onContextClose(context.getClosedContext(parentContext));
+      }
+    }
+  }
+
+  /**
+   * Process a message with status READY from a context.
+   *
+   * @param contextStatusProto
+   * @param notifyClientOnNewActiveContext whether or not to inform the application when this in fact refers to a new
+   *                                       context.
+   */
+  private synchronized void onContextReady(final ReefServiceProtos.ContextStatusProto contextStatusProto,
+                                           final boolean notifyClientOnNewActiveContext) {
+    assert (ReefServiceProtos.ContextStatusProto.State.READY == contextStatusProto.getContextState());
+    final String contextID = contextStatusProto.getContextId();
+    // This could be the first message we get from that context
+    if (this.isUnknownContextId(contextID)) {
+      this.onNewContext(contextStatusProto, notifyClientOnNewActiveContext);
+    }
+
+    // Dispatch the messages to the application, if there are any.
+    for (final ReefServiceProtos.ContextStatusProto.ContextMessageProto contextMessageProto : contextStatusProto.getContextMessageList()) {
+      final byte[] theMessage = contextMessageProto.getMessage().toByteArray();
+      final String sourceID = contextMessageProto.getSourceId();
+      this.messageDispatcher.onContextMessage(new ContextMessageImpl(theMessage, contextID, sourceID));
+    }
+
+  }
+
+  /**
+   * Create and add a new context representer.
+   *
+   * @param contextStatusProto             the message to create the context from
+   * @param notifyClientOnNewActiveContext whether or not to fire an event to the user.
+   */
+  private synchronized void onNewContext(final ReefServiceProtos.ContextStatusProto contextStatusProto,
+                                         final boolean notifyClientOnNewActiveContext) {
+    final String contextID = contextStatusProto.getContextId();
+    LOG.log(Level.FINE, "Adding new context {0}.", contextID);
+
+    final Optional<String> parentID = contextStatusProto.hasParentId() ?
+        Optional.of(contextStatusProto.getParentId()) : Optional.<String>empty();
+    final EvaluatorContext context = contextFactory.newContext(contextID, parentID);
+    this.addContext(context);
+    if (contextStatusProto.getRecovery()) {
+      // when we get a recovered active context, always notify application
+      this.messageDispatcher.OnDriverRestartContextActive(context);
+    } else {
+      if (notifyClientOnNewActiveContext) {
+        this.messageDispatcher.onContextActive(context);
+      }
+    }
+  }
+
+  /**
+   * Add the given context to the data structures.
+   *
+   * @param context
+   */
+  private synchronized void addContext(final EvaluatorContext context) {
+    this.contextStack.add(context);
+    this.contextIds.add(context.getId());
+  }
+
+  /**
+   * Remove the given context from the data structures.
+   *
+   * @param context
+   */
+  private synchronized void removeContext(final EvaluatorContext context) {
+    this.contextStack.remove(context);
+    this.contextIds.remove(context.getId());
+  }
+
+  /**
+   * @param contextId
+   * @return true if the given context id is unknown so far.
+   */
+  private synchronized boolean isUnknownContextId(final String contextId) {
+    return !this.contextIds.contains(contextId);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/EvaluatorContext.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/EvaluatorContext.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/EvaluatorContext.java
new file mode 100644
index 0000000..162e9ec
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/EvaluatorContext.java
@@ -0,0 +1,280 @@
+/**
+ * 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.reef.runtime.common.driver.context;
+
+import com.google.protobuf.ByteString;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ClosedContext;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.driver.evaluator.EvaluatorDescriptor;
+import org.apache.reef.proto.EvaluatorRuntimeProtocol;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.driver.evaluator.EvaluatorMessageDispatcher;
+import org.apache.reef.runtime.common.utils.ExceptionCodec;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.formats.ConfigurationSerializer;
+import org.apache.reef.util.Optional;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Driver-side representation of a Context on an Evaluator.
+ */
+@DriverSide
+@Private
+public final class EvaluatorContext implements ActiveContext {
+
+  private final static Logger LOG = Logger.getLogger(EvaluatorContext.class.getName());
+
+  private final String contextIdentifier;
+  private final String evaluatorIdentifier;
+  private final EvaluatorDescriptor evaluatorDescriptor;
+
+  private final Optional<String> parentID;
+  private final ConfigurationSerializer configurationSerializer;
+  private final ContextControlHandler contextControlHandler;
+  private final ExceptionCodec exceptionCodec;
+  private final ContextRepresenters contextRepresenters;
+
+  private boolean isClosed = false;
+
+  public EvaluatorContext(final String contextIdentifier,
+                          final String evaluatorIdentifier,
+                          final EvaluatorDescriptor evaluatorDescriptor,
+                          final Optional<String> parentID,
+                          final ConfigurationSerializer configurationSerializer,
+                          final ContextControlHandler contextControlHandler,
+                          final EvaluatorMessageDispatcher messageDispatcher,
+                          final ExceptionCodec exceptionCodec,
+                          final ContextRepresenters contextRepresenters) {
+
+    this.contextIdentifier = contextIdentifier;
+    this.evaluatorIdentifier = evaluatorIdentifier;
+    this.evaluatorDescriptor = evaluatorDescriptor;
+    this.parentID = parentID;
+    this.configurationSerializer = configurationSerializer;
+    this.contextControlHandler = contextControlHandler;
+    this.exceptionCodec = exceptionCodec;
+    this.contextRepresenters = contextRepresenters;
+
+    LOG.log(Level.FINE, "Instantiated 'EvaluatorContext'");
+  }
+
+  @Override
+  public synchronized void close() {
+
+    if (this.isClosed) {
+      throw new RuntimeException("Active context already closed");
+    }
+
+    LOG.log(Level.FINEST, "Submit close context: RunningEvaluator id[{0}] for context id[{1}]",
+        new Object[]{getEvaluatorId(), getId()});
+
+    final EvaluatorRuntimeProtocol.ContextControlProto contextControlProto =
+        EvaluatorRuntimeProtocol.ContextControlProto.newBuilder()
+            .setRemoveContext(
+                EvaluatorRuntimeProtocol.RemoveContextProto.newBuilder()
+                    .setContextId(getId())
+                    .build())
+            .build();
+
+    this.contextControlHandler.send(contextControlProto);
+    this.isClosed = true;
+  }
+
+  @Override
+  public synchronized void sendMessage(final byte[] message) {
+
+    if (this.isClosed) {
+      throw new RuntimeException("Active context already closed");
+    }
+
+    LOG.log(Level.FINEST, "Send message: RunningEvaluator id[{0}] for context id[{1}]",
+        new Object[]{getEvaluatorId(), getId()});
+
+    final EvaluatorRuntimeProtocol.ContextControlProto contextControlProto =
+        EvaluatorRuntimeProtocol.ContextControlProto.newBuilder()
+            .setContextMessage(EvaluatorRuntimeProtocol.ContextMessageProto.newBuilder()
+                .setContextId(this.contextIdentifier)
+                .setMessage(ByteString.copyFrom(message))
+                .build())
+            .build();
+
+    this.contextControlHandler.send(contextControlProto);
+  }
+
+  @Override
+  public synchronized void submitTask(final Configuration taskConf) {
+
+    if (this.isClosed) {
+      throw new RuntimeException("Active context already closed");
+    }
+
+    LOG.log(Level.FINEST, "Submit task: RunningEvaluator id[{0}] for context id[{1}]",
+        new Object[]{getEvaluatorId(), getId()});
+
+    final EvaluatorRuntimeProtocol.ContextControlProto contextControlProto =
+        EvaluatorRuntimeProtocol.ContextControlProto.newBuilder()
+            .setStartTask(
+                EvaluatorRuntimeProtocol.StartTaskProto.newBuilder()
+                    .setContextId(this.contextIdentifier)
+                    .setConfiguration(this.configurationSerializer.toString(taskConf))
+                    .build())
+            .build();
+
+    this.contextControlHandler.send(contextControlProto);
+  }
+
+  @Override
+  public synchronized void submitContext(final Configuration contextConfiguration) {
+
+    if (this.isClosed) {
+      throw new RuntimeException("Active context already closed");
+    }
+
+    LOG.log(Level.FINEST, "Submit new context: RunningEvaluator id[{0}] for context id[{1}]",
+        new Object[]{getEvaluatorId(), getId()});
+
+    final EvaluatorRuntimeProtocol.ContextControlProto contextControlProto =
+        EvaluatorRuntimeProtocol.ContextControlProto.newBuilder()
+            .setAddContext(
+                EvaluatorRuntimeProtocol.AddContextProto.newBuilder()
+                    .setParentContextId(getId())
+                    .setContextConfiguration(this.configurationSerializer.toString(contextConfiguration))
+                    .build())
+            .build();
+
+    this.contextControlHandler.send(contextControlProto);
+  }
+
+  @Override
+  public synchronized void submitContextAndService(
+      final Configuration contextConfiguration, final Configuration serviceConfiguration) {
+
+    if (this.isClosed) {
+      throw new RuntimeException("Active context already closed");
+    }
+
+    LOG.log(Level.FINEST, "Submit new context: RunningEvaluator id[{0}] for context id[{1}]",
+        new Object[]{getEvaluatorId(), getId()});
+
+    final EvaluatorRuntimeProtocol.ContextControlProto contextControlProto =
+        EvaluatorRuntimeProtocol.ContextControlProto.newBuilder()
+            .setAddContext(
+                EvaluatorRuntimeProtocol.AddContextProto.newBuilder()
+                    .setParentContextId(getId())
+                    .setContextConfiguration(this.configurationSerializer.toString(contextConfiguration))
+                    .setServiceConfiguration(this.configurationSerializer.toString(serviceConfiguration))
+                    .build())
+            .build();
+
+    this.contextControlHandler.send(contextControlProto);
+  }
+
+  @Override
+  public String getEvaluatorId() {
+    return this.evaluatorIdentifier;
+  }
+
+  @Override
+  public Optional<String> getParentId() {
+    return this.parentID;
+  }
+
+  @Override
+  public EvaluatorDescriptor getEvaluatorDescriptor() {
+    return this.evaluatorDescriptor;
+  }
+
+  @Override
+  public String getId() {
+    return this.contextIdentifier;
+  }
+
+  @Override
+  public String toString() {
+    return "EvaluatorContext{" +
+        "contextIdentifier='" + this.contextIdentifier + '\'' +
+        ", evaluatorIdentifier='" + this.evaluatorIdentifier + '\'' +
+        ", parentID=" + this.parentID + '}';
+  }
+
+  public synchronized final ClosedContext getClosedContext(final ActiveContext parentContext) {
+    return new ClosedContextImpl(
+        parentContext, this.getId(), this.getEvaluatorId(), this.getEvaluatorDescriptor());
+  }
+
+  /**
+   * @return a FailedContext for the case of an EvaluatorFailure.
+   */
+  public synchronized FailedContext getFailedContextForEvaluatorFailure() {
+
+    final String id = this.getId();
+    final Optional<String> description = Optional.empty();
+    final Optional<byte[]> data = Optional.empty();
+    final Optional<Throwable> cause = Optional.empty();
+    final String message = "Evaluator Failure";
+
+    final Optional<ActiveContext> parentContext = getParentId().isPresent() ?
+        Optional.<ActiveContext>of(this.contextRepresenters.getContext(getParentId().get())) :
+        Optional.<ActiveContext>empty();
+
+    final EvaluatorDescriptor evaluatorDescriptor = getEvaluatorDescriptor();
+    final String evaluatorID = getEvaluatorId();
+
+    return new FailedContextImpl(
+        id, message, description, cause, data, parentContext, evaluatorDescriptor, evaluatorID);
+  }
+
+  public synchronized FailedContext getFailedContext(
+      final ReefServiceProtos.ContextStatusProto contextStatusProto) {
+
+    assert (ReefServiceProtos.ContextStatusProto.State.FAIL == contextStatusProto.getContextState());
+
+    final String id = this.getId();
+    final Optional<String> description = Optional.empty();
+
+    final Optional<byte[]> data = contextStatusProto.hasError() ?
+        Optional.of(contextStatusProto.getError().toByteArray()) :
+        Optional.<byte[]>empty();
+
+    final Optional<Throwable> cause = data.isPresent() ?
+        this.exceptionCodec.fromBytes(data) :
+        Optional.<Throwable>empty();
+
+    final String message = cause.isPresent() ? cause.get().getMessage() : "No message given";
+
+    final Optional<ActiveContext> parentContext = getParentId().isPresent() ?
+        Optional.<ActiveContext>of(this.contextRepresenters.getContext(getParentId().get())) :
+        Optional.<ActiveContext>empty();
+
+    final EvaluatorDescriptor evaluatorDescriptor = getEvaluatorDescriptor();
+    final String evaluatorID = getEvaluatorId();
+
+    return new FailedContextImpl(
+        id, message, description, cause, data, parentContext, evaluatorDescriptor, evaluatorID);
+  }
+
+  public synchronized boolean isRootContext() {
+    return !this.parentID.isPresent();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/FailedContextImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/FailedContextImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/FailedContextImpl.java
new file mode 100644
index 0000000..0799e50
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/FailedContextImpl.java
@@ -0,0 +1,95 @@
+/**
+ * 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.reef.runtime.common.driver.context;
+
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.common.AbstractFailure;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.driver.evaluator.EvaluatorDescriptor;
+import org.apache.reef.util.Optional;
+
+/**
+ * Driver-Side representation of a failed context.
+ */
+@Private
+@DriverSide
+public final class FailedContextImpl extends AbstractFailure implements FailedContext {
+
+  private final Optional<ActiveContext> parentContext;
+  private final EvaluatorDescriptor evaluatorDescriptor;
+  private final String evaluatorID;
+
+  /**
+   * @param id                  Identifier of the entity that produced the error.
+   * @param message             One-line error message.
+   * @param description         Long error description.
+   * @param cause               Java Exception that caused the error.
+   * @param data                byte array that contains serialized version of the error.
+   * @param parentContext       the parent context, if there is one.
+   * @param evaluatorDescriptor the descriptor of the Evaluator this context failed on.
+   * @param evaluatorID         the id of the Evaluator this context failed on.
+   */
+  public FailedContextImpl(final String id,
+                           final String message,
+                           final Optional<String> description,
+                           final Optional<Throwable> cause,
+                           final Optional<byte[]> data,
+                           final Optional<ActiveContext> parentContext,
+                           final EvaluatorDescriptor evaluatorDescriptor,
+                           final String evaluatorID) {
+    super(id, message, description, cause, data);
+    this.parentContext = parentContext;
+    this.evaluatorDescriptor = evaluatorDescriptor;
+    this.evaluatorID = evaluatorID;
+  }
+
+
+  @Override
+  public Optional<ActiveContext> getParentContext() {
+    return this.parentContext;
+  }
+
+  @Override
+  public String getEvaluatorId() {
+    return this.evaluatorID;
+  }
+
+  @Override
+  public Optional<String> getParentId() {
+    if (this.getParentContext().isPresent()) {
+      return Optional.of(this.getParentContext().get().getId());
+    } else {
+      return Optional.empty();
+    }
+  }
+
+  @Override
+  public EvaluatorDescriptor getEvaluatorDescriptor() {
+    return this.evaluatorDescriptor;
+  }
+
+
+  @Override
+  public String toString() {
+    return "FailedContext{" + "evaluatorID='" + evaluatorID + "', contextID='" + getId() + "'}";
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/package-info.java
new file mode 100644
index 0000000..9154c74
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/context/package-info.java
@@ -0,0 +1,26 @@
+/**
+ * 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.
+ */
+/**
+ * Implementations of Driver-Side representations of Contexts running on an Evaluator
+ */
+@DriverSide
+@Private package org.apache.reef.runtime.common.driver.context;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultClientCloseHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultClientCloseHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultClientCloseHandler.java
new file mode 100644
index 0000000..42722dd
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultClientCloseHandler.java
@@ -0,0 +1,46 @@
+/**
+ * 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.reef.runtime.common.driver.defaults;
+
+import org.apache.reef.util.ThreadLogger;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default handler for close messages from the client: Throw an Exception.
+ */
+public final class DefaultClientCloseHandler implements EventHandler<Void> {
+
+  private static final Logger LOG = Logger.getLogger(DefaultClientCloseHandler.class.getName());
+
+  @Inject
+  DefaultClientCloseHandler() {
+  }
+
+  @Override
+  public void onNext(final Void aVoid) {
+    final String message = ThreadLogger.getFormattedThreadList(
+        "Received a close message from the client, but no handler was bound for it. Active threads: ");
+    LOG.log(Level.WARNING, message);
+    throw new RuntimeException(message);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultClientCloseWithMessageHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultClientCloseWithMessageHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultClientCloseWithMessageHandler.java
new file mode 100644
index 0000000..603b9d9
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultClientCloseWithMessageHandler.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.runtime.common.driver.defaults;
+
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+
+/**
+ * Default handler for close messages from the client: Throw an Exception.
+ */
+public final class DefaultClientCloseWithMessageHandler implements EventHandler<byte[]> {
+
+  @Inject
+  public DefaultClientCloseWithMessageHandler() {
+  }
+
+  @Override
+  public void onNext(final byte[] bytes) {
+    throw new RuntimeException(
+        "No handler bound for client Close With Message event: " + new String(bytes));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultClientMessageHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultClientMessageHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultClientMessageHandler.java
new file mode 100644
index 0000000..276a012
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultClientMessageHandler.java
@@ -0,0 +1,42 @@
+/**
+ * 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.reef.runtime.common.driver.defaults;
+
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default event handler for Client messages: Logging it.
+ */
+public final class DefaultClientMessageHandler implements EventHandler<byte[]> {
+
+  private static final Logger LOG = Logger.getLogger(DefaultClientMessageHandler.class.getName());
+
+  @Inject
+  public DefaultClientMessageHandler() {
+  }
+
+  @Override
+  public void onNext(final byte[] bytes) {
+    LOG.log(Level.INFO, "Received ClientMessage: {0}", new String(bytes));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultContextActiveHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultContextActiveHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultContextActiveHandler.java
new file mode 100644
index 0000000..1016098
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultContextActiveHandler.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.runtime.common.driver.defaults;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default handler for ActiveContext: Close it.
+ */
+public final class DefaultContextActiveHandler implements EventHandler<ActiveContext> {
+
+  private static final Logger LOG = Logger.getLogger(DefaultContextActiveHandler.class.getName());
+
+  @Inject
+  private DefaultContextActiveHandler() {
+  }
+
+  @Override
+  public void onNext(final ActiveContext activeContext) {
+    LOG.log(Level.INFO, "Received ActiveContext: {0} :: CLOSING", activeContext);
+    activeContext.close();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultContextClosureHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultContextClosureHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultContextClosureHandler.java
new file mode 100644
index 0000000..de1f886
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultContextClosureHandler.java
@@ -0,0 +1,47 @@
+/**
+ * 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.reef.runtime.common.driver.defaults;
+
+import org.apache.reef.driver.context.ClosedContext;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default event handler for ClosedContext: Logging it.
+ */
+public final class DefaultContextClosureHandler implements EventHandler<ClosedContext> {
+
+  private static final Logger LOG = Logger.getLogger(DefaultContextClosureHandler.class.getName());
+
+  @Inject
+  public DefaultContextClosureHandler() {
+  }
+
+  @Override
+  public void onNext(final ClosedContext closedContext) {
+    LOG.log(Level.INFO, "Received ClosedContext: {0}", closedContext);
+    if (closedContext.getParentContext() != null) {
+      LOG.log(Level.INFO, "Closing parent context: {0}", closedContext.getParentContext().getId());
+      closedContext.getParentContext().close();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultContextFailureHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultContextFailureHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultContextFailureHandler.java
new file mode 100644
index 0000000..159bfad
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultContextFailureHandler.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.runtime.common.driver.defaults;
+
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+
+/**
+ * Default event handler used for FailedContext: It crashes the driver.
+ */
+public final class DefaultContextFailureHandler implements EventHandler<FailedContext> {
+
+  @Inject
+  public DefaultContextFailureHandler() {
+  }
+
+  @Override
+  public void onNext(final FailedContext failedContext) {
+    if (failedContext.getReason().isPresent()) {
+      throw new RuntimeException(
+          "No handler bound for FailedContext:" + failedContext, failedContext.getReason().get());
+    } else {
+      throw new RuntimeException("No handler bound for FailedContext:" + failedContext);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultContextMessageHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultContextMessageHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultContextMessageHandler.java
new file mode 100644
index 0000000..28c22f3
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultContextMessageHandler.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.runtime.common.driver.defaults;
+
+import org.apache.reef.driver.context.ContextMessage;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default event handler for ContextMessage: Logging it.
+ */
+public final class DefaultContextMessageHandler implements EventHandler<ContextMessage> {
+
+  private static final Logger LOG = Logger.getLogger(DefaultContextMessageHandler.class.getName());
+
+  @Inject
+  public DefaultContextMessageHandler() {
+  }
+
+  @Override
+  public void onNext(final ContextMessage contextMessage) {
+    LOG.log(Level.INFO, "Received ContextMessage: {0}", contextMessage);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultDriverRestartCompletedHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultDriverRestartCompletedHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultDriverRestartCompletedHandler.java
new file mode 100644
index 0000000..9f076ba
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultDriverRestartCompletedHandler.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.runtime.common.driver.defaults;
+
+import org.apache.reef.runtime.common.DriverRestartCompleted;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default handler for driver restart completed event: log it.
+ */
+public final class DefaultDriverRestartCompletedHandler implements EventHandler<DriverRestartCompleted> {
+
+  private static final Logger LOG = Logger.getLogger(DefaultDriverRestartCompletedHandler.class.getName());
+
+  @Inject
+  private DefaultDriverRestartCompletedHandler() {
+  }
+
+  @Override
+  public void onNext(final DriverRestartCompleted restartCompleted) {
+    LOG.log(Level.INFO, "Driver restart completed at time [{0}].", restartCompleted.getTimeStamp());
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultDriverRestartContextActiveHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultDriverRestartContextActiveHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultDriverRestartContextActiveHandler.java
new file mode 100644
index 0000000..86c913a
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultDriverRestartContextActiveHandler.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.runtime.common.driver.defaults;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default handler for ActiveContext from previous evaluator during driver restart: Close it.
+ */
+public final class DefaultDriverRestartContextActiveHandler implements EventHandler<ActiveContext> {
+
+  private static final Logger LOG = Logger.getLogger(DefaultDriverRestartContextActiveHandler.class.getName());
+
+  @Inject
+  private DefaultDriverRestartContextActiveHandler() {
+  }
+
+  @Override
+  public void onNext(final ActiveContext activeContext) {
+    LOG.log(Level.INFO, "Received ActiveContext running on previous Evaluator during driver restart: {0} :: CLOSING", activeContext);
+    activeContext.close();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultDriverRestartTaskRunningHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultDriverRestartTaskRunningHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultDriverRestartTaskRunningHandler.java
new file mode 100644
index 0000000..0235e03
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultDriverRestartTaskRunningHandler.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.runtime.common.driver.defaults;
+
+import org.apache.reef.driver.task.RunningTask;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Logger;
+
+/**
+ * Default event handler for Task Restart TaskRuntime: Logging it.
+ */
+public final class DefaultDriverRestartTaskRunningHandler implements EventHandler<RunningTask> {
+
+  private static final Logger LOG = Logger.getLogger(DefaultDriverRestartTaskRunningHandler.class.getName());
+
+  @Inject
+  public DefaultDriverRestartTaskRunningHandler() {
+  }
+
+  @Override
+  public void onNext(final RunningTask runningTask) {
+    throw new RuntimeException(
+        "RunningTask [" + runningTask.toString() + "] received during driver restart, but no DriverRestartTaskRunningHandler is bound");
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultEvaluatorAllocationHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultEvaluatorAllocationHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultEvaluatorAllocationHandler.java
new file mode 100644
index 0000000..8f697dc
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultEvaluatorAllocationHandler.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.runtime.common.driver.defaults;
+
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default handler for AllocatedEvaluator: close it.
+ */
+public final class DefaultEvaluatorAllocationHandler implements EventHandler<AllocatedEvaluator> {
+
+  private static final Logger LOG = Logger.getLogger(DefaultContextMessageHandler.class.getName());
+
+  @Inject
+  public DefaultEvaluatorAllocationHandler() {
+  }
+
+  @Override
+  public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+    LOG.log(Level.INFO, "Received AllocatedEvaluator: {0} :: CLOSING", allocatedEvaluator);
+    allocatedEvaluator.close();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultEvaluatorCompletionHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultEvaluatorCompletionHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultEvaluatorCompletionHandler.java
new file mode 100644
index 0000000..f723e0f
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultEvaluatorCompletionHandler.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.runtime.common.driver.defaults;
+
+import org.apache.reef.driver.evaluator.CompletedEvaluator;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default event handler for CompletedEvaluator: Logging it.
+ */
+public final class DefaultEvaluatorCompletionHandler implements EventHandler<CompletedEvaluator> {
+
+  private static final Logger LOG = Logger.getLogger(DefaultContextMessageHandler.class.getName());
+
+  @Inject
+  public DefaultEvaluatorCompletionHandler() {
+  }
+
+  @Override
+  public void onNext(final CompletedEvaluator completedEvaluator) {
+    LOG.log(Level.INFO, "Received CompletedEvaluator: {0}", completedEvaluator);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultEvaluatorFailureHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultEvaluatorFailureHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultEvaluatorFailureHandler.java
new file mode 100644
index 0000000..0f9546b
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultEvaluatorFailureHandler.java
@@ -0,0 +1,41 @@
+/**
+ * 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.reef.runtime.common.driver.defaults;
+
+import org.apache.reef.driver.evaluator.FailedEvaluator;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+
+/**
+ * Default event handler used for FailedEvaluator: It crashes the driver.
+ */
+public final class DefaultEvaluatorFailureHandler implements EventHandler<FailedEvaluator> {
+
+  @Inject
+  public DefaultEvaluatorFailureHandler() {
+  }
+
+  @Override
+  public void onNext(final FailedEvaluator failedEvaluator) {
+    throw new RuntimeException(
+        "No handler bound for FailedEvaluator: " + failedEvaluator,
+        failedEvaluator.getEvaluatorException());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskCompletionHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskCompletionHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskCompletionHandler.java
new file mode 100644
index 0000000..2d69045
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskCompletionHandler.java
@@ -0,0 +1,47 @@
+/**
+ * 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.reef.runtime.common.driver.defaults;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.task.CompletedTask;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default event handler for CompletedTask: Log it and close the context.
+ */
+public final class DefaultTaskCompletionHandler implements EventHandler<CompletedTask> {
+
+  private static final Logger LOG = Logger.getLogger(DefaultTaskCompletionHandler.class.getName());
+
+  @Inject
+  public DefaultTaskCompletionHandler() {
+  }
+
+  @Override
+  public void onNext(final CompletedTask completedTask) {
+    final ActiveContext context = completedTask.getActiveContext();
+    LOG.log(Level.INFO, "Received CompletedTask: {0} :: CLOSING context: {1}",
+        new Object[]{completedTask, context});
+    context.close();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskFailureHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskFailureHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskFailureHandler.java
new file mode 100644
index 0000000..b0e5592
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskFailureHandler.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.runtime.common.driver.defaults;
+
+import org.apache.reef.driver.task.FailedTask;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+
+/**
+ * Default event handler used for FailedTask: It crashes the driver.
+ */
+public final class DefaultTaskFailureHandler implements EventHandler<FailedTask> {
+
+  @Inject
+  public DefaultTaskFailureHandler() {
+  }
+
+  @Override
+  public void onNext(final FailedTask failedTask) {
+    throw new RuntimeException("No handler bound for FailedTask: " + failedTask, failedTask.getReason().orElse(null));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskMessageHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskMessageHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskMessageHandler.java
new file mode 100644
index 0000000..bdf6b3a
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskMessageHandler.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.runtime.common.driver.defaults;
+
+import org.apache.reef.driver.task.TaskMessage;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default event handler for TaskMessage: Logging it.
+ */
+public final class DefaultTaskMessageHandler implements EventHandler<TaskMessage> {
+
+  private static final Logger LOG = Logger.getLogger(DefaultTaskMessageHandler.class.getName());
+
+  @Inject
+  public DefaultTaskMessageHandler() {
+  }
+
+  @Override
+  public void onNext(final TaskMessage taskMessage) {
+    LOG.log(Level.INFO, "Received TaskMessage: {0}", taskMessage);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskRunningHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskRunningHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskRunningHandler.java
new file mode 100644
index 0000000..7f070b8
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskRunningHandler.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.runtime.common.driver.defaults;
+
+import org.apache.reef.driver.task.RunningTask;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default event handler for TaskRuntime: Logging it.
+ */
+public final class DefaultTaskRunningHandler implements EventHandler<RunningTask> {
+
+  private static final Logger LOG = Logger.getLogger(DefaultTaskRunningHandler.class.getName());
+
+  @Inject
+  public DefaultTaskRunningHandler() {
+  }
+
+  @Override
+  public void onNext(final RunningTask runningTask) {
+    LOG.log(Level.INFO, "Received TaskRuntime: {0}", runningTask);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskSuspensionHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskSuspensionHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskSuspensionHandler.java
new file mode 100644
index 0000000..90b3796
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/DefaultTaskSuspensionHandler.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.runtime.common.driver.defaults;
+
+import org.apache.reef.driver.task.SuspendedTask;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+
+/**
+ * Default event handler used for SuspendedTask: It crashes the driver.
+ */
+public final class DefaultTaskSuspensionHandler implements EventHandler<SuspendedTask> {
+
+  @Inject
+  public DefaultTaskSuspensionHandler() {
+  }
+
+  @Override
+  public void onNext(final SuspendedTask suspendedTask) {
+    throw new RuntimeException("No handler bound for SuspendedTask: " + suspendedTask);
+  }
+}


[10/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestBindSingleton.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestBindSingleton.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestBindSingleton.java
new file mode 100644
index 0000000..e148d6a
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestBindSingleton.java
@@ -0,0 +1,420 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.ConfigurationFile;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.inject.Inject;
+
+import static org.junit.Assert.assertTrue;
+
+public class TestBindSingleton {
+
+  @Before
+  public void before() {
+    InbredSingletons.A.count = 0;
+    InbredSingletons.B.count = 0;
+    InbredSingletons.C.count = 0;
+
+    IncestuousSingletons.A.count = 0;
+    IncestuousSingletons.B.count = 0;
+    IncestuousSingletons.BN.count = 0;
+    IncestuousSingletons.C.count = 0;
+
+    IncestuousInterfaceSingletons.A.count = 0;
+    IncestuousInterfaceSingletons.B.count = 0;
+    IncestuousInterfaceSingletons.BN.count = 0;
+    IncestuousInterfaceSingletons.C.count = 0;
+  }
+
+  @Test
+  public void testSingletonRoundTrip() throws BindException, InjectionException {
+
+    final JavaConfigurationBuilder b = Tang.Factory.getTang()
+        .newConfigurationBuilder();
+    b.bindImplementation(A.class, B.class);
+    final Configuration src = b.build();
+
+    final JavaConfigurationBuilder dest = Tang.Factory.getTang()
+        .newConfigurationBuilder();
+    ConfigurationFile.addConfiguration(dest, ConfigurationFile.toConfigurationString(src));
+    final Injector i = Tang.Factory.getTang().newInjector(dest.build());
+    final A a1 = i.getInstance(A.class);
+    final A a2 = i.getInstance(A.class);
+    final B b1 = i.getInstance(B.class);
+
+    assertTrue("Two singletons should be the same", a1 == a2);
+    assertTrue("Both instances should be of class B", a1 instanceof B);
+    assertTrue("Both instances should be of class B", a2 instanceof B);
+    assertTrue("Singleton and not singleton should be the same", a1 == b1);
+
+    final Injector injector2 = Tang.Factory.getTang().newInjector(src);
+    final A a3 = injector2.getInstance(A.class);
+    assertTrue(
+        "Two different injectors should return two different singletons",
+        a3 != a1);
+
+    final Injector injector3 = injector2.forkInjector();
+    final A a4 = injector3.getInstance(A.class);
+    assertTrue(
+        "Child Injectors should return the same singletons as their parents",
+        a3 == a4);
+  }
+
+  @Test
+  public void testLateBoundVolatileInstanceWithSingletonX()
+      throws BindException, InjectionException {
+    Tang tang = Tang.Factory.getTang();
+    JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+    cb.bindImplementation(LateBoundVolatile.A.class,
+        LateBoundVolatile.B.class);
+    final Injector i = tang.newInjector(cb.build());
+    i.bindVolatileInstance(LateBoundVolatile.C.class, new LateBoundVolatile.C());
+    i.getInstance(LateBoundVolatile.A.class);
+  }
+
+  @Test
+  public void testMultipleInjectorInstaceWithSingleton() throws BindException, InjectionException {
+    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+
+    final Injector i1 = Tang.Factory.getTang().newInjector(cb.build());
+    final Injector i2 = Tang.Factory.getTang().newInjector(cb.build());
+
+    assertTrue("Different injectors should return different singleton object instances", i1.getInstance(AA.class) != i2.getInstance(AA.class));
+
+    final Configuration c = cb.build();
+
+    final Injector i3 = Tang.Factory.getTang().newInjector(c);
+    final Injector i4 = Tang.Factory.getTang().newInjector(c);
+
+    assertTrue("Different injectors should return different singleton object instances", i3.getInstance(AA.class) != i4.getInstance(AA.class));
+
+  }
+
+  @Test
+  public void testLateBoundVolatileInstanceWithSingletonY()
+      throws BindException, InjectionException {
+    Tang tang = Tang.Factory.getTang();
+    JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+    Injector i = tang.newInjector(cb.build());
+    i.bindVolatileInstance(LateBoundVolatile.C.class, new LateBoundVolatile.C());
+    i.getInstance(LateBoundVolatile.C.class);
+  }
+
+  @Test
+  public void testLateBoundVolatileInstanceWithSingletonZ()
+      throws BindException, InjectionException {
+    Tang tang = Tang.Factory.getTang();
+    JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+    cb.bindImplementation(LateBoundVolatile.B.class,
+        LateBoundVolatile.B.class);
+    Injector i = tang.newInjector(cb.build());
+    i.bindVolatileInstance(LateBoundVolatile.C.class, new LateBoundVolatile.C());
+    i.getInstance(LateBoundVolatile.B.class);
+  }
+
+  @Test
+  public void testInbredSingletons() throws BindException, InjectionException {
+    Tang t = Tang.Factory.getTang();
+    JavaConfigurationBuilder b = t.newConfigurationBuilder();
+    b.bindImplementation(InbredSingletons.A.class,
+        InbredSingletons.A.class);
+    b.bindImplementation(InbredSingletons.B.class,
+        InbredSingletons.B.class);
+    b.bindImplementation(InbredSingletons.C.class,
+        InbredSingletons.C.class);
+    Injector i = t.newInjector(b.build());
+    i.getInstance(InbredSingletons.A.class);
+  }
+
+  @Test
+  public void testIncestuousSingletons() throws BindException,
+      InjectionException {
+    Tang t = Tang.Factory.getTang();
+    JavaConfigurationBuilder b = t.newConfigurationBuilder();
+    b.bindImplementation(IncestuousSingletons.A.class,
+        IncestuousSingletons.A.class);
+    b.bindImplementation(IncestuousSingletons.B.class,
+        IncestuousSingletons.B.class);
+    b.bindImplementation(IncestuousSingletons.C.class,
+        IncestuousSingletons.C.class);
+    Injector i = t.newInjector(b.build());
+    i.getInstance(IncestuousSingletons.A.class);
+  }
+
+  @Test
+  public void testIncestuousSingletons2() throws BindException,
+      InjectionException {
+    Tang t = Tang.Factory.getTang();
+    JavaConfigurationBuilder b = t.newConfigurationBuilder();
+    b.bindImplementation(IncestuousSingletons.A.class,
+        IncestuousSingletons.A.class);
+    b.bindImplementation(IncestuousSingletons.B.class,
+        IncestuousSingletons.BN.class);
+    b.bindImplementation(IncestuousSingletons.C.class,
+        IncestuousSingletons.C.class);
+    Injector i = t.newInjector(b.build());
+    i.getInstance(IncestuousSingletons.A.class);
+  }
+
+  @Test
+  public void testIncestuousInterfaceSingletons() throws BindException,
+      InjectionException {
+    Tang t = Tang.Factory.getTang();
+    JavaConfigurationBuilder b = t.newConfigurationBuilder();
+    b.bindImplementation(IncestuousInterfaceSingletons.AI.class,
+        IncestuousInterfaceSingletons.A.class);
+    b.bindImplementation(IncestuousInterfaceSingletons.BI.class,
+        IncestuousInterfaceSingletons.BN.class);
+    b.bindImplementation(IncestuousInterfaceSingletons.CI.class,
+        IncestuousInterfaceSingletons.C.class);
+    Injector i = t.newInjector(b.build());
+    i.getInstance(IncestuousInterfaceSingletons.AI.class);
+  }
+
+  @Test
+  public void testIncestuousInterfaceSingletons2() throws BindException,
+      InjectionException {
+    Tang t = Tang.Factory.getTang();
+    JavaConfigurationBuilder b = t.newConfigurationBuilder();
+    b.bindImplementation(IncestuousInterfaceSingletons.AI.class,
+        IncestuousInterfaceSingletons.A.class);
+    b.bindImplementation(IncestuousInterfaceSingletons.BI.class,
+        IncestuousInterfaceSingletons.B.class);
+    // TODO: Should we require bind(A,B), then bind(B,B) if B has subclasses?
+    b.bindImplementation(IncestuousInterfaceSingletons.B.class,
+        IncestuousInterfaceSingletons.B.class);
+    b.bindImplementation(IncestuousInterfaceSingletons.CI.class,
+        IncestuousInterfaceSingletons.C.class);
+    Injector i = t.newInjector(b.build());
+    i.getInstance(IncestuousInterfaceSingletons.AI.class);
+  }
+
+  @Test
+  public void testIsBrokenClassInjectable() throws BindException {
+    Tang t = Tang.Factory.getTang();
+    JavaConfigurationBuilder b = t.newConfigurationBuilder();
+    b.bind(IsBrokenClassInjectable.class, IsBrokenClassInjectable.class);
+    Assert.assertTrue(t.newInjector(b.build()).isInjectable(
+        IsBrokenClassInjectable.class));
+  }
+
+  @Test
+  public void testIsBrokenSingletonClassInjectable() throws BindException {
+    Tang t = Tang.Factory.getTang();
+    JavaConfigurationBuilder b = t.newConfigurationBuilder();
+    b.bindImplementation(IsBrokenClassInjectable.class,
+        IsBrokenClassInjectable.class);
+    Assert.assertTrue(t.newInjector(b.build()).isInjectable(
+        IsBrokenClassInjectable.class));
+  }
+
+  @Test(expected = InjectionException.class)
+  public void testBrokenSingletonClassCantInject() throws BindException, InjectionException {
+    Tang t = Tang.Factory.getTang();
+    JavaConfigurationBuilder b = t.newConfigurationBuilder();
+    b.bindImplementation(IsBrokenClassInjectable.class,
+        IsBrokenClassInjectable.class);
+    Assert.assertTrue(t.newInjector(b.build()).isInjectable(
+        IsBrokenClassInjectable.class));
+    t.newInjector(b.build()).getInstance(IsBrokenClassInjectable.class);
+  }
+
+  public static class A {
+    @Inject
+    public A() {
+      // Intentionally blank
+    }
+
+  }
+
+  public static class AA {
+    @Inject
+    public AA() {
+      // Intentionally blank
+    }
+
+  }
+
+  public static class B extends A {
+    @Inject
+    public B() {
+      // intentionally blank
+    }
+  }
+}
+
+class LateBoundVolatile {
+  static class A {
+  }
+
+  static class B extends A {
+    @Inject
+    B(C c) {
+    }
+  }
+
+  static class C {
+  }
+}
+
+class InbredSingletons {
+  static class A {
+    static int count = 0;
+
+    @Inject
+    A(B b) {
+      Assert.assertEquals(0, count);
+      count++;
+    }
+  }
+
+  static class B {
+    static int count = 0;
+
+    @Inject
+    B(C c) {
+      Assert.assertEquals(0, count);
+      count++;
+    }
+  }
+
+  static class C {
+    static int count = 0;
+
+    @Inject
+    C() {
+      Assert.assertEquals(0, count);
+      count++;
+    }
+  }
+}
+
+class IncestuousSingletons {
+  static class A {
+    static int count = 0;
+
+    @Inject
+    A(C c, B b) {
+      Assert.assertEquals(0, count);
+      count++;
+    }
+  }
+
+  static class B {
+    static int count = 0;
+
+    protected B() {
+    }
+
+    @Inject
+    B(C c) {
+      Assert.assertEquals(0, count);
+      count++;
+    }
+  }
+
+  static class BN extends B {
+    static int count = 0;
+
+    @Inject
+    BN(C c) {
+      super();
+      Assert.assertEquals(0, count);
+      count++;
+    }
+  }
+
+  static class C {
+    static int count = 0;
+
+    @Inject
+    C() {
+      Assert.assertEquals(0, count);
+      count++;
+    }
+  }
+}
+
+class IncestuousInterfaceSingletons {
+  interface AI {
+  }
+
+  interface BI {
+  }
+
+  interface CI {
+  }
+
+  static class A implements AI {
+    static int count = 0;
+
+    @Inject
+    A(CI c, BI b) {
+      Assert.assertEquals(0, count);
+      count++;
+    }
+  }
+
+  static class B implements BI {
+    static int count = 0;
+
+    protected B() {
+    }
+
+    @Inject
+    B(CI c) {
+      Assert.assertEquals(0, count);
+      count++;
+    }
+  }
+
+  static class BN extends B {
+    static int count = 0;
+
+    @Inject
+    BN(CI c) {
+      super();
+      Assert.assertEquals(0, count);
+      count++;
+    }
+  }
+
+  static class C implements CI {
+    static int count = 0;
+
+    @Inject
+    C() {
+      Assert.assertEquals(0, count);
+      count++;
+    }
+  }
+}
+
+class IsBrokenClassInjectable {
+  @Inject
+  public IsBrokenClassInjectable() {
+    throw new UnsupportedOperationException();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestClassLoaders.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestClassLoaders.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestClassLoaders.java
new file mode 100644
index 0000000..4394abb
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestClassLoaders.java
@@ -0,0 +1,118 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.exceptions.NameResolutionException;
+import org.apache.reef.tang.types.ClassNode;
+import org.junit.Assert;
+
+import java.io.File;
+import java.net.MalformedURLException;
+
+public class TestClassLoaders {
+
+  //  @Test
+  public void testOneJar() throws MalformedURLException,
+      ClassNotFoundException, NameResolutionException, BindException {
+    Tang.Factory
+        .getTang()
+        .newConfigurationBuilder(
+            new File("../tang-test-jarA/target/tang-test-jarA-1.0-SNAPSHOT.jar")
+                .toURI().toURL()).getClassHierarchy().getNode("org.apache.reef.tang.examples.A");
+
+  }
+
+  //  @Test
+  public void testTwoJars() throws MalformedURLException,
+      ClassNotFoundException, BindException, InjectionException, NameResolutionException {
+    Tang t = Tang.Factory.getTang();
+
+    JavaConfigurationBuilder cbA = t.newConfigurationBuilder(new File(
+        "../tang-test-jarA/target/tang-test-jarA-1.0-SNAPSHOT.jar").toURI()
+        .toURL());
+    JavaConfigurationBuilder cbB = t.newConfigurationBuilder(new File(
+        "../tang-test-jarB/target/tang-test-jarB-1.0-SNAPSHOT.jar").toURI()
+        .toURL());
+    cbA.addConfiguration(cbB.build());
+
+    cbA.getClassHierarchy().getNode("org.apache.reef.tang.examples.A");
+    cbA.getClassHierarchy().getNode("org.apache.reef.tang.examples.B");
+
+    t.newInjector(cbA.build());
+  }
+
+  //  @Test
+  public void testTwoClasses() throws MalformedURLException,
+      ClassNotFoundException, BindException, InjectionException, NameResolutionException {
+    Tang t = Tang.Factory.getTang();
+    JavaConfigurationBuilder cbA = t.newConfigurationBuilder(new File(
+        "../tang-test-jarAB/target/tang-test-jarAB-1.0-SNAPSHOT.jar").toURI()
+        .toURL());
+    JavaConfigurationBuilder cbB = t.newConfigurationBuilder(new File(
+        "../tang-test-jarAB/target/tang-test-jarAB-1.0-SNAPSHOT.jar").toURI()
+        .toURL());
+    cbA.addConfiguration(cbB.build());
+
+    cbA.getClassHierarchy().getNode("org.apache.reef.tang.examples.A");
+    cbA.getClassHierarchy().getNode("org.apache.reef.tang.examples.B");
+
+    t.newInjector(cbA.build());
+  }
+
+  //  @Test
+  public void aliasingNameSameDifferentTypes()
+      throws MalformedURLException, InjectionException, BindException,
+      ClassNotFoundException, NameResolutionException {
+    Tang t = Tang.Factory.getTang();
+    JavaConfigurationBuilder cbA1 = t.newConfigurationBuilder(new File(
+        "../tang-test-jarAB/target/tang-test-jarAB-1.0-SNAPSHOT.jar").toURI()
+        .toURL());
+    JavaConfigurationBuilder cbA2 = t.newConfigurationBuilder(new File(
+        "../tang-test-jarAB/target/tang-test-jarAB-1.0-SNAPSHOT.jar").toURI()
+        .toURL());
+    cbA1.getClassHierarchy().getNode("org.apache.reef.tang.examples.A");
+    cbA1.bind("org.apache.reef.tang.examples.A", "org.apache.reef.tang.examples.B");
+    cbA2.bind("org.apache.reef.tang.examples.A", "org.apache.reef.tang.examples.B");
+    Object o = t.newInjector(cbA1.build()).getInstance("org.apache.reef.tang.examples.A");
+    Object p = t.newInjector(cbA2.build()).getInstance("org.apache.reef.tang.examples.A");
+    Assert.assertSame(o.getClass(), p.getClass());
+    JavaConfigurationBuilder cbAother = t.newConfigurationBuilder(new File(
+        "../tang-test-jarA/target/tang-test-jarA-1.0-SNAPSHOT.jar").toURI()
+        .toURL());
+
+    Assert.assertEquals(1, ((ClassNode<?>) (cbA1.getClassHierarchy().getNode("org.apache.reef.tang.examples.A"))).getInjectableConstructors().length);
+    Assert.assertEquals(0, ((ClassNode<?>) (cbAother.getClassHierarchy().getNode("org.apache.reef.tang.examples.A"))).getInjectableConstructors().length);
+
+  }
+
+  //  @Test
+  public void testOneClassOneJar()
+      throws MalformedURLException, InjectionException, BindException,
+      ClassNotFoundException, NameResolutionException {
+    Tang t = Tang.Factory.getTang();
+    JavaConfigurationBuilder cbA1 = t.newConfigurationBuilder(new File(
+        "../tang-test-jarAB/target/tang-test-jarAB-1.0-SNAPSHOT.jar").toURI()
+        .toURL());
+    cbA1.bind("org.apache.reef.tang.examples.A", "org.apache.reef.tang.examples.B");
+    cbA1.getClassHierarchy().getNode("org.apache.reef.tang.examples.A");
+    t.newInjector(cbA1.build()).getInstance("org.apache.reef.tang.examples.B");
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestConfFileParser.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestConfFileParser.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestConfFileParser.java
new file mode 100644
index 0000000..694351f
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestConfFileParser.java
@@ -0,0 +1,119 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.ConfigurationFile;
+import org.apache.reef.tang.implementation.TangImpl;
+import org.apache.reef.tang.util.ReflectionUtilities;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class TestConfFileParser {
+
+  @Before
+  public void setUp() {
+    TangImpl.reset();
+  }
+
+  @Test
+  public void testRoundTrip() throws BindException {
+    // TODO: This likely only passes on windows, as it relies on newlines
+    // being \r\n, and on java.lang.Object having a lower hash code than
+    // org.apache.reef.tang.TestConfFileParser
+    Tang t = Tang.Factory.getTang();
+    JavaConfigurationBuilder cb = t.newConfigurationBuilder();
+    String in = "org.apache.reef.tang.TestConfFileParser=org.apache.reef.tang.TestConfFileParser\n";
+    ConfigurationFile.addConfiguration(cb, in);
+    String out = ConfigurationFile.toConfigurationString(cb.build());
+    Assert.assertEquals(in, out);
+  }
+
+  @Test
+  public void testBindSingleton() throws BindException {
+    // TODO: This likely only passes on windows, as it relies on newlines
+    // being \r\n, and on java.lang.Object having a lower hash code than
+    // org.apache.reef.tang.TestConfFileParser
+    Tang t = Tang.Factory.getTang();
+    JavaConfigurationBuilder cb = t.newConfigurationBuilder();
+    cb.bindImplementation(SingleTest.A.class, SingleTest.B.class);
+
+    String out = ConfigurationFile.toConfigurationString(cb.build());
+    String in = "org.apache.reef.tang.SingleTest$A=org.apache.reef.tang.SingleTest$B\n";
+    Assert.assertEquals(in, out);
+  }
+
+  @Test
+  public void testNamedParameter() throws BindException {
+    Tang t = Tang.Factory.getTang();
+    String conf = "org.apache.reef.tang.TestConfFileParser$Foo=woot";
+    ConfigurationBuilder cb = t.newConfigurationBuilder();
+    ConfigurationFile.addConfiguration(cb, conf);
+    Assert.assertTrue(t.newInjector(cb.build()).isParameterSet(Foo.class));
+  }
+
+  @Test
+  public void testNamedParameter2() throws BindException, IOException, InjectionException {
+
+    final String value = "socket://131.179.176.216:19278";
+    final File tmp = File.createTempFile("test", "conf");
+
+    try (final FileOutputStream fout = new FileOutputStream(tmp)) {
+      final String line = ReflectionUtilities.getFullName(RemoteIdentifier.class) + "=" + value;
+      fout.write(line.getBytes());
+    }
+
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    ConfigurationFile.addConfiguration(cb, tmp);
+    final Injector i = Tang.Factory.getTang().newInjector(cb.build());
+    Assert.assertEquals(value, i.getNamedInstance(RemoteIdentifier.class));
+  }
+
+  @NamedParameter(doc = "remote id.")
+  private final static class RemoteIdentifier implements Name<String> {
+  }
+
+  @NamedParameter()
+  class Foo implements Name<String> {
+  }
+}
+
+@NamedParameter
+final class Foo implements Name<String> {
+}
+
+class SingleTest {
+  static class A {
+  }
+
+  static class B extends A {
+    @Inject
+    B() {
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestExternalConstructor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestExternalConstructor.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestExternalConstructor.java
new file mode 100644
index 0000000..66748c4
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestExternalConstructor.java
@@ -0,0 +1,89 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.junit.Test;
+
+import javax.inject.Inject;
+
+public class TestExternalConstructor {
+
+  @Test
+  public void testExternalConstructor() throws BindException,
+      InjectionException {
+
+    final JavaConfigurationBuilder b = Tang.Factory.getTang()
+        .newConfigurationBuilder();
+    b.bindConstructor(A.class, ACons.class);
+    b.bindConstructor(B.class, BCons.class);
+
+    Tang.Factory.getTang().newInjector(b.build()).getInstance(B.class);
+  }
+
+  static final class A {
+    A() {
+    }
+  }
+
+  static final class B {
+    B(final A a) {
+    }
+  }
+
+  static final class ACons implements ExternalConstructor<A> {
+
+    @Inject
+    ACons() {
+    }
+
+    @Override
+    public A newInstance() {
+      return new A();
+    }
+  }
+
+  static final class BCons implements ExternalConstructor<B> {
+
+    @Inject
+    BCons(final A a) {
+    }
+
+    @Override
+    public B newInstance() {
+      return new B(null);
+    }
+  }
+
+/*  @Test
+  public void testExplicitExternalConstructorIsSingleton() throws BindException, InjectionException {
+    final JavaConfigurationBuilder b = Tang.Factory.getTang()
+        .newConfigurationBuilder();
+    b.bindConstructor(A.class, ACons.class);
+
+    Injector i = Tang.Factory.getTang().newInjector(b.build());
+    
+    A a = i.getInstance(A.class);
+    A aa = (i.getInstance(ACons.class)).newInstance();
+    
+    Assert.assertTrue(a == aa);
+
+  } */
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestImplicitConversions.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestImplicitConversions.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestImplicitConversions.java
new file mode 100644
index 0000000..cc6bf9e
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestImplicitConversions.java
@@ -0,0 +1,167 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.ConfigurationFile;
+import org.apache.reef.tang.types.NamedParameterNode;
+import org.apache.reef.tang.util.ReflectionUtilities;
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.inject.Inject;
+
+public class TestImplicitConversions {
+  @SuppressWarnings("unchecked")
+  @Test
+  public void testBindFromString() throws BindException, InjectionException {
+    JavaConfigurationBuilder b = Tang.Factory.getTang().newConfigurationBuilder(IdentifierParser.class);
+    b.bindNamedParameter(IdName.class, "b://b");
+
+    Configuration c = b.build();
+    String s = ConfigurationFile.toConfigurationString(c);
+
+    JavaConfigurationBuilder b2 = Tang.Factory.getTang().newConfigurationBuilder(IdentifierParser.class);
+    ConfigurationFile.addConfiguration(b2, s);
+    Configuration c2 = b2.build();
+
+    Assert.assertEquals("b://b", c2.getNamedParameter((NamedParameterNode<?>) c2.getClassHierarchy().getNode(ReflectionUtilities.getFullName(IdName.class))));
+    Injector i = Tang.Factory.getTang().newInjector(c2);
+
+    Assert.assertEquals("b://b", i.getNamedInstance(IdName.class).toString());
+    Assert.assertTrue(i.getNamedInstance(IdName.class) instanceof BIdentifier);
+
+  }
+
+  ;
+
+  @SuppressWarnings("unchecked")
+  @Test
+  public void testBindSubclassFromString() throws BindException, InjectionException {
+    JavaConfigurationBuilder b = Tang.Factory.getTang().newConfigurationBuilder(IdentifierParser.class);
+    b.bindNamedParameter(AIdName.class, "a://a");
+    b.bindNamedParameter(BIdName.class, "b://b");
+
+    Configuration c = b.build();
+    String s = ConfigurationFile.toConfigurationString(c);
+
+    JavaConfigurationBuilder b2 = Tang.Factory.getTang().newConfigurationBuilder(IdentifierParser.class);
+    ConfigurationFile.addConfiguration(b2, s);
+    Configuration c2 = b2.build();
+
+    Assert.assertEquals("b://b", c2.getNamedParameter((NamedParameterNode<?>) c2.getClassHierarchy().getNode(ReflectionUtilities.getFullName(BIdName.class))));
+    Injector i = Tang.Factory.getTang().newInjector(c2);
+
+    Assert.assertEquals("b://b", i.getNamedInstance(BIdName.class).toString());
+    Assert.assertTrue(i.getNamedInstance(BIdName.class) instanceof BIdentifier);
+    Assert.assertEquals("a://a", i.getNamedInstance(AIdName.class).toString());
+    Assert.assertTrue(i.getNamedInstance(AIdName.class) instanceof AIdentifier);
+  }
+
+  @SuppressWarnings("unchecked")
+  @Test(expected = ClassCastException.class)
+  public void testBindWrongSubclassFromString() throws BindException, InjectionException {
+    JavaConfigurationBuilder b = Tang.Factory.getTang().newConfigurationBuilder(IdentifierParser.class);
+    b.bindNamedParameter(AIdName.class, "b://b");
+  }
+
+  ;
+
+  @Test(expected = InjectionException.class)
+  public void testInjectUnboundParsable() throws BindException, InjectionException {
+    @SuppressWarnings("unchecked")
+    JavaConfigurationBuilder b = Tang.Factory.getTang().newConfigurationBuilder(IdentifierParser.class);
+    Tang.Factory.getTang().newInjector(b.build()).getNamedInstance(IdName.class);
+  }
+
+  static interface Identifier {
+
+  }
+
+  ;
+
+  static interface AIdentifier extends Identifier {
+
+  }
+
+  static interface BIdentifier extends Identifier {
+
+  }
+
+  static class AIdentifierImpl implements AIdentifier {
+    private final String aString;
+
+    @Inject
+    AIdentifierImpl(String aString) {
+      this.aString = aString;
+    }
+
+    @Override
+    public String toString() {
+      return aString;
+    }
+  }
+
+  static class BIdentifierImpl implements BIdentifier {
+    private final String bString;
+
+    @Inject
+    BIdentifierImpl(String bString) {
+      this.bString = bString;
+    }
+
+    @Override
+    public String toString() {
+      return bString;
+    }
+  }
+
+  static class IdentifierParser implements ExternalConstructor<Identifier> {
+    final Identifier id;
+
+    @Inject
+    public IdentifierParser(String id) {
+      this.id = id.startsWith("a://") ? new AIdentifierImpl(id) : id.startsWith("b://") ? new BIdentifierImpl(id) : null;
+      if (this.id == null) {
+        throw new IllegalArgumentException("Need string that starts with a:// or b://!");
+      }
+    }
+
+    @Override
+    public Identifier newInstance() {
+      return id;
+    }
+  }
+
+  @NamedParameter
+  class IdName implements Name<Identifier> {
+  }
+
+  @NamedParameter
+  class AIdName implements Name<AIdentifier> {
+  }
+
+  @NamedParameter
+  class BIdName implements Name<BIdentifier> {
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestInjectionFuture.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestInjectionFuture.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestInjectionFuture.java
new file mode 100644
index 0000000..dca2359
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestInjectionFuture.java
@@ -0,0 +1,195 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.annotations.DefaultImplementation;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.inject.Inject;
+
+interface A {
+}
+
+@DefaultImplementation(C.class)
+interface B extends A {
+}
+
+public class TestInjectionFuture {
+  @Test
+  public void testFutures() throws InjectionException, BindException {
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    Injector i = Tang.Factory.getTang().newInjector(cb.build());
+    Injector i2 = Tang.Factory.getTang().newInjector(cb.build());
+
+    Futurist f = i.getInstance(Futurist.class);
+    Assert.assertTrue(f == f.getMyCar().getDriver());
+    Assert.assertTrue(f.getMyCar() == f.getMyCar().getDriver().getMyCar());
+
+    Futurist f2 = i2.getInstance(Futurist.class);
+    Assert.assertTrue(f2 == f2.getMyCar().getDriver());
+    Assert.assertTrue(f2.getMyCar() == f2.getMyCar().getDriver().getMyCar());
+
+    Assert.assertTrue(f != f2.getMyCar().getDriver());
+    Assert.assertTrue(f.getMyCar() != f2.getMyCar().getDriver().getMyCar());
+
+  }
+
+  @Test
+  public void testFutures2() throws InjectionException, BindException {
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    Injector i = Tang.Factory.getTang().newInjector(cb.build());
+    Injector i2 = i.forkInjector();
+
+    FlyingCar c = i.getInstance(FlyingCar.class);
+    Assert.assertTrue(c == c.getDriver().getMyCar());
+    Assert.assertTrue(c.getDriver() == c.getDriver().getMyCar().getDriver());
+
+    FlyingCar c2 = i2.getInstance(FlyingCar.class);
+    Assert.assertTrue(c2 == c2.getDriver().getMyCar());
+    Assert.assertTrue(c2.getDriver() == c2.getDriver().getMyCar().getDriver());
+
+    Assert.assertTrue(c2 != c.getDriver().getMyCar());
+    Assert.assertTrue(c2.getDriver() != c.getDriver().getMyCar().getDriver());
+
+  }
+
+  @Test
+  public void testNamedParameterInjectionFuture() throws InjectionException, BindException {
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindImplementation(FlyingCar.class, FlyingCar.class);
+    Injector i = Tang.Factory.getTang().newInjector(cb.build());
+    PickyFuturist f = i.getInstance(PickyFuturist.class);
+    Assert.assertNotNull(f.getMyCar());
+  }
+
+  @Test
+  public void testNamedParameterInjectionFutureDefaultImpl() throws InjectionException, BindException {
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    Injector i = Tang.Factory.getTang().newInjector(cb.build());
+    PickyFuturist f = i.getInstance(PickyFuturist.class);
+    Assert.assertNotNull(f.getMyCar());
+  }
+
+  @Test
+  public void testNamedParameterInjectionFutureBindImpl() throws InjectionException, BindException {
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindImplementation(Futurist.class, PickyFuturist.class);
+    cb.bindNamedParameter(MyFlyingCar.class, BigFlyingCar.class);
+    Injector i = Tang.Factory.getTang().newInjector(cb.build());
+    PickyFuturist f = i.getInstance(PickyFuturist.class);
+    Assert.assertNotNull((BigFlyingCar) f.getMyCar());
+  }
+
+  @Test
+  public void testNamedParameterBoundToDelegatingInterface() throws InjectionException, BindException {
+    Injector i = Tang.Factory.getTang().newInjector();
+    @SuppressWarnings("unused")
+    C c = (C) i.getNamedInstance(AName.class);
+  }
+
+  @Test
+  public void testBoundToDelegatingInterface() throws InjectionException, BindException {
+    Injector i = Tang.Factory.getTang().newInjector();
+    @SuppressWarnings("unused")
+    C c = (C) i.getInstance(B.class);
+  }
+
+
+  @DefaultImplementation(Futurist.class)
+  public static class Futurist {
+    private final InjectionFuture<FlyingCar> f_car;
+
+    @Inject
+    public Futurist(InjectionFuture<FlyingCar> car) {
+      this.f_car = car;
+    }
+
+    public FlyingCar getMyCar() {
+      FlyingCar c = f_car.get();
+      return c;
+    }
+  }
+
+  public static class PickyFuturist extends Futurist {
+    private final InjectionFuture<FlyingCar> f_car;
+
+    @Inject
+    public PickyFuturist(@Parameter(MyFlyingCar.class) InjectionFuture<FlyingCar> myFlyingCar) {
+      super(myFlyingCar);
+      f_car = myFlyingCar;
+    }
+
+    public FlyingCar getMyCar() {
+      FlyingCar c = f_car.get();
+      return c;
+    }
+  }
+
+  @DefaultImplementation(FlyingCar.class)
+  public static class FlyingCar {
+    private final String color;
+    private final Futurist driver;
+
+    @Inject
+    FlyingCar(@Parameter(Color.class) String color, Futurist driver) {
+      this.color = color;
+      this.driver = driver;
+    }
+
+    public String getColor() {
+      return color;
+    }
+
+    public Futurist getDriver() {
+      return driver;
+    }
+
+    @NamedParameter(default_value = "blue")
+    class Color implements Name<String> {
+    }
+  }
+
+  public static class BigFlyingCar extends FlyingCar {
+    @Inject
+    BigFlyingCar(@Parameter(Color.class) String color, Futurist driver) {
+      super(color, driver);
+    }
+  }
+
+  @NamedParameter(default_class = FlyingCar.class)
+  public static class MyFlyingCar implements Name<FlyingCar> {
+  }
+
+}
+
+@NamedParameter(default_class = B.class)
+class AName implements Name<A> {
+}
+
+class C implements B {
+  @Inject
+  C() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestListInjection.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestListInjection.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestListInjection.java
new file mode 100644
index 0000000..9abc82d
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestListInjection.java
@@ -0,0 +1,344 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.RequiredParameter;
+import org.apache.reef.tang.types.ClassNode;
+import org.apache.reef.tang.types.NamedParameterNode;
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Tests for list injection in Tang.
+ */
+public class TestListInjection {
+
+  /**
+   * Test code for injecting default list with string elements
+   *
+   * @throws InjectionException
+   */
+  @Test
+  public void testStringInjectDefault() throws InjectionException {
+    List<String> actual = Tang.Factory.getTang().newInjector().getInstance(StringClass.class).stringList;
+    List<String> expected = new ArrayList<>();
+    expected.add("bye");
+    expected.add("hello");
+    expected.add("hi");
+    Assert.assertEquals(expected, actual);
+  }
+
+  /**
+   * Test code for injecting default list with non-string values
+   *
+   * @throws InjectionException
+   */
+  @Test
+  public void testIntegerInjectDefault() throws InjectionException {
+    List<Integer> actual = Tang.Factory.getTang().newInjector().getInstance(IntegerClass.class).integerList;
+    List<Integer> expected = new ArrayList<>();
+    expected.add(1);
+    expected.add(2);
+    expected.add(3);
+    Assert.assertEquals(expected, actual);
+  }
+
+  /**
+   * Test code for injecting default list with implementations
+   *
+   * @throws InjectionException
+   */
+  @Test
+  public void testObjectInjectDefault() throws InjectionException {
+    Integer integer = 1;
+    Float ffloat = 1.001f;
+
+    Injector injector = Tang.Factory.getTang().newInjector();
+    injector.bindVolatileInstance(Integer.class, integer);
+    injector.bindVolatileInstance(Float.class, ffloat);
+    List<Number> actual = injector.getInstance(NumberClass.class).numberList;
+    List<Number> expected = new ArrayList<>();
+    expected.add(integer);
+    expected.add(ffloat);
+    Assert.assertEquals(expected, actual);
+  }
+
+  /**
+   * Test code for injecting list with String elements
+   *
+   * @throws InjectionException
+   */
+  @Test
+  public void testStringInjectBound() throws InjectionException {
+    List<String> injected = new ArrayList<>();
+    injected.add("hi");
+    injected.add("hello");
+    injected.add("bye");
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindList(StringList.class, injected);
+    List<String> actual = Tang.Factory.getTang().newInjector(cb.build()).getInstance(StringClass.class).stringList;
+    List<String> expected = new ArrayList<>();
+    expected.add("hi");
+    expected.add("hello");
+    expected.add("bye");
+    Assert.assertEquals(expected, actual);
+  }
+
+  /**
+   * Test code for injecting list with parsable non-string values
+   *
+   * @throws InjectionException
+   */
+  @Test
+  public void testIntegerInjectBound() throws InjectionException {
+    List<String> injected = new ArrayList<>();
+    injected.add("1");
+    injected.add("2");
+    injected.add("3");
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindList(IntegerList.class, injected);
+
+    List<Integer> actual = Tang.Factory.getTang().newInjector(cb.build()).getInstance(IntegerClass.class).integerList;
+    List<Integer> expected = new ArrayList<>();
+    expected.add(1);
+    expected.add(2);
+    expected.add(3);
+    Assert.assertEquals(expected, actual);
+  }
+
+  /**
+   * Test code for injecting list with implementations
+   *
+   * @throws InjectionException
+   */
+  @Test
+  public void testObjectInjectBound() throws InjectionException {
+    Integer integer = 1;
+    Float ffloat = 1.001f;
+
+    // Inject implementations via class object
+    List<Class> injected1 = new ArrayList<>();
+    injected1.add(Integer.class);
+    injected1.add(Float.class);
+    JavaConfigurationBuilder cb1 = Tang.Factory.getTang().newConfigurationBuilder();
+    cb1.bindList(NumberList.class, injected1);
+    Injector injector1 = Tang.Factory.getTang().newInjector(cb1.build());
+    injector1.bindVolatileInstance(Integer.class, integer);
+    injector1.bindVolatileInstance(Float.class, ffloat);
+    List<Number> actual1 = injector1.getInstance(NumberClass.class).numberList;
+
+    // Inject implementations via class name
+    List<String> injected2 = new ArrayList<>();
+    injected2.add("java.lang.Integer");
+    injected2.add("java.lang.Float");
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindList(NumberList.class, injected2);
+    Injector injector2 = Tang.Factory.getTang().newInjector(cb.build());
+    injector2.bindVolatileInstance(Integer.class, integer);
+    injector2.bindVolatileInstance(Float.class, ffloat);
+    List<Number> actual2 = injector2.getInstance(NumberClass.class).numberList;
+
+    List<Number> expected = new ArrayList<>();
+    expected.add(integer);
+    expected.add(ffloat);
+    Assert.assertEquals(expected, actual1);
+    Assert.assertEquals(expected, actual2);
+  }
+
+  // TODO: Make tests for list serialization/deserialization after implementing those features.
+
+  /**
+   * Test code for Tang selectivity.
+   *
+   * @throws InjectionException
+   */
+  @Test
+  public void testInjectSelectiveConstructor() throws InjectionException {
+    // Test injection without list binding
+    List<String> actual1 = Tang.Factory.getTang().newInjector().getInstance(SelectiveConsructorClass.class).list;
+    List<String> expected1 = new ArrayList<>();
+    Assert.assertEquals(expected1, actual1);
+    // Test injection with list binding
+    List<String> injected = new ArrayList<>();
+    injected.add("hi");
+    injected.add("hello");
+    injected.add("bye");
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindList(SelectiveInjectTestList.class, injected);
+    List<String> actual2 = Tang.Factory.getTang().newInjector(cb.build()).getInstance(SelectiveConsructorClass.class)
+        .list;
+    List<String> expected2 = new ArrayList<>();
+    expected2.add("hi");
+    expected2.add("hello");
+    expected2.add("bye");
+    Assert.assertEquals(expected2, actual2);
+  }
+
+  /**
+   * Test code for injecting list of strings with ConfigurationBuilder
+   *
+   * @throws InjectionException
+   */
+  @Test
+  public void testStringInjectConfigurationBuilder() throws InjectionException {
+    JavaClassHierarchy namespace = Tang.Factory.getTang().getDefaultClassHierarchy();
+    NamedParameterNode<List<String>> np = (NamedParameterNode) namespace.getNode(StringList.class);
+    List<String> injected = new ArrayList<>();
+    injected.add("hi");
+    injected.add("hello");
+    injected.add("bye");
+
+    ConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindList(np, injected);
+    List<String> actual = Tang.Factory.getTang().newInjector(cb.build()).getInstance(StringClass.class).stringList;
+    List<String> expected = new ArrayList<>();
+    expected.add("hi");
+    expected.add("hello");
+    expected.add("bye");
+    Assert.assertEquals(expected, actual);
+  }
+
+  /**
+   * Test code for injecting list of implementations with ConfigurationBuilder
+   *
+   * @throws InjectionException
+   */
+  @Test
+  public void testObjectInjectConfigurationBuilder() throws InjectionException {
+    Integer integer = 1;
+    Float ffloat = 1.001f;
+
+    JavaClassHierarchy namespace = Tang.Factory.getTang().getDefaultClassHierarchy();
+    NamedParameterNode<List<Class>> np = (NamedParameterNode) namespace.getNode(NumberList.class);
+    List<ClassNode> injected = new ArrayList<>();
+    injected.add((ClassNode) namespace.getNode(Integer.class));
+    injected.add((ClassNode) namespace.getNode(Float.class));
+
+    ConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindList(np, injected);
+
+    Injector injector = Tang.Factory.getTang().newInjector(cb.build());
+    injector.bindVolatileInstance(Integer.class, integer);
+    injector.bindVolatileInstance(Float.class, ffloat);
+    List<Number> actual = injector.getInstance(NumberClass.class).numberList;
+    List<Number> expected = new ArrayList<>();
+    expected.add(integer);
+    expected.add(ffloat);
+    Assert.assertEquals(expected, actual);
+  }
+
+  /**
+   * Test code for injectiong list with ConfigurationModule
+   *
+   * @throws InjectionException
+   */
+  @Test
+  public void testInjectConfigurationModule() throws InjectionException {
+    List<String> injected = new ArrayList<>();
+    injected.add("hi");
+    injected.add("hello");
+    injected.add("bye");
+    Configuration conf = StringClassConfiguration.CONF
+        .set(StringClassConfiguration.STRING_LIST, injected)
+        .build();
+    List<String> actual = Tang.Factory.getTang().newInjector(conf).getInstance(StringClass.class).stringList;
+    List<String> expected = new ArrayList<>();
+    expected.add("hi");
+    expected.add("hello");
+    expected.add("bye");
+    Assert.assertEquals(expected, actual);
+  }
+
+  // ConfigurationModuleBuilder for StringClass
+  public static class StringClassConfiguration extends ConfigurationModuleBuilder {
+    public static final RequiredParameter<List> STRING_LIST = new RequiredParameter<>();
+
+    public static final ConfigurationModule CONF = new StringClassConfiguration()
+        .bindList(StringList.class, StringClassConfiguration.STRING_LIST)
+        .build();
+  }
+}
+
+@NamedParameter(default_values = {"bye", "hello", "hi"})
+class StringList implements Name<List<String>> {
+}
+
+@NamedParameter(default_values = {"1", "2", "3"})
+class IntegerList implements Name<List<Integer>> {
+}
+
+@NamedParameter(default_values = {"java.lang.Integer", "java.lang.Float"})
+class NumberList implements Name<List<Number>> {
+}
+
+@NamedParameter
+class SelectiveInjectTestList implements Name<List<String>> {
+}
+
+class SelectiveConsructorClass {
+  public final List<String> list;
+
+  @Inject
+  SelectiveConsructorClass() {
+    list = new ArrayList<>();
+  }
+
+  @Inject
+  SelectiveConsructorClass(@Parameter(SelectiveInjectTestList.class) final List<String> list) {
+    this.list = list;
+  }
+
+}
+
+class StringClass {
+  public final List<String> stringList;
+
+  @Inject
+  StringClass(@Parameter(StringList.class) final List<String> stringList) {
+    this.stringList = stringList;
+  }
+}
+
+class IntegerClass {
+  public final List<Integer> integerList;
+
+  @Inject
+  IntegerClass(@Parameter(IntegerList.class) final List<Integer> integerList) {
+    this.integerList = integerList;
+  }
+}
+
+class NumberClass {
+  public final List<Number> numberList;
+
+  @Inject
+  NumberClass(@Parameter(NumberList.class) final List<Number> numberList) {
+    this.numberList = numberList;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestNamedParameterRoundTrip.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestNamedParameterRoundTrip.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestNamedParameterRoundTrip.java
new file mode 100644
index 0000000..6ba9ab5
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestNamedParameterRoundTrip.java
@@ -0,0 +1,105 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.ConfigurationFile;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestNamedParameterRoundTrip {
+
+  @Test
+  public void testRoundTrip() throws BindException, InjectionException {
+    final int d = 10;
+    final double eps = 1e-5;
+    final JavaConfigurationBuilder b = Tang.Factory.getTang().newConfigurationBuilder();
+    b.bindNamedParameter(Dimensionality.class, String.valueOf(d));
+    b.bindNamedParameter(Eps.class, String.valueOf(eps));
+    final Configuration conf = b.build();
+
+    {
+      final Injector i = Tang.Factory.getTang().newInjector(conf);
+
+      final int readD = i.getNamedInstance(Dimensionality.class).intValue();
+      final double readEps = i.getNamedInstance(Eps.class).doubleValue();
+
+      assertEquals(eps, readEps, 1e-12);
+      assertEquals(d, readD);
+    }
+
+
+    {
+      JavaConfigurationBuilder roundTrip = Tang.Factory.getTang().newConfigurationBuilder();
+      ConfigurationFile.addConfiguration(roundTrip, ConfigurationFile.toConfigurationString(conf));
+      final Injector i = Tang.Factory.getTang().newInjector(roundTrip.build());
+
+      final int readD = i.getNamedInstance(Dimensionality.class).intValue();
+      final double readEps = i.getNamedInstance(Eps.class).doubleValue();
+
+      assertEquals(eps, readEps, 1e-12);
+      assertEquals(d, readD);
+    }
+
+    {
+      final Injector parent = Tang.Factory.getTang().newInjector(Tang.Factory.getTang().newConfigurationBuilder().build());
+      final Injector i = parent.forkInjector(conf);
+
+      final int readD = i.getNamedInstance(Dimensionality.class).intValue();
+      final double readEps = i.getNamedInstance(Eps.class).doubleValue();
+
+      assertEquals(eps, readEps, 1e-12);
+      assertEquals(d, readD);
+    }
+
+    {
+      final Injector parent = Tang.Factory.getTang().newInjector(Tang.Factory.getTang().newConfigurationBuilder().build());
+      final JavaConfigurationBuilder roundTrip = Tang.Factory.getTang().newConfigurationBuilder();
+      ConfigurationFile.addConfiguration(roundTrip,
+          ConfigurationFile.toConfigurationString(conf));
+      final Injector i = parent.forkInjector(roundTrip.build());
+
+      final int readD = i.getNamedInstance(Dimensionality.class).intValue();
+      final double readEps = i.getNamedInstance(Eps.class).doubleValue();
+
+      assertEquals(eps, readEps, 1e-12);
+      assertEquals(d, readD);
+    }
+
+  }
+
+  @NamedParameter()
+  public final class Dimensionality implements Name<Integer> {
+    // Intentionally Empty
+  }
+
+  /**
+   * Break criterion for the optimizer. If the progress in mean loss between
+   * two iterations is less than this, the optimization stops.
+   */
+  @NamedParameter()
+  public final class Eps implements Name<Double> {
+    // Intentionally Empty
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestSetInjection.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestSetInjection.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestSetInjection.java
new file mode 100644
index 0000000..0901a4d
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestSetInjection.java
@@ -0,0 +1,181 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.AvroConfigurationSerializer;
+import org.apache.reef.tang.formats.ConfigurationSerializer;
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+public class TestSetInjection {
+  @Test
+  public void testStringInjectDefault() throws InjectionException {
+    Set<String> actual = Tang.Factory.getTang().newInjector().getInstance(Box.class).strings;
+
+    Set<String> expected = new HashSet<>();
+    expected.add("one");
+    expected.add("two");
+    expected.add("three");
+
+    Assert.assertEquals(expected, actual);
+  }
+
+  @Test
+  public void testObjectInjectDefault() throws InjectionException, BindException {
+    Injector i = Tang.Factory.getTang().newInjector();
+    i.bindVolatileInstance(Integer.class, 42);
+    i.bindVolatileInstance(Float.class, 42.0001f);
+    Set<Number> actual = i.getInstance(Pool.class).numbers;
+    Set<Number> expected = new HashSet<>();
+    expected.add(42);
+    expected.add(42.0001f);
+    Assert.assertEquals(expected, actual);
+  }
+
+  @Test
+  public void testStringInjectBound() throws InjectionException, BindException {
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindSetEntry(SetOfStrings.class, "four");
+    cb.bindSetEntry(SetOfStrings.class, "five");
+    cb.bindSetEntry(SetOfStrings.class, "six");
+    Set<String> actual = Tang.Factory.getTang().newInjector(cb.build()).getInstance(Box.class).strings;
+
+    Set<String> expected = new HashSet<>();
+    expected.add("four");
+    expected.add("five");
+    expected.add("six");
+
+    Assert.assertEquals(expected, actual);
+  }
+
+  @Test
+  public void testObjectInjectBound() throws InjectionException, BindException {
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindSetEntry(SetOfClasses.class, Short.class);
+    cb.bindSetEntry(SetOfClasses.class, Float.class);
+
+    Injector i = Tang.Factory.getTang().newInjector(cb.build());
+    i.bindVolatileInstance(Short.class, (short) 4);
+    i.bindVolatileInstance(Float.class, 42.0001f);
+    Set<Number> actual = i.getInstance(Pool.class).numbers;
+    Set<Number> expected = new HashSet<>();
+    expected.add((short) 4);
+    expected.add(42.0001f);
+    Assert.assertEquals(expected, actual);
+  }
+
+  @Test
+  public void testStringInjectRoundTrip() throws InjectionException, BindException, IOException {
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindSetEntry(SetOfStrings.class, "four");
+    cb.bindSetEntry(SetOfStrings.class, "five");
+    cb.bindSetEntry(SetOfStrings.class, "six");
+
+    ConfigurationSerializer serializer = new AvroConfigurationSerializer();
+
+    String s = serializer.toString(cb.build());
+    JavaConfigurationBuilder cb2 = Tang.Factory.getTang().newConfigurationBuilder();
+    Configuration conf = serializer.fromString(s);
+    cb2.addConfiguration(conf);
+
+    Set<String> actual = Tang.Factory.getTang().newInjector(cb2.build()).getInstance(Box.class).strings;
+
+    Set<String> expected = new HashSet<>();
+    expected.add("four");
+    expected.add("five");
+    expected.add("six");
+
+    Assert.assertEquals(expected, actual);
+  }
+
+  @Test
+  public void testObjectInjectRoundTrip() throws InjectionException, BindException, IOException {
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindSetEntry(SetOfClasses.class, Short.class);
+    cb.bindSetEntry(SetOfClasses.class, Float.class);
+
+    ConfigurationSerializer serializer = new AvroConfigurationSerializer();
+
+    String s = serializer.toString(cb.build());
+    JavaConfigurationBuilder cb2 = Tang.Factory.getTang().newConfigurationBuilder();
+    Configuration conf = serializer.fromString(s);
+    cb2.addConfiguration(conf);
+
+    Injector i = Tang.Factory.getTang().newInjector(cb2.build());
+    i.bindVolatileInstance(Short.class, (short) 4);
+    i.bindVolatileInstance(Float.class, 42.0001f);
+    Set<Number> actual = i.getInstance(Pool.class).numbers;
+    Set<Number> expected = new HashSet<>();
+    expected.add((short) 4);
+    expected.add(42.0001f);
+    Assert.assertEquals(expected, actual);
+  }
+
+  @Test
+  public void testDefaultAsClass() throws InjectionException, BindException {
+    Injector i = Tang.Factory.getTang().newInjector();
+    i.bindVolatileInstance(Integer.class, 1);
+    i.bindVolatileInstance(Float.class, 2f);
+    Set<Number> actual = i.getNamedInstance(SetOfClassesDefaultClass.class);
+    Set<Number> expected = new HashSet<>();
+    expected.add(1);
+    Assert.assertEquals(expected, actual);
+  }
+
+}
+
+@NamedParameter(default_values = {"one", "two", "three"})
+class SetOfStrings implements Name<Set<String>> {
+}
+
+class Box {
+  public final Set<String> strings;
+
+  @Inject
+  Box(@Parameter(SetOfStrings.class) Set<String> strings) {
+    this.strings = strings;
+  }
+}
+
+@NamedParameter(default_values = {"java.lang.Integer", "java.lang.Float"})
+class SetOfClasses implements Name<Set<Number>> {
+}
+
+class Pool {
+  public final Set<Number> numbers;
+
+  @Inject
+  Pool(@Parameter(SetOfClasses.class) Set<Number> numbers) {
+    this.numbers = numbers;
+  }
+}
+
+@NamedParameter(default_class = Integer.class)
+class SetOfClassesDefaultClass implements Name<Set<Number>> {
+}
\ No newline at end of file


[22/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/AzureStorageAccountKey.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/AzureStorageAccountKey.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/AzureStorageAccountKey.java
new file mode 100644
index 0000000..d17ca80
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/AzureStorageAccountKey.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.runtime.hdinsight.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The Storage account key to be used by Azure.
+ */
+@NamedParameter(doc = "The Storage account key to be used by Azure")
+public final class AzureStorageAccountKey implements Name<String> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/AzureStorageAccountName.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/AzureStorageAccountName.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/AzureStorageAccountName.java
new file mode 100644
index 0000000..5d0acae
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/AzureStorageAccountName.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.runtime.hdinsight.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The Storage account to be used by Azure.
+ */
+@NamedParameter(doc = "The Storage account to be used by Azure")
+public final class AzureStorageAccountName implements Name<String> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/AzureStorageBaseFolder.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/AzureStorageBaseFolder.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/AzureStorageBaseFolder.java
new file mode 100644
index 0000000..46f6d85
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/AzureStorageBaseFolder.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.runtime.hdinsight.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The folder to use as the base folder for storing the JARs.
+ */
+@NamedParameter(doc = " The folder to use as the base folder for storing the JARs.", default_value = "apps/reef/jobs/")
+public final class AzureStorageBaseFolder implements Name<String> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/HDInsightInstanceURL.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/HDInsightInstanceURL.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/HDInsightInstanceURL.java
new file mode 100644
index 0000000..2019970
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/HDInsightInstanceURL.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.runtime.hdinsight.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The password to be used for connecting to hdinsight.
+ */
+@NamedParameter(doc = "The instance URL")
+public final class HDInsightInstanceURL implements Name<String> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/HDInsightPassword.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/HDInsightPassword.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/HDInsightPassword.java
new file mode 100644
index 0000000..458c66e
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/HDInsightPassword.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.runtime.hdinsight.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The password to be used for connecting to hdinsight.
+ */
+@NamedParameter(doc = "The password to be used for connecting to hdinsight.")
+public final class HDInsightPassword implements Name<String> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/HDInsightUsername.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/HDInsightUsername.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/HDInsightUsername.java
new file mode 100644
index 0000000..21bc14e
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/HDInsightUsername.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.runtime.hdinsight.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The username to be used for connecting to hdinsight.
+ */
+@NamedParameter(doc = "The username to be used for connecting to hdinsight.")
+public final class HDInsightUsername implements Name<String> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/pom.xml b/lang/java/reef-runtime-local/pom.xml
new file mode 100644
index 0000000..7dff839
--- /dev/null
+++ b/lang/java/reef-runtime-local/pom.xml
@@ -0,0 +1,62 @@
+<?xml version="1.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.
+-->
+<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.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>reef-runtime-local</artifactId>
+    <name>REEF Runtime Local</name>
+    <description>A local implementation of REEF that uses local JVMs for execution.</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <resources>
+            <resource>
+                <targetPath>META-INF/</targetPath>
+                <filtering>false</filtering>
+                <directory>${basedir}/conf</directory>
+                <includes>
+                    <include>*.xml</include>
+                    <include>*.properties</include>
+                </includes>
+                <excludes>
+                </excludes>
+            </resource>
+        </resources>
+    </build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/LocalClasspathProvider.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/LocalClasspathProvider.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/LocalClasspathProvider.java
new file mode 100644
index 0000000..22d1fd8
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/LocalClasspathProvider.java
@@ -0,0 +1,134 @@
+/**
+ * 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.reef.runtime.local;
+
+import org.apache.reef.runtime.common.files.RuntimeClasspathProvider;
+import org.apache.reef.util.Optional;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+
+/**
+ * RuntimeClasspathProvider for the local runtime.
+ * <p/>
+ * The prefix for the local runtime is empty, the suffix is the classpath of the current JVM. That classpath is filtered
+ * to not contain subfolders of JAVA_HOME. Also, duplicates are removed.
+ */
+public final class LocalClasspathProvider implements RuntimeClasspathProvider {
+  private final List<String> classPathSuffix;
+
+  @Inject
+  LocalClasspathProvider() {
+    this.classPathSuffix = Collections.unmodifiableList(new ArrayList<>(getFilteredClasspath()));
+  }
+
+  /**
+   * @return the classpath filtered by entries in subfolders of JAVA_HOME are removed, so are duplicate entries.
+   */
+  private static LinkedHashSet<String> getFilteredClasspath() {
+    final LinkedHashSet<String> result = new LinkedHashSet<>();
+    final Optional<Path> javaHome = getJavaHome();
+
+    if (javaHome.isPresent()) {
+      final Path javaHomePath = javaHome.get();
+      for (final Path classPathEntry : getClasspath()) {
+        if (!classPathEntry.startsWith(javaHomePath)) {
+          result.add(toAbsolutePathString(classPathEntry));
+        }
+      }
+    } else {
+      for (final Path classPathEntry : getClasspath()) {
+        result.add(toAbsolutePathString(classPathEntry));
+      }
+    }
+    return result;
+  }
+
+  /**
+   * @return the path to "JAVA_HOME", if that is set. Optional.empty(), else.
+   */
+  private static Optional<Path> getJavaHome() {
+    final Optional<String> javaHome = getEnv("JAVA_HOME");
+
+    if (javaHome.isPresent()) {
+      final File javaHomeFile = new File(javaHome.get());
+      if (javaHomeFile.exists()) {
+        return Optional.of(javaHomeFile.toPath());
+      }
+    }
+    return Optional.empty();
+  }
+
+  /**
+   * @param envName
+   * @return the value of the environment variable, if there is one.
+   */
+  private static Optional<String> getEnv(final String envName) {
+    return Optional.ofNullable(System.getenv(envName));
+  }
+
+  /**
+   * @return the classpath of the current JVM. Duplicates are removed.
+   */
+  private static LinkedHashSet<Path> getClasspath() {
+    final LinkedHashSet<Path> result = new LinkedHashSet<>();
+    for (final String classPathEntry : System.getProperty("java.class.path").split(File.pathSeparator)) {
+      final File file = new File(classPathEntry);
+      if (file.exists()) {
+        result.add(file.toPath());
+      }
+    }
+    return result;
+  }
+
+  /**
+   * Concerts the given path into a String representing the absolute path.
+   *
+   * @param path
+   * @return
+   */
+  private static String toAbsolutePathString(final Path path) {
+    return path.toAbsolutePath().toString();
+  }
+
+  @Override
+  public List<String> getDriverClasspathPrefix() {
+    return Collections.emptyList();
+  }
+
+  @Override
+  public List<String> getDriverClasspathSuffix() {
+    return this.classPathSuffix;
+  }
+
+  @Override
+  public List<String> getEvaluatorClasspathPrefix() {
+    return Collections.emptyList();
+  }
+
+  @Override
+  public List<String> getEvaluatorClasspathSuffix() {
+    return this.classPathSuffix;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/DriverFiles.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/DriverFiles.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/DriverFiles.java
new file mode 100644
index 0000000..06262e4
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/DriverFiles.java
@@ -0,0 +1,174 @@
+/**
+ * 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.reef.runtime.local.client;
+
+import org.apache.reef.proto.ClientRuntimeProtocol;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.files.REEFFileNames;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.OptionalParameter;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Represents the files added to a driver.
+ * <p/>
+ * This class is constructed via the from() method that instantiates it based on a JobSubmissionProto
+ */
+final class DriverFiles {
+
+  private static final Logger LOG = Logger.getLogger(DriverFiles.class.getName());
+
+  private final FileSet localFiles = new FileSet();
+  private final FileSet localLibs = new FileSet();
+  private final FileSet globalFiles = new FileSet();
+  private final FileSet globalLibs = new FileSet();
+  private final REEFFileNames fileNames;
+
+  public DriverFiles(final REEFFileNames fileNames) {
+    this.fileNames = fileNames;
+  }
+
+  /**
+   * Instantiates an instance based on the given JobSubmissionProto.
+   *
+   * @param jobSubmissionProto the JobSubmissionProto to parse.
+   * @return a DriverFiles instance pre-populated with the information from the given JobSubmissionProto.
+   * @throws IOException
+   */
+  public static DriverFiles fromJobSubmission(
+      final ClientRuntimeProtocol.JobSubmissionProto jobSubmissionProto,
+      final REEFFileNames fileNames) throws IOException {
+
+    final DriverFiles driverFiles = new DriverFiles(fileNames);
+
+    for (final ReefServiceProtos.FileResourceProto frp : jobSubmissionProto.getGlobalFileList()) {
+      final File f = new File(frp.getPath());
+      if (frp.getType() == ReefServiceProtos.FileType.LIB) {
+        driverFiles.addGlobalLib(f);
+      } else {
+        driverFiles.addGlobalFile(f);
+      }
+    }
+
+    for (final ReefServiceProtos.FileResourceProto frp : jobSubmissionProto.getLocalFileList()) {
+      final File f = new File(frp.getPath());
+      if (frp.getType() == ReefServiceProtos.FileType.LIB) {
+        driverFiles.addLocalLib(f);
+      } else {
+        driverFiles.addLocalFile(f);
+      }
+    }
+
+    return driverFiles;
+  }
+
+  private void addLocalLib(final File f) throws IOException {
+    checkFile(f);
+    this.localLibs.add(f);
+  }
+
+  private void addLocalFile(final File f) throws IOException {
+    checkFile(f);
+    this.localFiles.add(f);
+  }
+
+  private void addGlobalFile(final File f) throws IOException {
+    checkFile(f);
+    this.globalFiles.add(f);
+  }
+
+  private void addGlobalLib(final File f) throws IOException {
+    checkFile(f);
+    this.globalLibs.add(f);
+  }
+
+  private void checkFile(final File f) {
+    if (this.globalLibs.containsFileWithName(f.getName())) {
+      LOG.log(Level.FINEST, "Adding a file that is already part of the global libraries: {0}", f);
+    }
+    if (this.globalFiles.containsFileWithName(f.getName())) {
+      LOG.log(Level.FINEST, "Adding a file that is already part of the global files: {0}", f);
+    }
+    if (this.localLibs.containsFileWithName(f.getName())) {
+      LOG.log(Level.FINEST, "Adding a file that is already part of the local libraries: {0}", f);
+    }
+    if (this.localFiles.containsFileWithName(f.getName())) {
+      LOG.log(Level.FINEST, "Adding a file that is already part of the local files: {0}", f);
+    }
+  }
+
+  /**
+   * Copies this set of files to the destination folder given.
+   * <p/>
+   * Will attempt to create symbolic links for the files to the destination
+   * folder.  If the filesystem does not support symbolic links or the user
+   * does not have appropriate permissions, the entire file will be copied instead.
+   *
+   * @param destinationFolder the folder the files shall be copied to.
+   * @throws IOException if one or more of the copies fail.
+   */
+  public void copyTo(final File destinationFolder) throws IOException {
+    destinationFolder.mkdirs();
+    final File reefFolder = new File(destinationFolder, fileNames.getREEFFolderName());
+
+    final File localFolder = new File(reefFolder, fileNames.getLocalFolderName());
+    final File globalFolder = new File(reefFolder, fileNames.getGlobalFolderName());
+    localFolder.mkdirs();
+    globalFolder.mkdirs();
+
+    try {
+      this.localFiles.createSymbolicLinkTo(localFolder);
+      this.localLibs.createSymbolicLinkTo(localFolder);
+      this.globalLibs.createSymbolicLinkTo(globalFolder);
+      this.globalFiles.createSymbolicLinkTo(globalFolder);
+    } catch (IOException e) {
+      this.localFiles.copyTo(localFolder);
+      this.localLibs.copyTo(localFolder);
+      this.globalLibs.copyTo(globalFolder);
+      this.globalFiles.copyTo(globalFolder);
+    }
+  }
+
+  /**
+   * Fills out a ConfigurationModule.
+   *
+   * @param input           The ConfigurationModule to start with.
+   * @param globalFileField the field on which to set() the global files.
+   * @param globalLibField  the field on which to set() the global libraries.
+   * @param localFileField  the field on which to set() the local files.
+   * @param localLibField   the field on which to set() the local libraries.
+   * @return a copy of input with files and libraries added to the given fields.
+   */
+  public ConfigurationModule addNamesTo(final ConfigurationModule input,
+                                        final OptionalParameter<String> globalFileField,
+                                        final OptionalParameter<String> globalLibField,
+                                        final OptionalParameter<String> localFileField,
+                                        final OptionalParameter<String> localLibField) {
+    ConfigurationModule result = input;
+    result = this.globalFiles.addNamesTo(result, globalFileField);
+    result = this.globalLibs.addNamesTo(result, globalLibField);
+    result = this.localFiles.addNamesTo(result, localFileField);
+    result = this.localLibs.addNamesTo(result, localLibField);
+    return result;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/ExecutorServiceConstructor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/ExecutorServiceConstructor.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/ExecutorServiceConstructor.java
new file mode 100644
index 0000000..8a211e8
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/ExecutorServiceConstructor.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.runtime.local.client;
+
+import org.apache.reef.tang.ExternalConstructor;
+
+import javax.inject.Inject;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Used to make instances of ExecutorService via tang.
+ */
+public final class ExecutorServiceConstructor implements ExternalConstructor<ExecutorService> {
+  private static final Logger LOG = Logger.getLogger(ExecutorServiceConstructor.class.getName());
+
+  @Inject
+  ExecutorServiceConstructor() {
+  }
+
+  @Override
+  public ExecutorService newInstance() {
+    LOG.log(Level.FINEST, "Instantiating new 'ExecutorService'.");
+    return Executors.newCachedThreadPool();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/FileSet.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/FileSet.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/FileSet.java
new file mode 100644
index 0000000..df3d5cd
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/FileSet.java
@@ -0,0 +1,113 @@
+/**
+ * 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.reef.runtime.local.client;
+
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.OptionalParameter;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Manages a set of files.
+ */
+final class FileSet {
+  private static final Logger LOG = Logger.getLogger(FileSet.class.getName());
+  private final Set<File> theFiles = new HashSet<>();
+  private final Set<String> fileNames = new HashSet<>();
+
+  /**
+   * Add a file to the FileSet.
+   * <p/>
+   * If the file is a directory, it is turned into a JAR and the resulting JAR is added.
+   * <p/>
+   * Files already added will be ignored.
+   *
+   * @param file the file to be added.
+   */
+  final void add(final File file) {
+    if (file.isFile()) {
+      if (this.fileNames.contains(file.getName())) {
+        LOG.log(Level.FINEST, "A file with this name has already been added: {0}", file.getName());
+      } else {
+        this.fileNames.add(file.getName());
+        this.theFiles.add(file);
+      }
+    } else {
+      LOG.log(Level.FINEST, "Ignoring, because it is not a proper file: {0}", file);
+    }
+  }
+
+  final boolean containsFileWithName(final String name) {
+    return this.fileNames.contains(name);
+  }
+
+  /**
+   * @return an iterable over the filenames, sans the folder. e.g. "/tmp/foo.txt" is returned as "foo.txt"
+   */
+  final Set<String> fileNames() {
+    return this.fileNames;
+  }
+
+  /**
+   * Copies all files in the current FileSet to the given destinationFolder.
+   *
+   * @param destinationFolder the folder where the files shall be copied to.
+   * @throws IOException
+   */
+  final void copyTo(final File destinationFolder) throws IOException {
+    for (final File f : this.theFiles) {
+      final File destinationFile = new File(destinationFolder, f.getName());
+      Files.copy(f.toPath(), destinationFile.toPath());
+    }
+  }
+
+  /**
+   * Creates symbolic links for the current FileSet into the given destinationFolder.
+   *
+   * @param destinationFolder the folder where the symbolic links will be created.
+   * @throws IOException
+   */
+  final void createSymbolicLinkTo(final File destinationFolder) throws IOException {
+    for (final File f : this.theFiles) {
+      final File destinationFile = new File(destinationFolder, f.getName());
+      Files.createSymbolicLink(destinationFile.toPath(), f.toPath());
+    }
+  }
+
+  /**
+   * Adds the file names of this FileSet to the given field of the given ConfigurationModule.
+   *
+   * @param input the ConfigurationModule to fill out
+   * @param field the field to add the files in this set to.
+   * @return the filled out ConfigurationModule
+   */
+  final ConfigurationModule addNamesTo(final ConfigurationModule input, final OptionalParameter<String> field) {
+    ConfigurationModule result = input;
+    for (final String fileName : this.fileNames()) {
+      result = result.set(field, fileName);
+    }
+    return result;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/LocalJobSubmissionHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/LocalJobSubmissionHandler.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/LocalJobSubmissionHandler.java
new file mode 100644
index 0000000..66b3ce6
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/LocalJobSubmissionHandler.java
@@ -0,0 +1,166 @@
+/**
+ * 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.reef.runtime.local.client;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.ClientRuntimeProtocol;
+import org.apache.reef.runtime.common.client.api.JobSubmissionHandler;
+import org.apache.reef.runtime.common.files.ClasspathProvider;
+import org.apache.reef.runtime.common.files.REEFFileNames;
+import org.apache.reef.runtime.common.launch.JavaLaunchCommandBuilder;
+import org.apache.reef.runtime.common.parameters.JVMHeapSlack;
+import org.apache.reef.runtime.local.client.parameters.NumberOfProcesses;
+import org.apache.reef.runtime.local.client.parameters.RootFolder;
+import org.apache.reef.runtime.local.driver.LocalDriverConfiguration;
+import org.apache.reef.runtime.local.driver.LocalDriverRuntimeConfiguration;
+import org.apache.reef.runtime.local.process.LoggingRunnableProcessObserver;
+import org.apache.reef.runtime.local.process.RunnableProcess;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.formats.ConfigurationSerializer;
+import org.apache.reef.util.logging.LoggingScope;
+import org.apache.reef.util.logging.LoggingScopeFactory;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Handles Job Submissions for the Local Runtime.
+ */
+@Private
+@ClientSide
+final class LocalJobSubmissionHandler implements JobSubmissionHandler {
+
+  /**
+   * The name of the folder for the driver within the Job folder.
+   */
+  public static final String DRIVER_FOLDER_NAME = "driver";
+  /**
+   * The (hard-coded) amount of memory to be used for the driver.
+   */
+  public static final int DRIVER_MEMORY = 512;
+  private static final Logger LOG = Logger.getLogger(LocalJobSubmissionHandler.class.getName());
+  private final ExecutorService executor;
+  private final int nThreads;
+  private final String rootFolderName;
+  private final ConfigurationSerializer configurationSerializer;
+  private final REEFFileNames filenames;
+  private final ClasspathProvider classpath;
+  private final double jvmHeapSlack;
+  private final LoggingScopeFactory loggingScopeFactory;
+
+  @Inject
+  public LocalJobSubmissionHandler(
+      final ExecutorService executor,
+      final @Parameter(RootFolder.class) String rootFolderName,
+      final @Parameter(NumberOfProcesses.class) int nThreads,
+      final ConfigurationSerializer configurationSerializer,
+      final REEFFileNames filenames,
+      final ClasspathProvider classpath,
+      final @Parameter(JVMHeapSlack.class) double jvmHeapSlack,
+      final LoggingScopeFactory loggingScopeFactory) {
+
+    this.executor = executor;
+    this.nThreads = nThreads;
+    this.configurationSerializer = configurationSerializer;
+    this.filenames = filenames;
+    this.classpath = classpath;
+    this.jvmHeapSlack = jvmHeapSlack;
+    this.rootFolderName = new File(rootFolderName).getAbsolutePath();
+    this.loggingScopeFactory = loggingScopeFactory;
+
+    LOG.log(Level.FINE, "Instantiated 'LocalJobSubmissionHandler'");
+  }
+
+  @Override
+  public final void close() {
+    this.executor.shutdown();
+  }
+
+  @Override
+  public final void onNext(final ClientRuntimeProtocol.JobSubmissionProto t) {
+    try (final LoggingScope lf = loggingScopeFactory.localJobSubmission()) {
+      try {
+        LOG.log(Level.FINEST, "Starting local job {0}", t.getIdentifier());
+
+        final File jobFolder = new File(new File(rootFolderName),
+            "/" + t.getIdentifier() + "-" + System.currentTimeMillis() + "/");
+
+        final File driverFolder = new File(jobFolder, DRIVER_FOLDER_NAME);
+        driverFolder.mkdirs();
+
+        final DriverFiles driverFiles = DriverFiles.fromJobSubmission(t, this.filenames);
+        driverFiles.copyTo(driverFolder);
+
+        final Configuration driverConfigurationPart1 = driverFiles
+            .addNamesTo(LocalDriverConfiguration.CONF,
+                LocalDriverConfiguration.GLOBAL_FILES,
+                LocalDriverConfiguration.GLOBAL_LIBRARIES,
+                LocalDriverConfiguration.LOCAL_FILES,
+                LocalDriverConfiguration.LOCAL_LIBRARIES)
+            .set(LocalDriverConfiguration.NUMBER_OF_PROCESSES, this.nThreads)
+            .set(LocalDriverConfiguration.ROOT_FOLDER, jobFolder.getAbsolutePath())
+            .set(LocalDriverConfiguration.JVM_HEAP_SLACK, this.jvmHeapSlack)
+            .build();
+
+        final Configuration driverConfigurationPart2 = new LocalDriverRuntimeConfiguration()
+            .addClientConfiguration(this.configurationSerializer.fromString(t.getConfiguration()))
+            .setClientRemoteIdentifier(t.getRemoteId())
+            .setJobIdentifier(t.getIdentifier()).build();
+
+        final Configuration driverConfiguration = Tang.Factory.getTang()
+            .newConfigurationBuilder(driverConfigurationPart1, driverConfigurationPart2).build();
+        final File runtimeConfigurationFile = new File(driverFolder, this.filenames.getDriverConfigurationPath());
+        this.configurationSerializer.toFile(driverConfiguration, runtimeConfigurationFile);
+
+        final List<String> command = new JavaLaunchCommandBuilder()
+            .setErrorHandlerRID(t.getRemoteId())
+            .setLaunchID(t.getIdentifier())
+            .setConfigurationFileName(this.filenames.getDriverConfigurationPath())
+            .setClassPath(this.classpath.getDriverClasspath())
+            .setMemory(DRIVER_MEMORY)
+            .build();
+
+        if (LOG.isLoggable(Level.FINEST)) {
+          LOG.log(Level.FINEST, "REEF app command: {0}", StringUtils.join(command, ' '));
+        }
+
+        final RunnableProcess process = new RunnableProcess(command,
+            "driver",
+            driverFolder,
+            new LoggingRunnableProcessObserver(),
+            this.filenames.getDriverStdoutFileName(),
+            this.filenames.getDriverStderrFileName());
+        this.executor.submit(process);
+        this.executor.shutdown();
+
+      } catch (final Exception e) {
+        LOG.log(Level.SEVERE, "Unable to setup driver.", e);
+        throw new RuntimeException("Unable to setup driver.", e);
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/LocalRuntimeConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/LocalRuntimeConfiguration.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/LocalRuntimeConfiguration.java
new file mode 100644
index 0000000..fe7f104
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/LocalRuntimeConfiguration.java
@@ -0,0 +1,82 @@
+/**
+ * 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.reef.runtime.local.client;
+
+import org.apache.reef.client.REEF;
+import org.apache.reef.client.RunningJob;
+import org.apache.reef.runtime.common.client.REEFImplementation;
+import org.apache.reef.runtime.common.client.RunningJobImpl;
+import org.apache.reef.runtime.common.client.api.JobSubmissionHandler;
+import org.apache.reef.runtime.common.files.RuntimeClasspathProvider;
+import org.apache.reef.runtime.common.launch.REEFMessageCodec;
+import org.apache.reef.runtime.common.parameters.JVMHeapSlack;
+import org.apache.reef.runtime.local.LocalClasspathProvider;
+import org.apache.reef.runtime.local.client.parameters.NumberOfProcesses;
+import org.apache.reef.runtime.local.client.parameters.RootFolder;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.OptionalParameter;
+import org.apache.reef.wake.remote.RemoteConfiguration;
+
+import java.util.concurrent.ExecutorService;
+
+/**
+ * A ConfigurationModule to configure the local resourcemanager.
+ */
+public class LocalRuntimeConfiguration extends ConfigurationModuleBuilder {
+
+  /**
+   * The number of threads or processes available to the resourcemanager. This is the upper limit on the number of
+   * Evaluators that the local resourcemanager will hand out concurrently. This simulates the size of a physical cluster in
+   * terms of the number of slots available on it with one important caveat: The Driver is not counted against this
+   * number.
+   */
+  public static final OptionalParameter<Integer> NUMBER_OF_THREADS = new OptionalParameter<>();
+  /**
+   * The folder in which the sub-folders, one per Node, will be created. Those will contain one folder per
+   * Evaluator instantiated on the virtual node. Those inner folders will be named by the time when the Evaluator was
+   * launched.
+   * <p/>
+   * If none is given, a folder "REEF_LOCAL_RUNTIME" will be created in the local directory.
+   */
+  public static final OptionalParameter<String> RUNTIME_ROOT_FOLDER = new OptionalParameter<>();
+
+  /**
+   * The fraction of the container memory NOT to use for the Java Heap.
+   */
+  public static final OptionalParameter<Double> JVM_HEAP_SLACK = new OptionalParameter<>();
+
+  /**
+   * The ConfigurationModule for the local resourcemanager.
+   */
+  public static final ConfigurationModule CONF = new LocalRuntimeConfiguration()
+      .bindImplementation(REEF.class, REEFImplementation.class)
+      .bindImplementation(RunningJob.class, RunningJobImpl.class)
+      .bindImplementation(JobSubmissionHandler.class, LocalJobSubmissionHandler.class)
+      .bindConstructor(ExecutorService.class, ExecutorServiceConstructor.class)
+          // Bind the message codec for REEF.
+      .bindNamedParameter(RemoteConfiguration.MessageCodec.class, REEFMessageCodec.class)
+      .bindNamedParameter(NumberOfProcesses.class, NUMBER_OF_THREADS)
+      .bindNamedParameter(RootFolder.class, RUNTIME_ROOT_FOLDER)
+      .bindNamedParameter(JVMHeapSlack.class, JVM_HEAP_SLACK)
+      .bindImplementation(RuntimeClasspathProvider.class, LocalClasspathProvider.class)
+      .build();
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/package-info.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/package-info.java
new file mode 100644
index 0000000..6665204
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * client-side event handlers for the local resourcemanager
+ */
+package org.apache.reef.runtime.local.client;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/DefaultMemorySize.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/DefaultMemorySize.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/DefaultMemorySize.java
new file mode 100644
index 0000000..410723b
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/DefaultMemorySize.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.runtime.local.client.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The size of the default container returned in MB.
+ */
+@NamedParameter(doc = "The size of the default container returned in MB", default_value = "512")
+public class DefaultMemorySize implements Name<Integer> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/DefaultNumberOfCores.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/DefaultNumberOfCores.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/DefaultNumberOfCores.java
new file mode 100644
index 0000000..a57a067
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/DefaultNumberOfCores.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.runtime.local.client.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The number of the default core.
+ */
+@NamedParameter(doc = "The number of the default core", default_value = "1")
+public class DefaultNumberOfCores implements Name<Integer> {
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/NumberOfProcesses.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/NumberOfProcesses.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/NumberOfProcesses.java
new file mode 100644
index 0000000..be0e5d4
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/NumberOfProcesses.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.runtime.local.client.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The maximum number of processes to use at once
+ */
+@NamedParameter(default_value = "4", doc = "The maximum number of processes to use at once", short_name = "nThreads")
+public final class NumberOfProcesses implements Name<Integer> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/RootFolder.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/RootFolder.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/RootFolder.java
new file mode 100644
index 0000000..710e737
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/RootFolder.java
@@ -0,0 +1,30 @@
+/**
+ * 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.reef.runtime.local.client.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The folder where logs etc. shall be stored.
+ */
+@NamedParameter(default_value = RootFolder.DEFAULT_VALUE, doc = "The folder where logs etc. shall be stored.")
+public class RootFolder implements Name<String> {
+  public static final String DEFAULT_VALUE = "REEF_LOCAL_RUNTIME";
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/package-info.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/package-info.java
new file mode 100644
index 0000000..ec18095
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/client/parameters/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Parameters of the local runtime.
+ */
+package org.apache.reef.runtime.local.client.parameters;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/Container.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/Container.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/Container.java
new file mode 100644
index 0000000..602575b
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/Container.java
@@ -0,0 +1,85 @@
+/**
+ * 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.reef.runtime.local.driver;
+
+import org.apache.reef.annotations.audience.Private;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * Represents a Container: A slice of a machine.
+ * <p/>
+ * In the case of the local resourcemanager, this slice is always the one of the machine where the job was submitted.
+ */
+@Private
+interface Container extends AutoCloseable {
+
+  /**
+   * Run the given commandLine in the container.
+   *
+   * @param commandLine the command line to execute. It will typically be joined by spaces to form the command line.
+   */
+  public void run(final List<String> commandLine);
+
+  /**
+   * Copies the files to the working directory of the container.
+   *
+   * @param files the files to be added to the container.
+   */
+  public void addLocalFiles(final Iterable<File> files);
+
+  public void addGlobalFiles(final File globalFolder);
+
+  /**
+   * @return true if the Container is currently executing, false otherwise.
+   */
+  public boolean isRunning();
+
+  /**
+   * @return the ID of the node this Container is executing on.
+   */
+  public String getNodeID();
+
+  /**
+   * @return the ID of this Container.
+   */
+  public String getContainerID();
+
+  /**
+   * @return the main memory available to the Container.
+   */
+  public int getMemory();
+
+  /**
+   * @return the core available to the Container.
+   */
+  public int getNumberOfCores();
+
+  /**
+   * @return the working directory of the Container.
+   */
+  public File getFolder();
+
+  /**
+   * Kills the Container.
+   */
+  @Override
+  public void close();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ContainerManager.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ContainerManager.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ContainerManager.java
new file mode 100644
index 0000000..11fb21c
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ContainerManager.java
@@ -0,0 +1,202 @@
+/**
+ * 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.reef.runtime.local.driver;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.client.FailedRuntime;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.driver.api.RuntimeParameters;
+import org.apache.reef.runtime.common.files.REEFFileNames;
+import org.apache.reef.runtime.common.utils.RemoteManager;
+import org.apache.reef.runtime.local.client.parameters.NumberOfProcesses;
+import org.apache.reef.runtime.local.client.parameters.RootFolder;
+import org.apache.reef.runtime.local.process.ReefRunnableProcessObserver;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.NetUtils;
+import org.apache.reef.wake.remote.RemoteMessage;
+import org.apache.reef.wake.time.Time;
+import org.apache.reef.wake.time.runtime.RuntimeClock;
+import org.apache.reef.wake.time.runtime.event.RuntimeStart;
+import org.apache.reef.wake.time.runtime.event.RuntimeStop;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Manages a set of Containers that each reference a Thread.
+ */
+@Private
+@DriverSide
+final class ContainerManager implements AutoCloseable {
+
+  private final static Logger LOG = Logger.getLogger(ContainerManager.class.getName());
+
+  /**
+   * Map from containerID -> Container
+   */
+  private final Map<String, Container> containers = new HashMap<>();
+
+  /**
+   * List of free, unallocated nodes by their Node ID
+   */
+  private final List<String> freeNodeList = new LinkedList<>();
+
+  private final String errorHandlerRID;
+  private final int capacity;
+  private final EventHandler<DriverRuntimeProtocol.NodeDescriptorProto> nodeDescriptorHandler;
+  private final File rootFolder;
+  private final REEFFileNames fileNames;
+  private final ReefRunnableProcessObserver processObserver;
+
+  @Inject
+  ContainerManager(
+      final RemoteManager remoteManager,
+      final RuntimeClock clock,
+      final REEFFileNames fileNames,
+      final @Parameter(NumberOfProcesses.class) int capacity,
+      final @Parameter(RootFolder.class) String rootFolderName,
+      final @Parameter(RuntimeParameters.NodeDescriptorHandler.class)
+      EventHandler<DriverRuntimeProtocol.NodeDescriptorProto> nodeDescriptorHandler,
+      final ReefRunnableProcessObserver processObserver) {
+
+    this.capacity = capacity;
+    this.fileNames = fileNames;
+    this.processObserver = processObserver;
+    this.errorHandlerRID = remoteManager.getMyIdentifier();
+    this.nodeDescriptorHandler = nodeDescriptorHandler;
+    this.rootFolder = new File(rootFolderName);
+
+    LOG.log(Level.FINEST, "Initializing Container Manager with {0} containers", capacity);
+
+    remoteManager.registerHandler(ReefServiceProtos.RuntimeErrorProto.class, new EventHandler<RemoteMessage<ReefServiceProtos.RuntimeErrorProto>>() {
+      @Override
+      public void onNext(final RemoteMessage<ReefServiceProtos.RuntimeErrorProto> value) {
+        final FailedRuntime error = new FailedRuntime(value.getMessage());
+        LOG.log(Level.SEVERE, "FailedRuntime: " + error, error.getReason().orElse(null));
+        release(error.getId());
+      }
+    });
+    clock.registerEventHandler(RuntimeStart.class, new EventHandler<Time>() {
+      @Override
+      public void onNext(final Time value) {
+        synchronized (ContainerManager.this) {
+          ContainerManager.this.sendNodeDescriptors();
+        }
+      }
+    });
+
+    clock.registerEventHandler(RuntimeStop.class, new EventHandler<Time>() {
+      @Override
+      public void onNext(final Time value) {
+        synchronized (ContainerManager.this) {
+          LOG.log(Level.FINEST, "RuntimeStop: close the container manager");
+          ContainerManager.this.close();
+        }
+      }
+    });
+
+    LOG.log(Level.FINE, "Initialized Container Manager with {0} containers", capacity);
+  }
+
+  private void sendNodeDescriptors() {
+    final IDMaker idmaker = new IDMaker("Node-");
+    for (int i = 0; i < capacity; i++) {
+      final String id = idmaker.getNextID();
+      this.freeNodeList.add(id);
+      nodeDescriptorHandler.onNext(DriverRuntimeProtocol.NodeDescriptorProto.newBuilder()
+          .setIdentifier(id)
+          .setRackName("/default-rack")
+          .setHostName(NetUtils.getLocalAddress())
+          .setPort(i)
+          .setMemorySize(512) // TODO: Find the actual system memory on this machine.
+          .build());
+    }
+  }
+
+  final boolean hasContainerAvailable() {
+    return this.freeNodeList.size() > 0;
+  }
+
+  final Container allocateOne(final int megaBytes, final int numberOfCores) {
+    synchronized (this.containers) {
+      final String nodeId = this.freeNodeList.remove(0);
+      final String processID = nodeId + "-" + String.valueOf(System.currentTimeMillis());
+      final File processFolder = new File(this.rootFolder, processID);
+      processFolder.mkdirs();
+      final ProcessContainer container = new ProcessContainer(
+          this.errorHandlerRID, nodeId, processID, processFolder, megaBytes, numberOfCores, this.fileNames, this.processObserver);
+      this.containers.put(container.getContainerID(), container);
+      LOG.log(Level.FINE, "Allocated {0}", container.getContainerID());
+      return container;
+    }
+  }
+
+  final void release(final String containerID) {
+    synchronized (this.containers) {
+      final Container ctr = this.containers.get(containerID);
+      if (null != ctr) {
+        LOG.log(Level.INFO, "Releasing Container with containerId [{0}]", ctr);
+        if (ctr.isRunning()) {
+          ctr.close();
+        }
+        this.freeNodeList.add(ctr.getNodeID());
+        this.containers.remove(ctr.getContainerID());
+      } else {
+        LOG.log(Level.INFO, "Ignoring release request for unknown containerID [{0}]", containerID);
+      }
+    }
+  }
+
+  final Container get(final String containedID) {
+    synchronized (this.containers) {
+      return this.containers.get(containedID);
+    }
+  }
+
+  /**
+   * @return a List of the IDs of currently allocated Containers.
+   */
+  final Iterable<String> getAllocatedContainerIDs() {
+    return this.containers.keySet();
+  }
+
+  @Override
+  public void close() {
+    synchronized (this.containers) {
+      if (this.containers.isEmpty()) {
+        LOG.log(Level.FINEST, "Clean shutdown with no outstanding containers.");
+      } else {
+        LOG.log(Level.WARNING, "Dirty shutdown with outstanding containers.");
+        for (final Container c : this.containers.values()) {
+          LOG.log(Level.WARNING, "Force shutdown of: {0}", c);
+          c.close();
+        }
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/IDMaker.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/IDMaker.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/IDMaker.java
new file mode 100644
index 0000000..3bd1d09
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/IDMaker.java
@@ -0,0 +1,47 @@
+/**
+ * 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.reef.runtime.local.driver;
+
+
+/**
+ * Generates unique IDs.
+ */
+public final class IDMaker {
+
+  private final String prefix;
+  private int counter = 0;
+
+  /**
+   * The ids generated by getNextID are of the form "prefixNUMBER", where
+   * number is counted up.
+   *
+   * @param prefix a prefix to be used for the IDs generated.
+   */
+  public IDMaker(final String prefix) {
+    this.prefix = prefix;
+  }
+
+  /**
+   * @return the next ID
+   */
+  public final String getNextID() {
+    this.counter += 1;
+    return this.prefix + this.counter;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalDriverConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalDriverConfiguration.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalDriverConfiguration.java
new file mode 100644
index 0000000..c6a6206
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalDriverConfiguration.java
@@ -0,0 +1,81 @@
+/**
+ * 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.reef.runtime.local.driver;
+
+import org.apache.reef.runtime.common.files.RuntimeClasspathProvider;
+import org.apache.reef.runtime.common.parameters.JVMHeapSlack;
+import org.apache.reef.runtime.local.LocalClasspathProvider;
+import org.apache.reef.runtime.local.client.parameters.NumberOfProcesses;
+import org.apache.reef.runtime.local.client.parameters.RootFolder;
+import org.apache.reef.runtime.local.driver.parameters.GlobalFiles;
+import org.apache.reef.runtime.local.driver.parameters.GlobalLibraries;
+import org.apache.reef.runtime.local.driver.parameters.LocalFiles;
+import org.apache.reef.runtime.local.driver.parameters.LocalLibraries;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.OptionalParameter;
+import org.apache.reef.tang.formats.RequiredParameter;
+
+/**
+ * ConfigurationModule for the Driver executed in the local resourcemanager. This is meant to eventually replace
+ * LocalDriverRuntimeConfiguration.
+ */
+public class LocalDriverConfiguration extends ConfigurationModuleBuilder {
+
+  /**
+   * Files for the driver only.
+   */
+  public static final OptionalParameter<String> LOCAL_FILES = new OptionalParameter<>();
+  /**
+   * Libraries for the driver only.
+   */
+  public static final OptionalParameter<String> LOCAL_LIBRARIES = new OptionalParameter<>();
+  /**
+   * Files for the driver and all evaluators.
+   */
+  public static final OptionalParameter<String> GLOBAL_FILES = new OptionalParameter<>();
+  /**
+   * Libraries for the driver and all evaluators.
+   */
+  public static final OptionalParameter<String> GLOBAL_LIBRARIES = new OptionalParameter<>();
+  /**
+   * The maximum number or processes to spawn.
+   */
+  public static final RequiredParameter<Integer> NUMBER_OF_PROCESSES = new RequiredParameter<>();
+  /**
+   * The root folder of the job. Assumed to be an absolute path.
+   */
+  public static final RequiredParameter<String> ROOT_FOLDER = new RequiredParameter<>();
+  /**
+   * The fraction of the container memory NOT to use for the Java Heap.
+   */
+  public static final OptionalParameter<Double> JVM_HEAP_SLACK = new OptionalParameter<>();
+
+
+  public static final ConfigurationModule CONF = new LocalDriverConfiguration()
+      .bindSetEntry(LocalFiles.class, LOCAL_FILES)
+      .bindSetEntry(LocalLibraries.class, LOCAL_LIBRARIES)
+      .bindSetEntry(GlobalFiles.class, GLOBAL_FILES)
+      .bindSetEntry(GlobalLibraries.class, GLOBAL_LIBRARIES)
+      .bindNamedParameter(NumberOfProcesses.class, NUMBER_OF_PROCESSES)
+      .bindNamedParameter(RootFolder.class, ROOT_FOLDER)
+      .bindNamedParameter(JVMHeapSlack.class, JVM_HEAP_SLACK)
+      .bindImplementation(RuntimeClasspathProvider.class, LocalClasspathProvider.class)
+      .build();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalDriverRuntimeConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalDriverRuntimeConfiguration.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalDriverRuntimeConfiguration.java
new file mode 100644
index 0000000..52bd622
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalDriverRuntimeConfiguration.java
@@ -0,0 +1,30 @@
+/**
+ * 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.reef.runtime.local.driver;
+
+import org.apache.reef.runtime.common.driver.api.AbstractDriverRuntimeConfiguration;
+
+import javax.inject.Inject;
+
+public class LocalDriverRuntimeConfiguration extends AbstractDriverRuntimeConfiguration {
+  @Inject
+  public LocalDriverRuntimeConfiguration() {
+    super(LocalResourceLaunchHandler.class, LocalResourceReleaseHandler.class, LocalResourceRequestHandler.class);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalResourceLaunchHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalResourceLaunchHandler.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalResourceLaunchHandler.java
new file mode 100644
index 0000000..be3ead8
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalResourceLaunchHandler.java
@@ -0,0 +1,46 @@
+/**
+ * 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.reef.runtime.local.driver;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.api.ResourceLaunchHandler;
+
+import javax.inject.Inject;
+
+/**
+ * Takes resource launch events and patches them through to the ResourceManager.
+ */
+@Private
+@DriverSide
+final class LocalResourceLaunchHandler implements ResourceLaunchHandler {
+
+  private final ResourceManager resourceManager;
+
+  @Inject
+  public LocalResourceLaunchHandler(final ResourceManager resourceManager) {
+    this.resourceManager = resourceManager;
+  }
+
+  @Override
+  public void onNext(final DriverRuntimeProtocol.ResourceLaunchProto t) {
+    this.resourceManager.onResourceLaunchRequest(t);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalResourceReleaseHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalResourceReleaseHandler.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalResourceReleaseHandler.java
new file mode 100644
index 0000000..04c2730
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalResourceReleaseHandler.java
@@ -0,0 +1,47 @@
+/**
+ * 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.reef.runtime.local.driver;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.api.ResourceReleaseHandler;
+
+import javax.inject.Inject;
+
+/**
+ * Takes Resource Release requests and patches them through to the resource
+ * manager.
+ */
+@Private
+@DriverSide
+public final class LocalResourceReleaseHandler implements ResourceReleaseHandler {
+
+  private ResourceManager resourceManager;
+
+  @Inject
+  LocalResourceReleaseHandler(final ResourceManager resourceManager) {
+    this.resourceManager = resourceManager;
+  }
+
+  @Override
+  public void onNext(final DriverRuntimeProtocol.ResourceReleaseProto t) {
+    this.resourceManager.onResourceReleaseRequest(t);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalResourceRequestHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalResourceRequestHandler.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalResourceRequestHandler.java
new file mode 100644
index 0000000..a08b05c
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/LocalResourceRequestHandler.java
@@ -0,0 +1,46 @@
+/**
+ * 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.reef.runtime.local.driver;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.api.ResourceRequestHandler;
+
+import javax.inject.Inject;
+
+/**
+ * Takes resource requests and patches them through to the ResourceManager
+ */
+@Private
+@DriverSide
+final class LocalResourceRequestHandler implements ResourceRequestHandler {
+
+  private final ResourceManager resourceManager;
+
+  @Inject
+  LocalResourceRequestHandler(final ResourceManager resourceManager) {
+    this.resourceManager = resourceManager;
+  }
+
+  @Override
+  public void onNext(final DriverRuntimeProtocol.ResourceRequestProto t) {
+    this.resourceManager.onResourceRequest(t);
+  }
+}


[06/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/Client.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/Client.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/Client.java
new file mode 100644
index 0000000..cbad811
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/Client.java
@@ -0,0 +1,57 @@
+/**
+ * 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.reef.tests.fail.task;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.task.Task;
+import org.apache.reef.tests.TestDriverLauncher;
+import org.apache.reef.util.EnvironmentUtils;
+
+/**
+ * Client for the test REEF job that fails on different stages of execution.
+ */
+public final class Client {
+
+  public static LauncherStatus run(
+      final Class<? extends Task> failTaskClass,
+      final Configuration runtimeConfig,
+      final int timeOut) throws BindException, InjectionException {
+
+    final Configuration driverConfig = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(Driver.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, failTaskClass.getSimpleName())
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, Driver.AllocatedEvaluatorHandler.class)
+        .set(DriverConfiguration.ON_TASK_RUNNING, Driver.RunningTaskHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_ACTIVE, Driver.ActiveContextHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_STARTED, Driver.StartHandler.class)
+        .build();
+
+    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.addConfiguration(driverConfig);
+    cb.bindNamedParameter(Driver.FailTaskName.class, failTaskClass.getSimpleName());
+
+    return TestDriverLauncher.getLauncher(runtimeConfig).run(cb.build(), timeOut);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/Driver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/Driver.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/Driver.java
new file mode 100644
index 0000000..0d3ed1d
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/Driver.java
@@ -0,0 +1,169 @@
+/**
+ * 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.reef.tests.fail.task;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.driver.task.RunningTask;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+public final class Driver {
+
+  private static final Logger LOG = Logger.getLogger(Driver.class.getName());
+  private final transient String failTaskName;
+  private final transient EvaluatorRequestor requestor;
+  private transient String taskId;
+
+  @Inject
+  public Driver(final @Parameter(FailTaskName.class) String failTaskName,
+                final EvaluatorRequestor requestor) {
+    this.failTaskName = failTaskName;
+    this.requestor = requestor;
+  }
+
+  /**
+   * Name of the message class to specify the failing message handler.
+   */
+  @NamedParameter(doc = "Full name of the (failing) task class", short_name = "task")
+  public static final class FailTaskName implements Name<String> {
+  }
+
+  final class AllocatedEvaluatorHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator eval) {
+
+      try {
+
+        taskId = failTaskName + "_" + eval.getId();
+        LOG.log(Level.INFO, "Submit task: {0}", taskId);
+
+        final Configuration contextConfig =
+            ContextConfiguration.CONF.set(ContextConfiguration.IDENTIFIER, taskId).build();
+
+        ConfigurationModule taskConfig =
+            TaskConfiguration.CONF.set(TaskConfiguration.IDENTIFIER, taskId);
+
+        switch (failTaskName) {
+          case "FailTask":
+            taskConfig = taskConfig.set(TaskConfiguration.TASK, FailTask.class);
+            break;
+          case "FailTaskCall":
+            taskConfig = taskConfig.set(TaskConfiguration.TASK, FailTaskCall.class);
+            break;
+          case "FailTaskMsg":
+            taskConfig = taskConfig
+                .set(TaskConfiguration.TASK, FailTaskMsg.class)
+                .set(TaskConfiguration.ON_MESSAGE, FailTaskMsg.class);
+            break;
+          case "FailTaskSuspend":
+            taskConfig = taskConfig
+                .set(TaskConfiguration.TASK, FailTaskSuspend.class)
+                .set(TaskConfiguration.ON_SUSPEND, FailTaskSuspend.class);
+            break;
+          case "FailTaskStart":
+            taskConfig = taskConfig
+                .set(TaskConfiguration.TASK, FailTaskStart.class)
+                .set(TaskConfiguration.ON_TASK_STARTED, FailTaskStart.class);
+            break;
+          case "FailTaskStop":
+            taskConfig = taskConfig
+                .set(TaskConfiguration.TASK, FailTaskStop.class)
+                .set(TaskConfiguration.ON_TASK_STOP, FailTaskStop.class)
+                .set(TaskConfiguration.ON_CLOSE, FailTaskStop.CloseEventHandler.class);
+            break;
+          case "FailTaskClose":
+            taskConfig = taskConfig
+                .set(TaskConfiguration.TASK, FailTaskClose.class)
+                .set(TaskConfiguration.ON_CLOSE, FailTaskClose.class);
+            break;
+        }
+
+        eval.submitContextAndTask(contextConfig, taskConfig.build());
+
+      } catch (final BindException ex) {
+        LOG.log(Level.WARNING, "Configuration error", ex);
+        throw new DriverSideFailure("Configuration error", ex);
+      }
+    }
+  }
+
+  final class RunningTaskHandler implements EventHandler<RunningTask> {
+    @Override
+    public void onNext(final RunningTask task) {
+
+      LOG.log(Level.INFO, "TaskRuntime: {0} expect {1}",
+          new Object[]{task.getId(), taskId});
+
+      if (!taskId.equals(task.getId())) {
+        throw new DriverSideFailure("Task ID " + task.getId()
+            + " not equal expected ID " + taskId);
+      }
+
+      switch (failTaskName) {
+        case "FailTaskMsg":
+          LOG.log(Level.INFO, "TaskRuntime: Send message: {0}", task);
+          task.send(new byte[0]);
+          break;
+        case "FailTaskSuspend":
+          LOG.log(Level.INFO, "TaskRuntime: Suspend: {0}", task);
+          task.suspend();
+          break;
+        case "FailTaskStop":
+        case "FailTaskClose":
+          LOG.log(Level.INFO, "TaskRuntime: Stop/Close: {0}", task);
+          task.close();
+          break;
+      }
+    }
+  }
+
+  final class ActiveContextHandler implements EventHandler<ActiveContext> {
+    @Override
+    public void onNext(final ActiveContext context) throws DriverSideFailure {
+      throw new DriverSideFailure("Unexpected ActiveContext message: " + context.getId());
+    }
+  }
+
+  final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime time) {
+      LOG.log(Level.INFO, "StartTime: {0}", time);
+      Driver.this.requestor.submit(EvaluatorRequest.newBuilder()
+          .setNumber(1).setMemory(128).setNumberOfCores(1).build());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTask.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTask.java
new file mode 100644
index 0000000..ff8f905
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTask.java
@@ -0,0 +1,49 @@
+/**
+ * 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.reef.tests.fail.task;
+
+import org.apache.reef.task.Task;
+import org.apache.reef.tests.library.exceptions.SimulatedTaskFailure;
+import org.apache.reef.tests.library.exceptions.TaskSideFailure;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A basic task that just fails when we create it.
+ */
+public final class FailTask implements Task {
+
+  private static final Logger LOG = Logger.getLogger(FailTask.class.getName());
+
+  @Inject
+  public FailTask() throws SimulatedTaskFailure {
+    final SimulatedTaskFailure ex = new SimulatedTaskFailure("FailTask constructor called.");
+    LOG.log(Level.FINE, "FailTask created - failing now: {0}", ex);
+    throw ex;
+  }
+
+  @Override
+  public byte[] call(final byte[] memento) throws TaskSideFailure {
+    final RuntimeException ex = new TaskSideFailure("FailTask.call() should never be called.");
+    LOG.log(Level.SEVERE, "FailTask.call() invoked - that should never happen!", ex);
+    throw ex;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskCall.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskCall.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskCall.java
new file mode 100644
index 0000000..b923dd2
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskCall.java
@@ -0,0 +1,46 @@
+/**
+ * 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.reef.tests.fail.task;
+
+import org.apache.reef.task.Task;
+import org.apache.reef.tests.library.exceptions.SimulatedTaskFailure;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A basic task that just fails when we run it.
+ */
+public final class FailTaskCall implements Task {
+
+  private static final Logger LOG = Logger.getLogger(FailTaskCall.class.getName());
+
+  @Inject
+  public FailTaskCall() {
+    LOG.info("FailTaskCall created.");
+  }
+
+  @Override
+  public byte[] call(final byte[] memento) throws SimulatedTaskFailure {
+    final SimulatedTaskFailure ex = new SimulatedTaskFailure("FailTaskCall.call() invoked.");
+    LOG.log(Level.FINE, "FailTaskCall.call() invoked: {0}", ex);
+    throw ex;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskClose.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskClose.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskClose.java
new file mode 100644
index 0000000..b8d25e7
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskClose.java
@@ -0,0 +1,65 @@
+/**
+ * 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.reef.tests.fail.task;
+
+import org.apache.reef.task.Task;
+import org.apache.reef.task.events.CloseEvent;
+import org.apache.reef.tests.library.exceptions.SimulatedTaskFailure;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A basic task that just fails when we close it.
+ */
+public final class FailTaskClose implements Task, EventHandler<CloseEvent> {
+
+  private static final Logger LOG = Logger.getLogger(FailTaskClose.class.getName());
+
+  private transient boolean isRunning = true;
+
+  @Inject
+  public FailTaskClose() {
+    LOG.fine("FailTaskClose created.");
+  }
+
+  @Override
+  public byte[] call(final byte[] memento) {
+    synchronized (this) {
+      LOG.fine("FailTaskClose.call() invoked. Waiting for the message.");
+      while (this.isRunning) {
+        try {
+          this.wait();
+        } catch (final InterruptedException ex) {
+          LOG.log(Level.WARNING, "wait() interrupted.", ex);
+        }
+      }
+    }
+    return new byte[0];
+  }
+
+  @Override
+  public void onNext(final CloseEvent event) throws SimulatedTaskFailure {
+    final SimulatedTaskFailure ex = new SimulatedTaskFailure("FailTaskClose.send() invoked.");
+    LOG.log(Level.FINE, "FailTaskClose.onNext() invoked. Raise exception: {0}", ex.toString());
+    throw ex;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskMsg.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskMsg.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskMsg.java
new file mode 100644
index 0000000..34a9909
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskMsg.java
@@ -0,0 +1,65 @@
+/**
+ * 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.reef.tests.fail.task;
+
+import org.apache.reef.task.Task;
+import org.apache.reef.task.events.DriverMessage;
+import org.apache.reef.tests.library.exceptions.SimulatedTaskFailure;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A basic task that just fails when we send it a message.
+ */
+public final class FailTaskMsg implements Task, EventHandler<DriverMessage> {
+
+  private static final Logger LOG = Logger.getLogger(FailTaskMsg.class.getName());
+  private transient boolean isRunning = true;
+
+  @Inject
+  public FailTaskMsg() {
+    LOG.info("FailTaskMsg created.");
+  }
+
+  @Override
+  public byte[] call(final byte[] memento) {
+    synchronized (this) {
+      LOG.info("FailTaskMsg.call() invoked. Waiting for the message.");
+      while (this.isRunning) {
+        try {
+          this.wait();
+        } catch (final InterruptedException ex) {
+          LOG.log(Level.WARNING, "wait() interrupted.", ex);
+        }
+      }
+    }
+    return new byte[0];
+  }
+
+  @Override
+  public void onNext(final DriverMessage driverMessage) throws SimulatedTaskFailure {
+    final SimulatedTaskFailure ex = new SimulatedTaskFailure("FailTaskMsg.send() invoked.");
+    LOG.log(Level.FINE, "FailTaskMsg.send() invoked: {0}", ex);
+    throw ex;
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskStart.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskStart.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskStart.java
new file mode 100644
index 0000000..9913f2e
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskStart.java
@@ -0,0 +1,65 @@
+/**
+ * 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.reef.tests.fail.task;
+
+import org.apache.reef.task.Task;
+import org.apache.reef.task.events.TaskStart;
+import org.apache.reef.tests.library.exceptions.SimulatedTaskFailure;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A basic task that just fails when we invoke it.
+ */
+public final class FailTaskStart implements Task, EventHandler<TaskStart> {
+
+  private static final Logger LOG = Logger.getLogger(FailTaskStart.class.getName());
+
+  private transient boolean isRunning = true;
+
+  @Inject
+  public FailTaskStart() {
+    LOG.info("FailTaskStart created.");
+  }
+
+  @Override
+  public byte[] call(final byte[] memento) {
+    synchronized (this) {
+      LOG.info("FailTaskStart.call() invoked. Waiting for the message.");
+      while (this.isRunning) {
+        try {
+          this.wait();
+        } catch (final InterruptedException ex) {
+          LOG.log(Level.WARNING, "wait() interrupted.", ex);
+        }
+      }
+    }
+    return new byte[0];
+  }
+
+  @Override
+  public void onNext(final TaskStart event) throws SimulatedTaskFailure {
+    final SimulatedTaskFailure ex = new SimulatedTaskFailure("FailTaskStart.send() invoked.");
+    LOG.log(Level.FINE, "FailTaskStart.onNext() invoked: {0}", ex);
+    throw ex;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskStop.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskStop.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskStop.java
new file mode 100644
index 0000000..2398db0
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskStop.java
@@ -0,0 +1,79 @@
+/**
+ * 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.reef.tests.fail.task;
+
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.task.Task;
+import org.apache.reef.task.events.CloseEvent;
+import org.apache.reef.task.events.TaskStop;
+import org.apache.reef.tests.library.exceptions.SimulatedTaskFailure;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A basic task that just fails when we stop it.
+ */
+@Unit
+public final class FailTaskStop implements Task, EventHandler<TaskStop> {
+
+  private static final Logger LOG = Logger.getLogger(FailTaskStop.class.getName());
+
+  private transient boolean isRunning = true;
+
+  @Inject
+  public FailTaskStop() {
+    LOG.fine("FailTaskStop created.");
+  }
+
+  @Override
+  public byte[] call(final byte[] memento) {
+    synchronized (this) {
+      LOG.fine("FailTaskStop.call() invoked. Waiting for the message.");
+      while (this.isRunning) {
+        try {
+          this.wait();
+        } catch (final InterruptedException ex) {
+          LOG.log(Level.WARNING, "wait() interrupted.", ex);
+        }
+      }
+    }
+    return null;
+  }
+
+  @Override
+  public void onNext(final TaskStop event) throws SimulatedTaskFailure {
+    final SimulatedTaskFailure ex = new SimulatedTaskFailure("FailTaskStop.send() invoked.");
+    LOG.log(Level.FINE, "FailTaskStop.onNext() invoked. Raise exception: {0}", ex.toString());
+    throw ex;
+  }
+
+  public final class CloseEventHandler implements EventHandler<CloseEvent> {
+    @Override
+    public void onNext(final CloseEvent event) {
+      LOG.log(Level.FINEST, "FailTaskStop.CloseEventHandler.onNext() invoked: {0}", event);
+      synchronized (FailTaskStop.this) {
+        isRunning = false;
+        FailTaskStop.this.notify();
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskSuspend.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskSuspend.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskSuspend.java
new file mode 100644
index 0000000..08fcfaf
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/task/FailTaskSuspend.java
@@ -0,0 +1,69 @@
+/**
+ * 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.reef.tests.fail.task;
+
+import org.apache.reef.task.Task;
+import org.apache.reef.task.events.SuspendEvent;
+import org.apache.reef.tests.library.exceptions.SimulatedTaskFailure;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A basic task that just fails when we invoke it.
+ */
+public final class FailTaskSuspend implements Task, EventHandler<SuspendEvent> {
+
+  private static final Logger LOG = Logger.getLogger(FailTaskSuspend.class.getName());
+
+  private transient boolean isRunning = true;
+
+  @Inject
+  public FailTaskSuspend() {
+    LOG.info("FailTaskSuspend created.");
+  }
+
+  @Override
+  public byte[] call(final byte[] memento) {
+    synchronized (this) {
+      LOG.info("FailTaskSuspend.call() invoked. Waiting for suspend request.");
+      while (this.isRunning) {
+        try {
+          this.wait();
+        } catch (final InterruptedException ex) {
+          LOG.log(Level.WARNING, "wait() interrupted.", ex);
+        }
+      }
+    }
+    return new byte[0];
+  }
+
+  @Override
+  public void onNext(final SuspendEvent event) throws SimulatedTaskFailure {
+    // synchronized (this) {
+    //   this.isRunning = false;
+    //   this.notify();
+    // }
+    final SimulatedTaskFailure ex = new SimulatedTaskFailure("FailTaskSuspend.send() invoked.");
+    LOG.log(Level.FINE, "FailTaskSuspend.send() invoked: {0}", ex);
+    throw ex;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/driver/ExpectedTaskFailureHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/driver/ExpectedTaskFailureHandler.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/driver/ExpectedTaskFailureHandler.java
new file mode 100644
index 0000000..b035a09
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/driver/ExpectedTaskFailureHandler.java
@@ -0,0 +1,59 @@
+/**
+ * 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.reef.tests.library.driver;
+
+import org.apache.reef.driver.task.FailedTask;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.tests.library.exceptions.ExpectedTaskException;
+import org.apache.reef.util.Exceptions;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+
+/**
+ * A handler for FailedTask that will throw a DriverSideFailure unless the FailedTask was triggered by an
+ * ExpectedTaskException in the Task.
+ */
+public final class ExpectedTaskFailureHandler implements EventHandler<FailedTask> {
+
+  @Inject
+  public ExpectedTaskFailureHandler() {
+  }
+
+  /**
+   * Checks whether the FailedTask was caused by a ExpectedTaskException.
+   *
+   * @param failedTask
+   * @throws org.apache.reef.tests.library.exceptions.DriverSideFailure if the FailedTask wasn't triggered by a
+   *                                                                    ExpectedTaskException
+   */
+
+  @Override
+  public void onNext(final FailedTask failedTask) {
+    final Optional<Throwable> reasonOptional = failedTask.getReason();
+    if (!reasonOptional.isPresent()) {
+      throw new DriverSideFailure("Received a FailedTask, but it did not contain an exception.");
+    } else if (!(Exceptions.getUltimateCause(reasonOptional.get()) instanceof ExpectedTaskException)) {
+      throw new DriverSideFailure("Received a FailedTask, but the ExpectedTaskException isn't the ultimate cause.",
+          reasonOptional.get());
+    }
+    failedTask.getActiveContext().get().close();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/driver/OnDriverStartedAllocateOne.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/driver/OnDriverStartedAllocateOne.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/driver/OnDriverStartedAllocateOne.java
new file mode 100644
index 0000000..4a74c04
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/driver/OnDriverStartedAllocateOne.java
@@ -0,0 +1,48 @@
+/**
+ * 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.reef.tests.library.driver;
+
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+
+/**
+ * A Driver start handler that requests a single Evaluator of size 64MB.
+ */
+public final class OnDriverStartedAllocateOne implements EventHandler<StartTime> {
+
+  private final EvaluatorRequestor requestor;
+
+  @Inject
+  OnDriverStartedAllocateOne(EvaluatorRequestor requestor) {
+    this.requestor = requestor;
+  }
+
+  @Override
+  public void onNext(final StartTime startTime) {
+    this.requestor.submit(EvaluatorRequest.newBuilder()
+        .setMemory(64)
+        .setNumber(1)
+        .setNumberOfCores(1)
+        .build());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/ClientSideFailure.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/ClientSideFailure.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/ClientSideFailure.java
new file mode 100644
index 0000000..cfa5bb9
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/ClientSideFailure.java
@@ -0,0 +1,40 @@
+/**
+ * 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.reef.tests.library.exceptions;
+
+/**
+ * Thrown when a test fails on the client side.
+ */
+public class ClientSideFailure extends RuntimeException {
+
+  public ClientSideFailure() {
+  }
+
+  public ClientSideFailure(final String string) {
+    super(string);
+  }
+
+  public ClientSideFailure(final String string, final Throwable thrwbl) {
+    super(string, thrwbl);
+  }
+
+  public ClientSideFailure(final Throwable thrwbl) {
+    super(thrwbl);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/DriverSideFailure.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/DriverSideFailure.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/DriverSideFailure.java
new file mode 100644
index 0000000..0d65d7e
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/DriverSideFailure.java
@@ -0,0 +1,42 @@
+/**
+ * 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.reef.tests.library.exceptions;
+
+/**
+ * Thrown when a test fails on the driver side.
+ */
+public class DriverSideFailure extends RuntimeException {
+
+  public DriverSideFailure() {
+  }
+
+  public DriverSideFailure(final String message) {
+    super(message);
+  }
+
+  public DriverSideFailure(final String message, final Throwable cause) {
+    super(message, cause);
+  }
+
+  public DriverSideFailure(final Throwable cause) {
+    super(cause);
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/ExpectedTaskException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/ExpectedTaskException.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/ExpectedTaskException.java
new file mode 100644
index 0000000..0c64e1a
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/ExpectedTaskException.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.tests.library.exceptions;
+
+/**
+ * Expected Exception thrown by a Task.
+ */
+public final class ExpectedTaskException extends RuntimeException {
+  public ExpectedTaskException() {
+  }
+
+  public ExpectedTaskException(String s) {
+    super(s);
+  }
+
+  public ExpectedTaskException(String s, Throwable throwable) {
+    super(s, throwable);
+  }
+
+  public ExpectedTaskException(Throwable throwable) {
+    super(throwable);
+  }
+
+  public ExpectedTaskException(String s, Throwable throwable, boolean b, boolean b2) {
+    super(s, throwable, b, b2);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/SimulatedDriverFailure.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/SimulatedDriverFailure.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/SimulatedDriverFailure.java
new file mode 100644
index 0000000..7033853
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/SimulatedDriverFailure.java
@@ -0,0 +1,41 @@
+/**
+ * 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.reef.tests.library.exceptions;
+
+/**
+ * Thrown when a test fails on the task side.
+ */
+public class SimulatedDriverFailure extends RuntimeException {
+
+  public SimulatedDriverFailure() {
+    super();
+  }
+
+  public SimulatedDriverFailure(final String message) {
+    super(message);
+  }
+
+  public SimulatedDriverFailure(final String message, final Throwable cause) {
+    super(message, cause);
+  }
+
+  public SimulatedDriverFailure(final Throwable cause) {
+    super(cause);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/SimulatedTaskFailure.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/SimulatedTaskFailure.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/SimulatedTaskFailure.java
new file mode 100644
index 0000000..1ced6a4
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/SimulatedTaskFailure.java
@@ -0,0 +1,41 @@
+/**
+ * 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.reef.tests.library.exceptions;
+
+/**
+ * Thrown when a test fails on the task side.
+ */
+public class SimulatedTaskFailure extends RuntimeException {
+
+  public SimulatedTaskFailure() {
+    super();
+  }
+
+  public SimulatedTaskFailure(final String message) {
+    super(message);
+  }
+
+  public SimulatedTaskFailure(final String message, final Throwable cause) {
+    super(message, cause);
+  }
+
+  public SimulatedTaskFailure(final Throwable cause) {
+    super(cause);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/TaskSideFailure.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/TaskSideFailure.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/TaskSideFailure.java
new file mode 100644
index 0000000..3fe0623
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/TaskSideFailure.java
@@ -0,0 +1,41 @@
+/**
+ * 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.reef.tests.library.exceptions;
+
+/**
+ * Thrown when a test fails on the task side.
+ */
+public class TaskSideFailure extends RuntimeException {
+
+  public TaskSideFailure() {
+    super();
+  }
+
+  public TaskSideFailure(final String message) {
+    super(message);
+  }
+
+  public TaskSideFailure(final String message, final Throwable cause) {
+    super(message, cause);
+  }
+
+  public TaskSideFailure(final Throwable cause) {
+    super(cause);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/UnexpectedTaskReturnValue.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/UnexpectedTaskReturnValue.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/UnexpectedTaskReturnValue.java
new file mode 100644
index 0000000..ef6318b
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/exceptions/UnexpectedTaskReturnValue.java
@@ -0,0 +1,40 @@
+/**
+ * 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.reef.tests.library.exceptions;
+
+/**
+ * Thrown by the Driver in a test if a Task returned an unexpected value.
+ */
+public final class UnexpectedTaskReturnValue extends RuntimeException {
+  private final String expected;
+  private final String actual;
+
+  public UnexpectedTaskReturnValue(final String expected, final String actual) {
+    this.expected = expected;
+    this.actual = actual;
+  }
+
+  @Override
+  public String toString() {
+    return "UnexpectedTaskReturnValue{" +
+        "expected='" + expected + '\'' +
+        ", actual='" + actual + '\'' +
+        '}';
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/package-info.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/package-info.java
new file mode 100644
index 0000000..df3a0e3
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Commonly used event handlers and task implementations in our tests
+ */
+package org.apache.reef.tests.library;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/tasks/EchoTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/tasks/EchoTask.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/tasks/EchoTask.java
new file mode 100644
index 0000000..e42076a
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/tasks/EchoTask.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.tests.library.tasks;
+
+import org.apache.reef.task.Task;
+
+import javax.inject.Inject;
+
+/**
+ * A Task that just sends the memento back.
+ */
+public final class EchoTask implements Task {
+
+  @Inject
+  private EchoTask() {
+  }
+
+  @Override
+  public byte[] call(byte[] memento) throws Exception {
+    return memento;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/tasks/NoopTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/tasks/NoopTask.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/tasks/NoopTask.java
new file mode 100644
index 0000000..c5186d4
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/library/tasks/NoopTask.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.tests.library.tasks;
+
+import org.apache.reef.task.Task;
+
+import javax.inject.Inject;
+
+/**
+ * A Task that does nothing and returns null.
+ */
+public class NoopTask implements Task {
+
+  @Inject
+  private NoopTask() {
+  }
+
+  @Override
+  public byte[] call(byte[] memento) throws Exception {
+    return null;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/messaging/driver/DriverMessaging.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/messaging/driver/DriverMessaging.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/messaging/driver/DriverMessaging.java
new file mode 100644
index 0000000..c8cdacc
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/messaging/driver/DriverMessaging.java
@@ -0,0 +1,173 @@
+/**
+ * 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.reef.tests.messaging.driver;
+
+import org.apache.reef.client.*;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.util.EnvironmentUtils;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+public final class DriverMessaging {
+
+  private static final Logger LOG = Logger.getLogger(DriverMessaging.class.getName());
+
+  private final REEF reef;
+
+  private String lastMessage = null;
+  private Optional<RunningJob> theJob = Optional.empty();
+  private LauncherStatus status = LauncherStatus.INIT;
+
+  @Inject
+  private DriverMessaging(final REEF reef) {
+    this.reef = reef;
+  }
+
+  public static LauncherStatus run(final Configuration runtimeConfiguration,
+                                   final int launcherTimeout) throws BindException, InjectionException {
+
+    final Configuration clientConfiguration = ClientConfiguration.CONF
+        .set(ClientConfiguration.ON_JOB_RUNNING, DriverMessaging.RunningJobHandler.class)
+        .set(ClientConfiguration.ON_JOB_MESSAGE, DriverMessaging.JobMessageHandler.class)
+        .set(ClientConfiguration.ON_JOB_COMPLETED, DriverMessaging.CompletedJobHandler.class)
+        .set(ClientConfiguration.ON_JOB_FAILED, DriverMessaging.FailedJobHandler.class)
+        .set(ClientConfiguration.ON_RUNTIME_ERROR, DriverMessaging.RuntimeErrorHandler.class)
+        .build();
+
+    return Tang.Factory.getTang()
+        .newInjector(runtimeConfiguration, clientConfiguration)
+        .getInstance(DriverMessaging.class).run(launcherTimeout, 1000);
+  }
+
+  public synchronized void close() {
+    if (this.status.isRunning()) {
+      this.status = LauncherStatus.FORCE_CLOSED;
+    }
+    if (this.theJob.isPresent()) {
+      this.theJob.get().close();
+    }
+    this.notify();
+  }
+
+  private LauncherStatus run(final long jobTimeout, final long statusTimeout) {
+
+    final long startTime = System.currentTimeMillis();
+    LOG.log(Level.INFO, "Submitting REEF Job");
+
+    final Configuration driverConfig = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(this.getClass()))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "DriverMessagingTest")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, DriverMessagingDriver.StartHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, DriverMessagingDriver.AllocatedEvaluatorHandler.class)
+        .set(DriverConfiguration.ON_CLIENT_MESSAGE, DriverMessagingDriver.ClientMessageHandler.class)
+        .build();
+
+
+    this.reef.submit(driverConfig);
+
+    synchronized (this) {
+      while (!this.status.isDone()) {
+        LOG.log(Level.INFO, "Waiting for REEF job to finish.");
+        try {
+          this.wait(statusTimeout);
+        } catch (final InterruptedException ex) {
+          LOG.log(Level.FINER, "Waiting for REEF job interrupted.", ex);
+        }
+        if (System.currentTimeMillis() - startTime >= jobTimeout) {
+          LOG.log(Level.INFO, "Waiting for REEF job timed out after {0} sec.",
+              (System.currentTimeMillis() - startTime) / 1000);
+          break;
+        }
+      }
+    }
+
+    this.reef.close();
+    return this.status;
+  }
+
+  final class JobMessageHandler implements EventHandler<JobMessage> {
+    @Override
+    public void onNext(final JobMessage message) {
+      final String msg = new String(message.get());
+      synchronized (DriverMessaging.this) {
+        if (!msg.equals(DriverMessaging.this.lastMessage)) {
+          LOG.log(Level.SEVERE, "Expected {0} but got {1}",
+              new Object[]{DriverMessaging.this.lastMessage, msg});
+          DriverMessaging.this.status = LauncherStatus.FAILED;
+          DriverMessaging.this.notify();
+        }
+      }
+    }
+  }
+
+  final class RunningJobHandler implements EventHandler<RunningJob> {
+    @Override
+    public void onNext(final RunningJob job) {
+      LOG.log(Level.INFO, "The Job {0} is running", job.getId());
+      synchronized (DriverMessaging.this) {
+        DriverMessaging.this.status = LauncherStatus.RUNNING;
+        DriverMessaging.this.theJob = Optional.of(job);
+        DriverMessaging.this.lastMessage = "Hello, REEF!";
+        DriverMessaging.this.theJob.get().send(DriverMessaging.this.lastMessage.getBytes());
+      }
+    }
+  }
+
+  final class CompletedJobHandler implements EventHandler<CompletedJob> {
+    @Override
+    public void onNext(final CompletedJob job) {
+      LOG.log(Level.INFO, "Job Completed: {0}", job);
+      synchronized (DriverMessaging.this) {
+        DriverMessaging.this.status = LauncherStatus.COMPLETED;
+        DriverMessaging.this.notify();
+      }
+    }
+  }
+
+  final class FailedJobHandler implements EventHandler<FailedJob> {
+    @Override
+    public void onNext(final FailedJob job) {
+      LOG.log(Level.SEVERE, "Received an error for job " + job.getId(), job.getReason().orElse(null));
+      synchronized (DriverMessaging.this) {
+        DriverMessaging.this.status = LauncherStatus.FAILED(job.getReason());
+        DriverMessaging.this.notify();
+      }
+    }
+  }
+
+  final class RuntimeErrorHandler implements EventHandler<FailedRuntime> {
+    @Override
+    public void onNext(final FailedRuntime error) {
+      LOG.log(Level.SEVERE, "Received a runtime error: " + error, error.getReason().orElse(null));
+      synchronized (DriverMessaging.this) {
+        DriverMessaging.this.status = LauncherStatus.FAILED(error.getReason());
+        DriverMessaging.this.notify();
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/messaging/driver/DriverMessagingDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/messaging/driver/DriverMessagingDriver.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/messaging/driver/DriverMessagingDriver.java
new file mode 100644
index 0000000..ac31c31
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/messaging/driver/DriverMessagingDriver.java
@@ -0,0 +1,87 @@
+/**
+ * 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.reef.tests.messaging.driver;
+
+import org.apache.reef.driver.client.JobMessageObserver;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.event.Alarm;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Dummy implementation of a driver.
+ */
+@Unit
+final class DriverMessagingDriver {
+
+  private static final Logger LOG = Logger.getLogger(DriverMessagingDriver.class.getName());
+
+  private static final int DELAY = 2000; // 2 sec.
+
+  private final Clock clock;
+  private final JobMessageObserver client;
+
+  @Inject
+  DriverMessagingDriver(final Clock clock, final JobMessageObserver client) {
+    this.clock = clock;
+    this.client = client;
+  }
+
+  final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime startTime) {
+      // Schedule an alarm to not go idle immediately
+      clock.scheduleAlarm(DELAY, new EventHandler<Alarm>() {
+        @Override
+        public void onNext(final Alarm alarm) {
+        }
+      });
+    }
+  }
+
+  /**
+   * Sends the message back to the client and schedules an alarm in 500ms
+   * such that the Driver does not immediately go idle.
+   */
+  final class ClientMessageHandler implements EventHandler<byte[]> {
+    @Override
+    public void onNext(final byte[] message) {
+      LOG.log(Level.INFO, "Message received: {0}", String.valueOf(message));
+      client.sendMessageToClient(message);
+      clock.scheduleAlarm(DELAY, new EventHandler<Alarm>() {
+        @Override
+        public void onNext(final Alarm alarm) {
+        }
+      });
+    }
+  }
+
+  final class AllocatedEvaluatorHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator eval) {
+      throw new RuntimeException("This should never be called");
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/messaging/task/TaskMessagingDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/messaging/task/TaskMessagingDriver.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/messaging/task/TaskMessagingDriver.java
new file mode 100644
index 0000000..657c5a3
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/messaging/task/TaskMessagingDriver.java
@@ -0,0 +1,98 @@
+/**
+ * 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.reef.tests.messaging.task;
+
+import org.apache.reef.driver.client.JobMessageObserver;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.task.RunningTask;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.driver.task.TaskMessage;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.event.Alarm;
+
+import javax.inject.Inject;
+import java.util.Arrays;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+public final class TaskMessagingDriver {
+
+  private static final Logger LOG = Logger.getLogger(TaskMessagingDriver.class.getName());
+  private static final ObjectSerializableCodec<String> CODEC = new ObjectSerializableCodec<>();
+  private static final byte[] HELLO_STR = CODEC.encode("MESSAGE::HELLO");
+  private static final int DELAY = 1000; // send message to Task 1 sec. after TaskRuntime
+
+  private final transient JobMessageObserver client;
+  private final transient Clock clock;
+
+  @Inject
+  public TaskMessagingDriver(final JobMessageObserver client, final Clock clock) {
+    this.client = client;
+    this.clock = clock;
+  }
+
+  public final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+
+    @Override
+    public void onNext(final AllocatedEvaluator eval) {
+      final String taskId = "Task_" + eval.getId();
+      LOG.log(Level.INFO, "Submit task: {0}", taskId);
+
+      final Configuration taskConfig = TaskConfiguration.CONF
+          .set(TaskConfiguration.IDENTIFIER, taskId)
+          .set(TaskConfiguration.TASK, TaskMessagingTask.class)
+          .set(TaskConfiguration.ON_MESSAGE, TaskMessagingTask.DriverMessageHandler.class)
+          .set(TaskConfiguration.ON_SEND_MESSAGE, TaskMessagingTask.class)
+          .build();
+      eval.submitTask(taskConfig);
+    }
+  }
+
+  public final class TaskRunningHandler implements EventHandler<RunningTask> {
+    @Override
+    public void onNext(final RunningTask task) {
+      LOG.log(Level.FINE, "TaskRuntime: {0}", task.getId());
+      clock.scheduleAlarm(DELAY, new EventHandler<Alarm>() {
+        @Override
+        public void onNext(final Alarm alarm) {
+          task.send(HELLO_STR);
+        }
+      });
+    }
+  }
+
+  public final class TaskMessageHandler implements EventHandler<TaskMessage> {
+    @Override
+    public void onNext(final TaskMessage msg) {
+      LOG.log(Level.FINE, "TaskMessage: from {0}: {1}",
+          new Object[]{msg.getId(), CODEC.decode(msg.get())});
+      if (!Arrays.equals(msg.get(), HELLO_STR)) {
+        final RuntimeException ex = new DriverSideFailure("Unexpected message: " + CODEC.decode(msg.get()));
+        LOG.log(Level.SEVERE, "Bad message from " + msg.getId(), ex);
+        throw ex;
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/messaging/task/TaskMessagingTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/messaging/task/TaskMessagingTask.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/messaging/task/TaskMessagingTask.java
new file mode 100644
index 0000000..4c60c56
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/messaging/task/TaskMessagingTask.java
@@ -0,0 +1,83 @@
+/**
+ * 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.reef.tests.messaging.task;
+
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.task.Task;
+import org.apache.reef.task.TaskMessage;
+import org.apache.reef.task.TaskMessageSource;
+import org.apache.reef.task.events.DriverMessage;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A basic task that receives a message and sends it back to the driver.
+ */
+@Unit
+public final class TaskMessagingTask implements Task, TaskMessageSource {
+
+  private static final Logger LOG = Logger.getLogger(TaskMessagingTask.class.getName());
+  private static final ObjectSerializableCodec<String> CODEC = new ObjectSerializableCodec<>();
+  private static final TaskMessage INIT_MESSAGE = TaskMessage.from("", CODEC.encode("MESSAGE::INIT"));
+  private transient boolean isRunning = true;
+  private transient Optional<TaskMessage> message = Optional.empty();
+
+  @Inject
+  public TaskMessagingTask() {
+    LOG.info("TaskMsg created.");
+  }
+
+  @Override
+  public synchronized byte[] call(final byte[] memento) {
+    LOG.info("TaskMsg.call() invoked. Waiting for the message.");
+    while (this.isRunning) {
+      try {
+        this.wait();
+      } catch (final InterruptedException ex) {
+        LOG.log(Level.WARNING, "wait() interrupted.", ex);
+      }
+    }
+    return this.message.orElse(INIT_MESSAGE).get();
+  }
+
+  @Override
+  public synchronized Optional<TaskMessage> getMessage() {
+    LOG.log(Level.INFO, "TaskMsg.getMessage() invoked: {0}",
+        CODEC.decode(this.message.orElse(INIT_MESSAGE).get()));
+    if (this.message.isPresent()) {
+      this.isRunning = false;
+      this.notify();
+    }
+    return this.message;
+  }
+
+  public class DriverMessageHandler implements EventHandler<DriverMessage> {
+    @Override
+    public void onNext(DriverMessage driverMessage) {
+      final byte[] message = driverMessage.get().get();
+      LOG.log(Level.INFO, "TaskMsg.send() invoked: {0}", CODEC.decode(message));
+      TaskMessagingTask.this.message = Optional.of(TaskMessage.from(this.toString(), message));
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/statepassing/Counter.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/statepassing/Counter.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/statepassing/Counter.java
new file mode 100644
index 0000000..e833e43
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/statepassing/Counter.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.tests.statepassing;
+
+import javax.inject.Inject;
+
+public class Counter {
+
+  private int value = 0;
+
+  @Inject
+  public Counter() {
+  }
+
+  public void increment() {
+    this.value += 1;
+  }
+
+  public int getValue() {
+    return value;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/statepassing/StatePassingDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/statepassing/StatePassingDriver.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/statepassing/StatePassingDriver.java
new file mode 100644
index 0000000..4b7bf39
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/statepassing/StatePassingDriver.java
@@ -0,0 +1,126 @@
+/**
+ * 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.reef.tests.statepassing;
+
+import org.apache.reef.driver.client.JobMessageObserver;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.context.ServiceConfiguration;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.task.CompletedTask;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+public class StatePassingDriver {
+
+  private static final Logger LOG = Logger.getLogger(StatePassingDriver.class.getName());
+
+  private static final int PASSES = 2;
+  private final JobMessageObserver client;
+  private int pass = 0;
+
+  @Inject
+  public StatePassingDriver(final JobMessageObserver client) {
+    this.client = client;
+  }
+
+  private static boolean allEqual(final byte value, final byte[] bytes) {
+    for (int i = 0; i < bytes.length; ++i) {
+      if (bytes[i] != value) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  private void nextPass(final ActiveContext activeContext) {
+    try {
+      activeContext.submitTask(TaskConfiguration.CONF
+          .set(TaskConfiguration.IDENTIFIER, "StatePassing-" + pass)
+          .set(TaskConfiguration.TASK, StatePassingTask.class)
+          .build());
+      ++pass;
+    } catch (final BindException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator eb) {
+      final JavaConfigurationBuilder b = Tang.Factory.getTang().newConfigurationBuilder();
+      try {
+        final Configuration contextConfiguration = ContextConfiguration.CONF
+            .set(ContextConfiguration.IDENTIFIER, "StatePassingContext")
+            .build();
+
+        final Configuration serviceConfiguration = ServiceConfiguration.CONF
+            .set(ServiceConfiguration.SERVICES, Counter.class)
+            .build();
+
+        eb.submitContextAndService(contextConfiguration, serviceConfiguration);
+      } catch (final BindException e) {
+        throw new RuntimeException(e);
+      }
+    }
+  }
+
+  final class ContextActiveHandler implements EventHandler<ActiveContext> {
+    @Override
+    public void onNext(final ActiveContext activeContext) {
+      nextPass(activeContext);
+    }
+  }
+
+  final class TaskCompletedHandler implements EventHandler<CompletedTask> {
+    @Override
+    public void onNext(final CompletedTask completed) {
+      LOG.log(Level.INFO, "Received a completed task: " + completed);
+      final byte[] message = completed.get();
+
+      if (message.length != pass) {
+        final String msg = "Expected message of length " + pass + ", but got message of length " + message.length;
+        final RuntimeException ex = new RuntimeException(msg);
+        throw ex;
+      }
+      if (!allEqual((byte) 1, message)) {
+        final RuntimeException ex = new RuntimeException("Did not get the right message");
+        throw ex;
+      }
+
+      if (pass < PASSES) {
+        LOG.log(Level.INFO, "Submitting the next Task");
+        nextPass(completed.getActiveContext());
+      } else {
+        LOG.log(Level.INFO, "Done");
+        completed.getActiveContext().close();
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/statepassing/StatePassingTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/statepassing/StatePassingTask.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/statepassing/StatePassingTask.java
new file mode 100644
index 0000000..d7176dc
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/statepassing/StatePassingTask.java
@@ -0,0 +1,50 @@
+/**
+ * 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.reef.tests.statepassing;
+
+
+import org.apache.reef.task.Task;
+
+import javax.inject.Inject;
+import java.util.Arrays;
+
+public class StatePassingTask implements Task {
+
+
+  private final Counter c;
+
+  @Inject
+  public StatePassingTask(final Counter c) {
+    this.c = c;
+  }
+
+
+  private static byte[] makeArray(final int size, final byte value) {
+    final byte[] result = new byte[size];
+    Arrays.fill(result, value);
+    return result;
+  }
+
+
+  @Override
+  public byte[] call(byte[] memento) throws Exception {
+    this.c.increment();
+    return makeArray(this.c.getValue(), (byte) 1);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/yarn/failure/FailureDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/yarn/failure/FailureDriver.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/yarn/failure/FailureDriver.java
new file mode 100644
index 0000000..1cc7abd
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/yarn/failure/FailureDriver.java
@@ -0,0 +1,109 @@
+/**
+ * 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.reef.tests.yarn.failure;
+
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.driver.evaluator.FailedEvaluator;
+import org.apache.reef.poison.PoisonedConfiguration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+public class FailureDriver {
+
+  private static final int NUM_EVALUATORS = 40;
+  private static final int NUM_FAILURES = 10;
+  private final AtomicInteger toSubmit = new AtomicInteger(NUM_FAILURES);
+  private static final Logger LOG = Logger.getLogger(FailureDriver.class.getName());
+  private final EvaluatorRequestor requestor;
+
+  @Inject
+  public FailureDriver(final EvaluatorRequestor requestor) {
+    this.requestor = requestor;
+    LOG.info("Driver instantiated");
+  }
+
+  /**
+   * Handles the StartTime event: Request as single Evaluator.
+   */
+  final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime startTime) {
+      LOG.log(Level.FINE, "Request {0} Evaluators.", NUM_EVALUATORS);
+      FailureDriver.this.requestor.submit(EvaluatorRequest.newBuilder()
+          .setNumber(NUM_EVALUATORS)
+          .setMemory(64)
+          .setNumberOfCores(1)
+          .build());
+    }
+  }
+
+  /**
+   * Handles AllocatedEvaluator: Submit a poisoned context.
+   */
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+      final String evalId = allocatedEvaluator.getId();
+      LOG.log(Level.FINE, "Got allocated evaluator: {0}", evalId);
+      if (toSubmit.getAndDecrement() > 0) {
+        LOG.log(Level.FINE, "Submitting poisoned context. {0} to go.", toSubmit);
+        allocatedEvaluator.submitContext(
+            Tang.Factory.getTang()
+                .newConfigurationBuilder(
+                    ContextConfiguration.CONF
+                        .set(ContextConfiguration.IDENTIFIER, "Poisoned Context: " + evalId)
+                        .build(),
+                    PoisonedConfiguration.CONTEXT_CONF
+                        .set(PoisonedConfiguration.CRASH_PROBABILITY, "1")
+                        .set(PoisonedConfiguration.CRASH_TIMEOUT, "1")
+                        .build())
+                .build());
+      } else {
+        LOG.log(Level.FINE, "Closing evaluator {0}", evalId);
+        allocatedEvaluator.close();
+      }
+    }
+  }
+
+  /**
+   * Handles FailedEvaluator: Resubmits the single Evaluator resource request.
+   */
+  final class EvaluatorFailedHandler implements EventHandler<FailedEvaluator> {
+    @Override
+    public void onNext(final FailedEvaluator failedEvaluator) {
+      LOG.log(Level.FINE, "Got failed evaluator: {0} - re-request", failedEvaluator.getId());
+      FailureDriver.this.requestor.submit(EvaluatorRequest.newBuilder()
+          .setNumber(1)
+          .setMemory(64)
+          .setNumberOfCores(1)
+          .build());
+    }
+  }
+}


[35/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/CloseEventImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/CloseEventImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/CloseEventImpl.java
new file mode 100644
index 0000000..5b502d1
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/CloseEventImpl.java
@@ -0,0 +1,45 @@
+/**
+ * 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.reef.runtime.common.evaluator.task;
+
+import org.apache.reef.task.events.CloseEvent;
+import org.apache.reef.util.Optional;
+
+final class CloseEventImpl implements CloseEvent {
+  private final Optional<byte[]> value;
+
+  CloseEventImpl() {
+    this.value = Optional.empty();
+  }
+
+  CloseEventImpl(final byte[] theBytes) {
+    this.value = Optional.ofNullable(theBytes);
+  }
+
+  @Override
+  public Optional<byte[]> get() {
+    return this.value;
+  }
+
+  @Override
+  public String toString() {
+    return "CloseEvent{value=" + this.value + '}';
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/DriverMessageImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/DriverMessageImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/DriverMessageImpl.java
new file mode 100644
index 0000000..d1a492e
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/DriverMessageImpl.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.runtime.common.evaluator.task;
+
+import org.apache.reef.task.events.DriverMessage;
+import org.apache.reef.util.Optional;
+
+final class DriverMessageImpl implements DriverMessage {
+  private final Optional<byte[]> value;
+
+  DriverMessageImpl() {
+    this.value = Optional.empty();
+  }
+
+  DriverMessageImpl(final byte[] theBytes) {
+    this.value = Optional.ofNullable(theBytes);
+  }
+
+  @Override
+  public Optional<byte[]> get() {
+    return this.value;
+  }
+
+  @Override
+  public String toString() {
+    return "DriverMessage{value=" + this.value + '}';
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/SuspendEventImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/SuspendEventImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/SuspendEventImpl.java
new file mode 100644
index 0000000..a1c0f0d
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/SuspendEventImpl.java
@@ -0,0 +1,45 @@
+/**
+ * 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.reef.runtime.common.evaluator.task;
+
+import org.apache.reef.task.events.SuspendEvent;
+import org.apache.reef.util.Optional;
+
+final class SuspendEventImpl implements SuspendEvent {
+  private final Optional<byte[]> value;
+
+  SuspendEventImpl() {
+    this.value = Optional.empty();
+  }
+
+  SuspendEventImpl(final byte[] theBytes) {
+    this.value = Optional.ofNullable(theBytes);
+  }
+
+  @Override
+  public Optional<byte[]> get() {
+    return this.value;
+  }
+
+  @Override
+  public String toString() {
+    return "SuspendEvent{value=" + this.value + '}';
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskClientCodeException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskClientCodeException.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskClientCodeException.java
new file mode 100644
index 0000000..1e0cc5e
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskClientCodeException.java
@@ -0,0 +1,77 @@
+/**
+ * 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.reef.runtime.common.evaluator.task;
+
+import org.apache.reef.driver.task.TaskConfigurationOptions;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.InjectionException;
+
+/**
+ * Thrown by REEF's resourcemanager code when it catches an exception thrown by user code.
+ */
+public final class TaskClientCodeException extends Exception {
+
+  private final String taskId;
+  private final String contextId;
+
+  /**
+   * @param taskId    the id of the failed task.
+   * @param contextId the ID of the context the failed Task was executing in.
+   * @param message   the error message.
+   * @param cause     the exception that caused the Task to fail.
+   */
+  public TaskClientCodeException(final String taskId,
+                                 final String contextId,
+                                 final String message,
+                                 final Throwable cause) {
+    super("Failure in task '" + taskId + "' in context '" + contextId + "': " + message, cause);
+    this.taskId = taskId;
+    this.contextId = contextId;
+  }
+
+  /**
+   * Extracts a task id from the given configuration.
+   *
+   * @param config
+   * @return the task id in the given configuration.
+   * @throws RuntimeException if the configuration can't be parsed.
+   */
+  public static String getTaskId(final Configuration config) {
+    try {
+      return Tang.Factory.getTang().newInjector(config).getNamedInstance(TaskConfigurationOptions.Identifier.class);
+    } catch (final InjectionException ex) {
+      throw new RuntimeException("Unable to determine task identifier. Giving up.", ex);
+    }
+  }
+
+  /**
+   * @return the ID of the failed Task.
+   */
+  public String getTaskId() {
+    return this.taskId;
+  }
+
+  /**
+   * @return the ID of the context the failed Task was executing in.
+   */
+  public String getContextId() {
+    return this.contextId;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskLifeCycleHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskLifeCycleHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskLifeCycleHandlers.java
new file mode 100644
index 0000000..f03ed13
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskLifeCycleHandlers.java
@@ -0,0 +1,90 @@
+/**
+ * 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.reef.runtime.common.evaluator.task;
+
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.task.TaskConfigurationOptions;
+import org.apache.reef.runtime.common.evaluator.task.exceptions.TaskStartHandlerFailure;
+import org.apache.reef.runtime.common.evaluator.task.exceptions.TaskStopHandlerFailure;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.task.events.TaskStart;
+import org.apache.reef.task.events.TaskStop;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Convenience class to send task start and stop events.
+ */
+@EvaluatorSide
+@Private
+final class TaskLifeCycleHandlers {
+  private static final Logger LOG = Logger.getLogger(TaskLifeCycleHandlers.class.getName());
+  private final Set<EventHandler<TaskStop>> taskStopHandlers;
+  private final Set<EventHandler<TaskStart>> taskStartHandlers;
+  private final TaskStart taskStart;
+  private final TaskStop taskStop;
+
+  @Inject
+  TaskLifeCycleHandlers(final @Parameter(TaskConfigurationOptions.StopHandlers.class) Set<EventHandler<TaskStop>> taskStopHandlers,
+                        final @Parameter(TaskConfigurationOptions.StartHandlers.class) Set<EventHandler<TaskStart>> taskStartHandlers,
+                        final TaskStartImpl taskStart,
+                        final TaskStopImpl taskStop) {
+    this.taskStopHandlers = taskStopHandlers;
+    this.taskStartHandlers = taskStartHandlers;
+    this.taskStart = taskStart;
+    this.taskStop = taskStop;
+  }
+
+  /**
+   * Sends the TaskStart event to the handlers for it.
+   */
+  public void beforeTaskStart() throws TaskStartHandlerFailure {
+    LOG.log(Level.FINEST, "Sending TaskStart event to the registered event handlers.");
+    for (final EventHandler<TaskStart> startHandler : this.taskStartHandlers) {
+      try {
+        startHandler.onNext(this.taskStart);
+      } catch (final Throwable throwable) {
+        throw new TaskStartHandlerFailure(startHandler, throwable);
+      }
+    }
+    LOG.log(Level.FINEST, "Done sending TaskStart event to the registered event handlers.");
+  }
+
+  /**
+   * Sends the TaskStop event to the handlers for it.
+   */
+  public void afterTaskExit() throws TaskStopHandlerFailure {
+    LOG.log(Level.FINEST, "Sending TaskStop event to the registered event handlers.");
+    for (final EventHandler<TaskStop> stopHandler : this.taskStopHandlers) {
+      try {
+        stopHandler.onNext(this.taskStop);
+      } catch (final Throwable throwable) {
+        throw new TaskStopHandlerFailure(stopHandler, throwable);
+      }
+    }
+    LOG.log(Level.FINEST, "Done sending TaskStop event to the registered event handlers.");
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskRuntime.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskRuntime.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskRuntime.java
new file mode 100644
index 0000000..ea8dd27
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskRuntime.java
@@ -0,0 +1,313 @@
+/**
+ * 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.reef.runtime.common.evaluator.task;
+
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.task.TaskConfigurationOptions;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.evaluator.HeartBeatManager;
+import org.apache.reef.runtime.common.evaluator.task.exceptions.*;
+import org.apache.reef.tang.InjectionFuture;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.task.Task;
+import org.apache.reef.task.events.CloseEvent;
+import org.apache.reef.task.events.DriverMessage;
+import org.apache.reef.task.events.SuspendEvent;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import javax.xml.bind.DatatypeConverter;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The execution environment for a Task.
+ */
+@Private
+@EvaluatorSide
+public final class TaskRuntime implements Runnable {
+
+  private final static Logger LOG = Logger.getLogger(TaskRuntime.class.getName());
+
+  /**
+   * User supplied Task code.
+   */
+  private final Task task;
+
+  private final InjectionFuture<EventHandler<CloseEvent>> f_closeHandler;
+  private final InjectionFuture<EventHandler<SuspendEvent>> f_suspendHandler;
+  private final InjectionFuture<EventHandler<DriverMessage>> f_messageHandler;
+  private final TaskLifeCycleHandlers taskLifeCycleHandlers;
+
+  /**
+   * The memento given by the task configuration.
+   */
+  private final Optional<byte[]> memento;
+
+  /**
+   * Heart beat manager to trigger on heartbeats.
+   */
+  private final HeartBeatManager heartBeatManager;
+
+  private final TaskStatus currentStatus;
+
+  // TODO: Document
+  @Inject
+  private TaskRuntime(
+      final HeartBeatManager heartBeatManager,
+      final Task task,
+      final TaskStatus currentStatus,
+      final @Parameter(TaskConfigurationOptions.CloseHandler.class) InjectionFuture<EventHandler<CloseEvent>> f_closeHandler,
+      final @Parameter(TaskConfigurationOptions.SuspendHandler.class) InjectionFuture<EventHandler<SuspendEvent>> f_suspendHandler,
+      final @Parameter(TaskConfigurationOptions.MessageHandler.class) InjectionFuture<EventHandler<DriverMessage>> f_messageHandler,
+      final TaskLifeCycleHandlers taskLifeCycleHandlers) {
+    this(heartBeatManager, task, currentStatus, f_closeHandler, f_suspendHandler, f_messageHandler, null, taskLifeCycleHandlers);
+  }
+
+  // TODO: Document
+  @Inject
+  private TaskRuntime(
+      final HeartBeatManager heartBeatManager,
+      final Task task,
+      final TaskStatus currentStatus,
+      final @Parameter(TaskConfigurationOptions.CloseHandler.class) InjectionFuture<EventHandler<CloseEvent>> f_closeHandler,
+      final @Parameter(TaskConfigurationOptions.SuspendHandler.class) InjectionFuture<EventHandler<SuspendEvent>> f_suspendHandler,
+      final @Parameter(TaskConfigurationOptions.MessageHandler.class) InjectionFuture<EventHandler<DriverMessage>> f_messageHandler,
+      final @Parameter(TaskConfigurationOptions.Memento.class) String memento,
+      final TaskLifeCycleHandlers taskLifeCycleHandlers) {
+
+    this.heartBeatManager = heartBeatManager;
+    this.task = task;
+    this.taskLifeCycleHandlers = taskLifeCycleHandlers;
+
+    this.memento = null == memento ? Optional.<byte[]>empty() :
+        Optional.of(DatatypeConverter.parseBase64Binary(memento));
+
+    this.f_closeHandler = f_closeHandler;
+    this.f_suspendHandler = f_suspendHandler;
+    this.f_messageHandler = f_messageHandler;
+
+    this.currentStatus = currentStatus;
+  }
+
+  /**
+   * This method needs to be called before a Task can be run().
+   * It informs the Driver that the Task is initializing.
+   */
+  public void initialize() {
+    this.currentStatus.setInit();
+  }
+
+  /**
+   * Run the task: Fire TaskStart, call Task.call(), fire TaskStop.
+   */
+  @Override
+  public void run() {
+    try {
+      // Change state and inform the Driver
+      this.taskLifeCycleHandlers.beforeTaskStart();
+
+      LOG.log(Level.FINEST, "Informing registered EventHandler<TaskStart>.");
+      this.currentStatus.setRunning();
+
+      // Call Task.call()
+      final byte[] result = this.runTask();
+
+      // Inform the Driver about it
+      this.currentStatus.setResult(result);
+
+      LOG.log(Level.FINEST, "Informing registered EventHandler<TaskStop>.");
+      this.taskLifeCycleHandlers.afterTaskExit();
+
+    } catch (final TaskStartHandlerFailure taskStartHandlerFailure) {
+      LOG.log(Level.WARNING, "Caught an exception during TaskStart handler execution.", taskStartHandlerFailure);
+      this.currentStatus.setException(taskStartHandlerFailure.getCause());
+    } catch (final TaskStopHandlerFailure taskStopHandlerFailure) {
+      LOG.log(Level.WARNING, "Caught an exception during TaskStop handler execution.", taskStopHandlerFailure);
+      this.currentStatus.setException(taskStopHandlerFailure.getCause());
+    } catch (final TaskCallFailure e) {
+      LOG.log(Level.WARNING, "Caught an exception during Task.call().", e.getCause());
+      this.currentStatus.setException(e);
+    }
+  }
+
+  /**
+   * Called by heartbeat manager
+   *
+   * @return current TaskStatusProto
+   */
+  public ReefServiceProtos.TaskStatusProto getStatusProto() {
+    return this.currentStatus.toProto();
+  }
+
+  /**
+   * @return true, if the Task is no longer running, either because it is crashed or exited cleanly
+   */
+  public boolean hasEnded() {
+    return this.currentStatus.hasEnded();
+  }
+
+  /**
+   * @return the ID of the task.
+   */
+  public String getTaskId() {
+    return this.currentStatus.getTaskId();
+  }
+
+  public String getId() {
+    return "TASK:" + this.task.getClass().getSimpleName() + ':' + this.currentStatus.getTaskId();
+  }
+
+  /**
+   * Close the Task. This calls the configured close handler.
+   *
+   * @param message the optional message for the close handler or null if there none.
+   */
+  public final void close(final byte[] message) {
+    LOG.log(Level.FINEST, "Triggering Task close.");
+    synchronized (this.heartBeatManager) {
+      if (this.currentStatus.isNotRunning()) {
+        LOG.log(Level.WARNING, "Trying to close a task that is in state: {0}. Ignoring.",
+            this.currentStatus.getState());
+      } else {
+        try {
+          this.closeTask(message);
+          this.currentStatus.setCloseRequested();
+        } catch (final TaskCloseHandlerFailure taskCloseHandlerFailure) {
+          LOG.log(Level.WARNING, "Exception while executing task close handler.",
+              taskCloseHandlerFailure.getCause());
+          this.currentStatus.setException(taskCloseHandlerFailure.getCause());
+        }
+      }
+    }
+  }
+
+  /**
+   * Suspend the Task.  This calls the configured suspend handler.
+   *
+   * @param message the optional message for the suspend handler or null if there none.
+   */
+  public void suspend(final byte[] message) {
+    synchronized (this.heartBeatManager) {
+      if (this.currentStatus.isNotRunning()) {
+        LOG.log(Level.WARNING, "Trying to suspend a task that is in state: {0}. Ignoring.",
+            this.currentStatus.getState());
+      } else {
+        try {
+          this.suspendTask(message);
+          this.currentStatus.setSuspendRequested();
+        } catch (final TaskSuspendHandlerFailure taskSuspendHandlerFailure) {
+          LOG.log(Level.WARNING, "Exception while executing task suspend handler.",
+              taskSuspendHandlerFailure.getCause());
+          this.currentStatus.setException(taskSuspendHandlerFailure.getCause());
+        }
+      }
+    }
+  }
+
+  /**
+   * Deliver a message to the Task. This calls into the user supplied message handler.
+   *
+   * @param message the message to be delivered.
+   */
+  public void deliver(final byte[] message) {
+    synchronized (this.heartBeatManager) {
+      if (this.currentStatus.isNotRunning()) {
+        LOG.log(Level.WARNING,
+            "Trying to send a message to a task that is in state: {0}. Ignoring.",
+            this.currentStatus.getState());
+      } else {
+        try {
+          this.deliverMessageToTask(message);
+        } catch (final TaskMessageHandlerFailure taskMessageHandlerFailure) {
+          LOG.log(Level.WARNING, "Exception while executing task close handler.",
+              taskMessageHandlerFailure.getCause());
+          this.currentStatus.setException(taskMessageHandlerFailure.getCause());
+        }
+      }
+    }
+  }
+
+  /**
+   * @return the ID of the Context this task is executing in.
+   */
+  private String getContextID() {
+    return this.currentStatus.getContextId();
+  }
+
+  /**
+   * Calls the Task.call() method and catches exceptions it may throw.
+   *
+   * @return the return value of Task.call()
+   * @throws TaskCallFailure if any Throwable was caught from the Task.call() method.
+   *                         That throwable would be the cause of the TaskCallFailure.
+   */
+  private byte[] runTask() throws TaskCallFailure {
+    try {
+      final byte[] result;
+      if (this.memento.isPresent()) {
+        LOG.log(Level.FINEST, "Calling Task.call() with a memento");
+        result = this.task.call(this.memento.get());
+      } else {
+        LOG.log(Level.FINEST, "Calling Task.call() without a memento");
+        result = this.task.call(null);
+      }
+      LOG.log(Level.FINEST, "Task.call() exited cleanly.");
+      return result;
+    } catch (final Throwable throwable) {
+      throw new TaskCallFailure(throwable);
+    }
+  }
+
+  /**
+   * Calls the configured Task close handler and catches exceptions it may throw.
+   */
+  private void closeTask(final byte[] message) throws TaskCloseHandlerFailure {
+    LOG.log(Level.FINEST, "Invoking close handler.");
+    try {
+      this.f_closeHandler.get().onNext(new CloseEventImpl(message));
+    } catch (final Throwable throwable) {
+      throw new TaskCloseHandlerFailure(throwable);
+    }
+  }
+
+  /**
+   * Calls the configured Task message handler and catches exceptions it may throw.
+   */
+  private void deliverMessageToTask(final byte[] message) throws TaskMessageHandlerFailure {
+    try {
+      this.f_messageHandler.get().onNext(new DriverMessageImpl(message));
+    } catch (final Throwable throwable) {
+      throw new TaskMessageHandlerFailure(throwable);
+    }
+  }
+
+  /**
+   * Calls the configured Task suspend handler and catches exceptions it may throw.
+   */
+  private void suspendTask(final byte[] message) throws TaskSuspendHandlerFailure {
+    try {
+      this.f_suspendHandler.get().onNext(new SuspendEventImpl(message));
+    } catch (final Throwable throwable) {
+      throw new TaskSuspendHandlerFailure(throwable);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskStartImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskStartImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskStartImpl.java
new file mode 100644
index 0000000..5bd598e
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskStartImpl.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.runtime.common.evaluator.task;
+
+import org.apache.reef.driver.task.TaskConfigurationOptions;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.task.events.TaskStart;
+
+import javax.inject.Inject;
+
+/**
+ * Injectable implementation of TaskStart
+ */
+final class TaskStartImpl implements TaskStart {
+
+  private final String id;
+
+  @Inject
+  TaskStartImpl(final @Parameter(TaskConfigurationOptions.Identifier.class) String id) {
+    this.id = id;
+  }
+
+  @Override
+  public String getId() {
+    return this.id;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskStatus.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskStatus.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskStatus.java
new file mode 100644
index 0000000..2cce16f
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskStatus.java
@@ -0,0 +1,310 @@
+/**
+ * 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.reef.runtime.common.evaluator.task;
+
+import com.google.protobuf.ByteString;
+import org.apache.reef.driver.task.TaskConfigurationOptions;
+import org.apache.reef.evaluator.context.parameters.ContextIdentifier;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.evaluator.HeartBeatManager;
+import org.apache.reef.runtime.common.utils.ExceptionCodec;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.task.TaskMessage;
+import org.apache.reef.task.TaskMessageSource;
+import org.apache.reef.util.Optional;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Represents the various states a Task could be in.
+ */
+public final class TaskStatus {
+  private static final Logger LOG = Logger.getLogger(TaskStatus.class.getName());
+
+  private final String taskId;
+  private final String contextId;
+  private final HeartBeatManager heartBeatManager;
+  private final Set<TaskMessageSource> evaluatorMessageSources;
+  private final ExceptionCodec exceptionCodec;
+  private Optional<Throwable> lastException = Optional.empty();
+  private Optional<byte[]> result = Optional.empty();
+  private State state = State.PRE_INIT;
+
+
+  @Inject
+  TaskStatus(final @Parameter(TaskConfigurationOptions.Identifier.class) String taskId,
+             final @Parameter(ContextIdentifier.class) String contextId,
+             final @Parameter(TaskConfigurationOptions.TaskMessageSources.class) Set<TaskMessageSource> evaluatorMessageSources,
+             final HeartBeatManager heartBeatManager,
+             final ExceptionCodec exceptionCodec) {
+    this.taskId = taskId;
+    this.contextId = contextId;
+    this.heartBeatManager = heartBeatManager;
+    this.evaluatorMessageSources = evaluatorMessageSources;
+    this.exceptionCodec = exceptionCodec;
+  }
+
+  /**
+   * @param from
+   * @param to
+   * @return true, if the state transition from state 'from' to state 'to' is legal.
+   */
+  private static boolean isLegal(final State from, final State to) {
+    if (from == null) {
+      return to == State.INIT;
+    }
+    switch (from) {
+      case PRE_INIT:
+        switch (to) {
+          case INIT:
+            return true;
+          default:
+            return false;
+        }
+      case INIT:
+        switch (to) {
+          case RUNNING:
+          case FAILED:
+          case KILLED:
+          case DONE:
+            return true;
+          default:
+            return false;
+        }
+      case RUNNING:
+        switch (to) {
+          case CLOSE_REQUESTED:
+          case SUSPEND_REQUESTED:
+          case FAILED:
+          case KILLED:
+          case DONE:
+            return true;
+          default:
+            return false;
+        }
+      case CLOSE_REQUESTED:
+        switch (to) {
+          case FAILED:
+          case KILLED:
+          case DONE:
+            return true;
+          default:
+            return false;
+        }
+      case SUSPEND_REQUESTED:
+        switch (to) {
+          case FAILED:
+          case KILLED:
+          case SUSPENDED:
+            return true;
+          default:
+            return false;
+        }
+
+      case FAILED:
+      case DONE:
+      case KILLED:
+        return false;
+      default:
+        return false;
+    }
+  }
+
+  public final String getTaskId() {
+    return this.taskId;
+  }
+
+  ReefServiceProtos.TaskStatusProto toProto() {
+    this.check();
+    final ReefServiceProtos.TaskStatusProto.Builder result = ReefServiceProtos.TaskStatusProto.newBuilder()
+        .setContextId(this.contextId)
+        .setTaskId(this.taskId)
+        .setState(this.getProtoState());
+
+    if (this.result.isPresent()) {
+      result.setResult(ByteString.copyFrom(this.result.get()));
+    } else if (this.lastException.isPresent()) {
+      final byte[] error = this.exceptionCodec.toBytes(this.lastException.get());
+      result.setResult(ByteString.copyFrom(error));
+    } else if (this.state == State.RUNNING) {
+      for (final TaskMessage taskMessage : this.getMessages()) {
+        result.addTaskMessage(ReefServiceProtos.TaskStatusProto.TaskMessageProto.newBuilder()
+            .setSourceId(taskMessage.getMessageSourceID())
+            .setMessage(ByteString.copyFrom(taskMessage.get()))
+            .build());
+      }
+    }
+
+    return result.build();
+  }
+
+  private void check() {
+    if (this.result.isPresent() && this.lastException.isPresent()) {
+      throw new RuntimeException("Found both an exception and a result. This is unsupported.");
+    }
+  }
+
+  private ReefServiceProtos.State getProtoState() {
+    switch (this.state) {
+      case INIT:
+        return ReefServiceProtos.State.INIT;
+      case CLOSE_REQUESTED:
+      case SUSPEND_REQUESTED:
+      case RUNNING:
+        return ReefServiceProtos.State.RUNNING;
+      case DONE:
+        return ReefServiceProtos.State.DONE;
+      case SUSPENDED:
+        return ReefServiceProtos.State.SUSPEND;
+      case FAILED:
+        return ReefServiceProtos.State.FAILED;
+      case KILLED:
+        return ReefServiceProtos.State.KILLED;
+    }
+    throw new RuntimeException("Unknown state: " + this.state);
+  }
+
+  void setException(final Throwable throwable) {
+    synchronized (this.heartBeatManager) {
+      this.lastException = Optional.of(throwable);
+      this.state = State.FAILED;
+      this.check();
+      this.heartbeat();
+    }
+  }
+
+  void setResult(final byte[] result) {
+    synchronized (this.heartBeatManager) {
+      this.result = Optional.ofNullable(result);
+      if (this.state == State.RUNNING) {
+        this.setState(State.DONE);
+      } else if (this.state == State.SUSPEND_REQUESTED) {
+        this.setState(State.SUSPENDED);
+      } else if (this.state == State.CLOSE_REQUESTED) {
+        this.setState(State.DONE);
+      }
+      this.check();
+      this.heartbeat();
+    }
+  }
+
+  private void heartbeat() {
+    this.heartBeatManager.sendTaskStatus(this.toProto());
+  }
+
+  /**
+   * Sets the state to INIT and informs the driver about it.
+   */
+  void setInit() {
+    LOG.log(Level.FINEST, "Sending Task INIT heartbeat to the Driver.");
+    this.setState(State.INIT);
+    this.heartbeat();
+  }
+
+  /**
+   * Sets the state to RUNNING after the handlers for TaskStart have been called.
+   */
+  void setRunning() {
+    this.setState(State.RUNNING);
+  }
+
+  void setCloseRequested() {
+    this.setState(State.CLOSE_REQUESTED);
+  }
+
+  void setSuspendRequested() {
+    this.setState(State.SUSPEND_REQUESTED);
+  }
+
+  void setKilled() {
+    this.setState(State.KILLED);
+    this.heartbeat();
+  }
+
+  boolean isRunning() {
+    return this.state == State.RUNNING;
+  }
+
+  boolean isNotRunning() {
+    return this.state != State.RUNNING;
+  }
+
+  boolean hasEnded() {
+    switch (this.state) {
+      case DONE:
+      case SUSPENDED:
+      case FAILED:
+      case KILLED:
+        return true;
+      default:
+        return false;
+    }
+  }
+
+  State getState() {
+    return this.state;
+  }
+
+  private void setState(final State state) {
+    if (isLegal(this.state, state)) {
+      this.state = state;
+    } else {
+      final String msg = "Illegal state transition from [" + this.state + "] to [" + state + "]";
+      LOG.log(Level.SEVERE, msg);
+      throw new RuntimeException(msg);
+    }
+  }
+
+  String getContextId() {
+    return this.contextId;
+  }
+
+  /**
+   * @return the messages to be sent on the Task's behalf in the next heartbeat.
+   */
+  private final Collection<TaskMessage> getMessages() {
+    final List<TaskMessage> result = new ArrayList<>(this.evaluatorMessageSources.size());
+    for (final TaskMessageSource messageSource : this.evaluatorMessageSources) {
+      final Optional<TaskMessage> taskMessageOptional = messageSource.getMessage();
+      if (taskMessageOptional.isPresent()) {
+        result.add(taskMessageOptional.get());
+      }
+    }
+    return result;
+  }
+
+
+  enum State {
+    PRE_INIT,
+    INIT,
+    RUNNING,
+    CLOSE_REQUESTED,
+    SUSPEND_REQUESTED,
+    SUSPENDED,
+    FAILED,
+    DONE,
+    KILLED
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskStopImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskStopImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskStopImpl.java
new file mode 100644
index 0000000..521d859
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/TaskStopImpl.java
@@ -0,0 +1,42 @@
+/**
+ * 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.reef.runtime.common.evaluator.task;
+
+import org.apache.reef.driver.task.TaskConfigurationOptions;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.task.events.TaskStop;
+
+import javax.inject.Inject;
+
+/**
+ * Injectable implementation of TaskStop
+ */
+final class TaskStopImpl implements TaskStop {
+  private final String id;
+
+  @Inject
+  TaskStopImpl(final @Parameter(TaskConfigurationOptions.Identifier.class) String id) {
+    this.id = id;
+  }
+
+  @Override
+  public String getId() {
+    return this.id;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/defaults/DefaultCloseHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/defaults/DefaultCloseHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/defaults/DefaultCloseHandler.java
new file mode 100644
index 0000000..6920f82
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/defaults/DefaultCloseHandler.java
@@ -0,0 +1,41 @@
+/**
+ * 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.reef.runtime.common.evaluator.task.defaults;
+
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.task.events.CloseEvent;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+
+/**
+ * Default implementation for EventHandler<CloseEvent>
+ */
+@Private
+public final class DefaultCloseHandler implements EventHandler<CloseEvent> {
+
+  @Inject
+  public DefaultCloseHandler() {
+  }
+
+  @Override
+  public void onNext(final CloseEvent closeEvent) {
+    throw new RuntimeException("No EventHandler<CloseEvent> registered. Event received: " + closeEvent);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/defaults/DefaultDriverMessageHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/defaults/DefaultDriverMessageHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/defaults/DefaultDriverMessageHandler.java
new file mode 100644
index 0000000..f1b4f34
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/defaults/DefaultDriverMessageHandler.java
@@ -0,0 +1,41 @@
+/**
+ * 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.reef.runtime.common.evaluator.task.defaults;
+
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.task.events.DriverMessage;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+
+/**
+ * A default implementation of EventHandler<DriverMessage>
+ */
+@Private
+public final class DefaultDriverMessageHandler implements EventHandler<DriverMessage> {
+
+  @Inject
+  public DefaultDriverMessageHandler() {
+  }
+
+  @Override
+  public void onNext(final DriverMessage driverMessage) {
+    throw new RuntimeException("No DriverMessage handler bound. Message received:" + driverMessage);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/defaults/DefaultSuspendHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/defaults/DefaultSuspendHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/defaults/DefaultSuspendHandler.java
new file mode 100644
index 0000000..3b485c6
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/defaults/DefaultSuspendHandler.java
@@ -0,0 +1,41 @@
+/**
+ * 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.reef.runtime.common.evaluator.task.defaults;
+
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.task.events.SuspendEvent;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+
+/**
+ * Default handler for SuspendEvent
+ */
+@Private
+public final class DefaultSuspendHandler implements EventHandler<SuspendEvent> {
+
+  @Inject
+  public DefaultSuspendHandler() {
+  }
+
+  @Override
+  public void onNext(final SuspendEvent suspendEvent) {
+    throw new RuntimeException("No handler for SuspendEvent registered. event: " + suspendEvent);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/defaults/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/defaults/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/defaults/package-info.java
new file mode 100644
index 0000000..d69a4aa
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/defaults/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Default implementations for the optional task interfaces.
+ */
+package org.apache.reef.runtime.common.evaluator.task.defaults;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskCallFailure.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskCallFailure.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskCallFailure.java
new file mode 100644
index 0000000..9827a01
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskCallFailure.java
@@ -0,0 +1,37 @@
+/**
+ * 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.reef.runtime.common.evaluator.task.exceptions;
+
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Private;
+
+/**
+ * Thrown when a Task.call() throws an exception
+ */
+@EvaluatorSide
+@Private
+public final class TaskCallFailure extends Exception {
+
+  /**
+   * @param cause the exception thrown by the Task.call() method.
+   */
+  public TaskCallFailure(final Throwable cause) {
+    super("Task.call() threw an Exception.", cause);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskCloseHandlerFailure.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskCloseHandlerFailure.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskCloseHandlerFailure.java
new file mode 100644
index 0000000..bb18044
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskCloseHandlerFailure.java
@@ -0,0 +1,37 @@
+/**
+ * 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.reef.runtime.common.evaluator.task.exceptions;
+
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Private;
+
+/**
+ * Thrown when a Task Close Handler throws an exception
+ */
+@EvaluatorSide
+@Private
+public final class TaskCloseHandlerFailure extends Exception {
+
+  /**
+   * @param cause the exception thrown by the Task.call() method.
+   */
+  public TaskCloseHandlerFailure(final Throwable cause) {
+    super("Task close handler threw an Exception.", cause);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskMessageHandlerFailure.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskMessageHandlerFailure.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskMessageHandlerFailure.java
new file mode 100644
index 0000000..8ccf1d1
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskMessageHandlerFailure.java
@@ -0,0 +1,37 @@
+/**
+ * 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.reef.runtime.common.evaluator.task.exceptions;
+
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Private;
+
+/**
+ * Thrown when a Task Message Handler throws an exception
+ */
+@EvaluatorSide
+@Private
+public final class TaskMessageHandlerFailure extends Exception {
+
+  /**
+   * the exception thrown by the task message handler's onNext() method.
+   */
+  public TaskMessageHandlerFailure(final Throwable cause) {
+    super("Task message handler threw an Exception.", cause);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskStartHandlerFailure.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskStartHandlerFailure.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskStartHandlerFailure.java
new file mode 100644
index 0000000..24dcb35
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskStartHandlerFailure.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.runtime.common.evaluator.task.exceptions;
+
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.task.events.TaskStart;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ * Thrown when a TastStart handler throws an exception
+ */
+@EvaluatorSide
+@Private
+public final class TaskStartHandlerFailure extends Exception {
+
+  /**
+   * @param cause the exception thrown by the start handler
+   */
+  public TaskStartHandlerFailure(final EventHandler<TaskStart> handler, final Throwable cause) {
+    super("EventHandler<TaskStart> `" + handler.toString() + "` threw an Exception in onNext()", cause);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskStopHandlerFailure.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskStopHandlerFailure.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskStopHandlerFailure.java
new file mode 100644
index 0000000..05d77bc
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskStopHandlerFailure.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.runtime.common.evaluator.task.exceptions;
+
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.task.events.TaskStop;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ * Thrown when a TaskStop handler throws an exception
+ */
+@EvaluatorSide
+@Private
+public final class TaskStopHandlerFailure extends Exception {
+
+  /**
+   * @param cause the exception thrown by the stop handler
+   */
+  public TaskStopHandlerFailure(final EventHandler<TaskStop> handler, final Throwable cause) {
+    super("EventHandler<TaskStop> `" + handler.toString() + "` threw an Exception in onNext()", cause);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskSuspendHandlerFailure.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskSuspendHandlerFailure.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskSuspendHandlerFailure.java
new file mode 100644
index 0000000..31b275e
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/exceptions/TaskSuspendHandlerFailure.java
@@ -0,0 +1,37 @@
+/**
+ * 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.reef.runtime.common.evaluator.task.exceptions;
+
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Private;
+
+/**
+ * Thrown when a Task Suspend Handler throws an exception
+ */
+@EvaluatorSide
+@Private
+public final class TaskSuspendHandlerFailure extends Exception {
+
+  /**
+   * @param cause the exception thrown by the task suspend handler's onNext() method.
+   */
+  public TaskSuspendHandlerFailure(final Throwable cause) {
+    super("Task suspend handler threw an Exception.", cause);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/package-info.java
new file mode 100644
index 0000000..1329251
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/task/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Task-related implementation of the Evaluator resourcemanager.
+ */
+package org.apache.reef.runtime.common.evaluator.task;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/ClasspathProvider.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/ClasspathProvider.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/ClasspathProvider.java
new file mode 100644
index 0000000..a1ad04a
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/ClasspathProvider.java
@@ -0,0 +1,83 @@
+/**
+ * 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.reef.runtime.common.files;
+
+import net.jcip.annotations.Immutable;
+import org.apache.reef.annotations.audience.RuntimeAuthor;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Supplies the classpath to REEF for process (Driver, Evaluator) launches.
+ */
+@Immutable
+@RuntimeAuthor
+public final class ClasspathProvider {
+  private final List<String> driverClasspath;
+  private final List<String> evaluatorClasspath;
+
+
+  @Inject
+  ClasspathProvider(final RuntimeClasspathProvider runtimeClasspathProvider,
+                    final REEFFileNames reefFileNames) {
+    final List<String> baseClasspath = Arrays.asList(
+        reefFileNames.getLocalFolderPath() + "/*",
+        reefFileNames.getGlobalFolderPath() + "/*");
+
+    // Assemble the driver classpath
+    final List<String> runtimeDriverClasspathPrefix = runtimeClasspathProvider.getDriverClasspathPrefix();
+    final List<String> runtimeDriverClasspathSuffix = runtimeClasspathProvider.getDriverClasspathSuffix();
+    final List<String> driverClasspath = new ArrayList<>(baseClasspath.size() +
+        runtimeDriverClasspathPrefix.size() +
+        runtimeDriverClasspathSuffix.size());
+    driverClasspath.addAll(runtimeDriverClasspathPrefix);
+    driverClasspath.addAll(baseClasspath);
+    driverClasspath.addAll(runtimeDriverClasspathSuffix);
+    this.driverClasspath = Collections.unmodifiableList(driverClasspath);
+
+    // Assemble the evaluator classpath
+    final List<String> runtimeEvaluatorClasspathPrefix = runtimeClasspathProvider.getEvaluatorClasspathPrefix();
+    final List<String> runtimeEvaluatorClasspathSuffix = runtimeClasspathProvider.getEvaluatorClasspathSuffix();
+    final List<String> evaluatorClasspath = new ArrayList<>(runtimeEvaluatorClasspathPrefix.size() +
+        baseClasspath.size() +
+        runtimeEvaluatorClasspathSuffix.size());
+    evaluatorClasspath.addAll(runtimeEvaluatorClasspathPrefix);
+    evaluatorClasspath.addAll(baseClasspath);
+    evaluatorClasspath.addAll(runtimeEvaluatorClasspathSuffix);
+    this.evaluatorClasspath = Collections.unmodifiableList(evaluatorClasspath);
+  }
+
+  /**
+   * @return the classpath to be used for the Driver
+   */
+  public List<String> getDriverClasspath() {
+    return this.driverClasspath;
+  }
+
+  /**
+   * @return the classpath to be used for Evaluators.
+   */
+  public List<String> getEvaluatorClasspath() {
+    return this.evaluatorClasspath;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/JobJarMaker.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/JobJarMaker.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/JobJarMaker.java
new file mode 100644
index 0000000..5297158
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/JobJarMaker.java
@@ -0,0 +1,136 @@
+/**
+ * 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.reef.runtime.common.files;
+
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.annotations.audience.RuntimeAuthor;
+import org.apache.reef.proto.ClientRuntimeProtocol;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.parameters.DeleteTempFiles;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.formats.ConfigurationSerializer;
+import org.apache.reef.util.JARFileMaker;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Utility that takes a JobSubmissionProto and turns it into a Job Submission Jar.
+ */
+@Private
+@RuntimeAuthor
+@ClientSide
+public final class JobJarMaker {
+
+  private static final Logger LOG = Logger.getLogger(JobJarMaker.class.getName());
+
+  private final ConfigurationSerializer configurationSerializer;
+  private final REEFFileNames fileNames;
+  private final boolean deleteTempFilesOnExit;
+
+  @Inject
+  JobJarMaker(final ConfigurationSerializer configurationSerializer,
+              final REEFFileNames fileNames,
+              final @Parameter(DeleteTempFiles.class) boolean deleteTempFilesOnExit) {
+    this.configurationSerializer = configurationSerializer;
+    this.fileNames = fileNames;
+    this.deleteTempFilesOnExit = deleteTempFilesOnExit;
+  }
+
+  public static void copy(final Iterable<ReefServiceProtos.FileResourceProto> files, final File destinationFolder) {
+
+    if (!destinationFolder.exists()) {
+      destinationFolder.mkdirs();
+    }
+
+    for (final ReefServiceProtos.FileResourceProto fileProto : files) {
+      final File sourceFile = toFile(fileProto);
+      final File destinationFile = new File(destinationFolder, fileProto.getName());
+      if (destinationFile.exists()) {
+        LOG.log(Level.FINEST,
+            "Will not add {0} to the job jar because another file with the same name was already added.",
+            sourceFile.getAbsolutePath()
+        );
+      } else {
+        try {
+          java.nio.file.Files.copy(sourceFile.toPath(), destinationFile.toPath());
+        } catch (final IOException e) {
+          final String message = new StringBuilder("Copy of file [")
+              .append(sourceFile.getAbsolutePath())
+              .append("] to [")
+              .append(destinationFile.getAbsolutePath())
+              .append("] failed.")
+              .toString();
+          throw new RuntimeException(message, e);
+        }
+      }
+    }
+  }
+
+  private static File toFile(final ReefServiceProtos.FileResourceProto fileProto) {
+    return new File(fileProto.getPath());
+  }
+
+  public File createJobSubmissionJAR(
+      final ClientRuntimeProtocol.JobSubmissionProto jobSubmissionProto,
+      final Configuration driverConfiguration) throws IOException {
+
+    // Copy all files to a local job submission folder
+    final File jobSubmissionFolder = makejobSubmissionFolder();
+    LOG.log(Level.FINE, "Staging submission in {0}", jobSubmissionFolder);
+
+    final File localFolder = new File(jobSubmissionFolder, this.fileNames.getLocalFolderName());
+    final File globalFolder = new File(jobSubmissionFolder, this.fileNames.getGlobalFolderName());
+
+    this.copy(jobSubmissionProto.getGlobalFileList(), globalFolder);
+    this.copy(jobSubmissionProto.getLocalFileList(), localFolder);
+
+    // Store the Driver Configuration in the JAR file.
+    this.configurationSerializer.toFile(
+        driverConfiguration, new File(localFolder, this.fileNames.getDriverConfigurationName()));
+
+    // Create a JAR File for the submission
+    final File jarFile = File.createTempFile(this.fileNames.getJobFolderPrefix(), this.fileNames.getJarFileSuffix());
+
+    LOG.log(Level.FINE, "Creating job submission jar file: {0}", jarFile);
+    new JARFileMaker(jarFile).addChildren(jobSubmissionFolder).close();
+
+    if (this.deleteTempFilesOnExit) {
+      LOG.log(Level.FINE,
+          "Deleting the temporary job folder [{0}] and marking the jar file [{1}] for deletion after the JVM exits.",
+          new Object[]{jobSubmissionFolder.getAbsolutePath(), jarFile.getAbsolutePath()});
+      jobSubmissionFolder.delete();
+      jarFile.deleteOnExit();
+    } else {
+      LOG.log(Level.FINE, "Keeping the temporary job folder [{0}] and jar file [{1}] available after job submission.",
+          new Object[]{jobSubmissionFolder.getAbsolutePath(), jarFile.getAbsolutePath()});
+    }
+    return jarFile;
+  }
+
+  private File makejobSubmissionFolder() throws IOException {
+    return Files.createTempDirectory(this.fileNames.getJobFolderPrefix()).toFile();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/REEFFileNames.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/REEFFileNames.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/REEFFileNames.java
new file mode 100644
index 0000000..0fac287
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/REEFFileNames.java
@@ -0,0 +1,216 @@
+/**
+ * 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.reef.runtime.common.files;
+
+import net.jcip.annotations.Immutable;
+
+import javax.inject.Inject;
+import java.io.File;
+
+/**
+ * Access to the various places things go according to the REEF file system standard.
+ */
+@Immutable
+public final class REEFFileNames {
+
+  private static final String REEF_BASE_FOLDER = "reef";
+  private static final String GLOBAL_FOLDER = "global";
+  static final String GLOBAL_FOLDER_PATH = REEF_BASE_FOLDER + '/' + GLOBAL_FOLDER;
+  private static final String LOCAL_FOLDER = "local";
+  static final String LOCAL_FOLDER_PATH = REEF_BASE_FOLDER + '/' + LOCAL_FOLDER;
+  private static final String DRIVER_CONFIGURATION_NAME = "driver.conf";
+  private static final String DRIVER_CONFIGURATION_PATH =
+      LOCAL_FOLDER_PATH + '/' + DRIVER_CONFIGURATION_NAME;
+  private static final String EVALUATOR_CONFIGURATION_NAME = "evaluator.conf";
+  private static final String EVALUATOR_CONFIGURATION_PATH =
+      LOCAL_FOLDER_PATH + '/' + EVALUATOR_CONFIGURATION_NAME;
+  private static final String JAR_FILE_SUFFIX = ".jar";
+  private static final String JOB_FOLDER_PREFIX = "reef-job-";
+  private static final String EVALUATOR_FOLDER_PREFIX = "reef-evaluator-";
+  private static final String DRIVER_STDERR = "driver.stderr";
+  private static final String DRIVER_STDOUT = "driver.stdout";
+  private static final String EVALUATOR_STDERR = "evaluator.stderr";
+  private static final String EVALUATOR_STDOUT = "evaluator.stdout";
+  private static final String CPP_BRIDGE = "JavaClrBridge";
+  private static final String REEF_GLOBAL = "/reef/global";
+  private static final String REEF_DRIVER_APPDLL_DIR = "/ReefDriverAppDlls/";
+  private static final String TMP_LOAD_DIR = "/reef/CLRLoadingDirectory";
+
+  @Inject
+  public REEFFileNames() {
+  }
+
+  /**
+   * The name of the REEF folder inside of the working directory of an Evaluator or Driver
+   */
+  public String getREEFFolderName() {
+    return REEF_BASE_FOLDER;
+  }
+
+  /**
+   * @return the folder und which all REEF files are stored.
+   */
+  public File getREEFFolder() {
+    return new File(getREEFFolderName());
+  }
+
+
+  /**
+   * @return the name of the folder inside of REEF_BASE_FOLDER that houses the global files.
+   */
+  public String getGlobalFolderName() {
+    return GLOBAL_FOLDER;
+  }
+
+  /**
+   * @return the path to the global folder: REEF_BASE_FOLDER/GLOBAL_FOLDER
+   */
+  public String getGlobalFolderPath() {
+    return GLOBAL_FOLDER_PATH;
+  }
+
+  /**
+   * @return the folder holding the files global to all containers.
+   */
+  public File getGlobalFolder() {
+    return new File(getREEFFolder(), getGlobalFolderName());
+  }
+
+
+  /**
+   * @return the name of the folder inside of REEF_BASE_FOLDER that houses the local files.
+   */
+  public String getLocalFolderName() {
+    return LOCAL_FOLDER;
+  }
+
+  /**
+   * @return the path to the local folder: REEF_BASE_FOLDER/LOCAL_FOLDER
+   */
+  public String getLocalFolderPath() {
+    return LOCAL_FOLDER_PATH;
+  }
+
+  /**
+   * @return the folder holding the files local to this container.
+   */
+  public File getLocalFolder() {
+    return new File(getREEFFolder(), getLocalFolderName());
+  }
+
+
+  /**
+   * The name under which the driver configuration will be stored in REEF_BASE_FOLDER/LOCAL_FOLDER
+   */
+  public String getDriverConfigurationName() {
+    return DRIVER_CONFIGURATION_NAME;
+  }
+
+  /**
+   * @return The path to the driver configuration: GLOBAL_FOLDER/LOCAL_FOLDER/DRIVER_CONFIGURATION_NAME
+   */
+  public String getDriverConfigurationPath() {
+    return DRIVER_CONFIGURATION_PATH;
+  }
+
+  /**
+   * @return The name under which the driver configuration will be stored in REEF_BASE_FOLDER/LOCAL_FOLDER
+   */
+  public String getEvaluatorConfigurationName() {
+    return EVALUATOR_CONFIGURATION_NAME;
+  }
+
+  /**
+   * @return the path to the evaluator configuration.
+   */
+  public String getEvaluatorConfigurationPath() {
+    return EVALUATOR_CONFIGURATION_PATH;
+  }
+
+  /**
+   * @return The suffix used for JAR files, including the "."
+   */
+  public String getJarFileSuffix() {
+    return JAR_FILE_SUFFIX;
+  }
+
+  /**
+   * The prefix used whenever REEF is asked to create a job folder, on (H)DFS or locally.
+   * <p/>
+   * This prefix is also used with JAR files created to represent a job.
+   */
+  public String getJobFolderPrefix() {
+    return JOB_FOLDER_PREFIX;
+  }
+
+  /**
+   * @return The name used within the current working directory of the driver to redirect standard error to.
+   */
+  public String getDriverStderrFileName() {
+    return DRIVER_STDERR;
+  }
+
+  /**
+   * @return The name used within the current working directory of the driver to redirect standard out to.
+   */
+  public String getDriverStdoutFileName() {
+    return DRIVER_STDOUT;
+  }
+
+  /**
+   * @return The prefix used whenever REEF is asked to create an Evaluator folder, e.g. for staging.
+   */
+  public String getEvaluatorFolderPrefix() {
+    return EVALUATOR_FOLDER_PREFIX;
+  }
+
+  /**
+   * @return The name used within the current working directory of the driver to redirect standard error to.
+   */
+  public String getEvaluatorStderrFileName() {
+    return EVALUATOR_STDERR;
+  }
+
+  /**
+   * @return The name used within the current working directory of the driver to redirect standard out to.
+   */
+  public String getEvaluatorStdoutFileName() {
+    return EVALUATOR_STDOUT;
+  }
+
+  /**
+   * @return the name of cpp bridge file
+   */
+  public String getCppBridge() { return CPP_BRIDGE; }
+
+  /**
+   * @return reeg global file folder
+   */
+  public String getReefGlobal() { return REEF_GLOBAL; }
+
+  /**
+   * @return reef driver app dll directory
+   */
+  public String getReefDriverAppDllDir() { return REEF_DRIVER_APPDLL_DIR; }
+
+  /**
+   * @return temp load directory
+   */
+  public String getLoadDir() { return TMP_LOAD_DIR; }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/RuntimeClasspathProvider.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/RuntimeClasspathProvider.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/RuntimeClasspathProvider.java
new file mode 100644
index 0000000..8d753c8
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/RuntimeClasspathProvider.java
@@ -0,0 +1,48 @@
+/**
+ * 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.reef.runtime.common.files;
+
+import java.util.List;
+
+/**
+ * Interface to be implemented by each REEF runtime (YARN, Mesos, Local) to provide additional classpath elements to be
+ * pre- and postfixed to the user classpath.
+ */
+public interface RuntimeClasspathProvider {
+
+  /**
+   * @return the classpath to be prefixed in front of the user classpath of the Driver.
+   */
+  List<String> getDriverClasspathPrefix();
+
+  /**
+   * @return the classpath to be suffixed after of the user classpath of the Driver.
+   */
+  List<String> getDriverClasspathSuffix();
+
+  /**
+   * @return the classpath to be prefixed in front of the user classpath of each Evaluator.
+   */
+  List<String> getEvaluatorClasspathPrefix();
+
+  /**
+   * @return the classpath to be suffixed after of the user classpath of each Evaluator.
+   */
+  List<String> getEvaluatorClasspathSuffix();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/package-info.java
new file mode 100644
index 0000000..e0bfda0
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/files/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * This package will contain the implementation of the REEF file system standard.
+ */
+package org.apache.reef.runtime.common.files;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/CLRLaunchCommandBuilder.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/CLRLaunchCommandBuilder.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/CLRLaunchCommandBuilder.java
new file mode 100644
index 0000000..7c5334b
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/CLRLaunchCommandBuilder.java
@@ -0,0 +1,99 @@
+/**
+ * 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.reef.runtime.common.launch;
+
+import org.apache.commons.lang.StringUtils;
+
+import java.io.File;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A builder for the command line to launch a CLR Evaluator.
+ */
+public class CLRLaunchCommandBuilder implements LaunchCommandBuilder {
+  private static final Logger LOG = Logger.getLogger(CLRLaunchCommandBuilder.class.getName());
+  private static final String EVALUATOR_PATH = "reef/global/Microsoft.Reef.Evaluator.exe";
+
+
+  private String standardErrPath = null;
+  private String standardOutPath = null;
+  private String errorHandlerRID = null;
+  private String launchID = null;
+  private int megaBytes = 0;
+  private String evaluatorConfigurationPath = null;
+
+  @Override
+  public List<String> build() {
+    final List<String> result = new LinkedList<>();
+    File f = new File(EVALUATOR_PATH);
+    if (!f.exists()) {
+      LOG.log(Level.WARNING, "file can NOT be found: {0}", f.getAbsolutePath());
+    }
+    result.add(f.getPath());
+    result.add(errorHandlerRID);
+    result.add(evaluatorConfigurationPath);
+    if ((null != this.standardOutPath) && (!standardOutPath.isEmpty())) {
+      result.add(">" + this.standardOutPath);
+    }
+    if ((null != this.standardErrPath) && (!standardErrPath.isEmpty())) {
+      result.add("2>" + this.standardErrPath);
+    }
+    LOG.log(Level.FINE, "Launch Exe: {0}", StringUtils.join(result, ' '));
+    return result;
+  }
+
+  @Override
+  public CLRLaunchCommandBuilder setErrorHandlerRID(final String errorHandlerRID) {
+    this.errorHandlerRID = errorHandlerRID;
+    return this;
+  }
+
+  @Override
+  public CLRLaunchCommandBuilder setLaunchID(final String launchID) {
+    this.launchID = launchID;
+    return this;
+  }
+
+  @Override
+  public CLRLaunchCommandBuilder setMemory(final int megaBytes) {
+    this.megaBytes = megaBytes;
+    return this;
+  }
+
+  @Override
+  public CLRLaunchCommandBuilder setConfigurationFileName(final String configurationFileName) {
+    this.evaluatorConfigurationPath = configurationFileName;
+    return this;
+  }
+
+  @Override
+  public CLRLaunchCommandBuilder setStandardOut(final String standardOut) {
+    this.standardOutPath = standardOut;
+    return this;
+  }
+
+  @Override
+  public CLRLaunchCommandBuilder setStandardErr(final String standardErr) {
+    this.standardErrPath = standardErr;
+    return this;
+  }
+}


[48/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.cpp
new file mode 100644
index 0000000..0a9353d
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.cpp
@@ -0,0 +1,492 @@
+/**
+ * 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.
+ */
+#include "InteropUtil.h"
+#include "org_apache_reef_javabridge_NativeInterop.h"
+#include "JavaClrBridge.h"
+#include "InteropAssemblies.h"
+#include "InteropReturnInfo.h"
+#include "Clr2JavaImpl.h"
+#include "InteropLogger.h"
+#include "BinaryUtil.h"
+#include "malloc.h"
+
+using namespace System;
+using namespace System::IO;
+using namespace System::Collections::Generic;
+using namespace System::Runtime::InteropServices;
+using namespace System::Reflection;
+using namespace Microsoft::Reef::Driver::Bridge;
+
+ref class ManagedLog {
+  internal:
+    static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>");
+};
+
+static void MarshalErrorToJava (
+  JNIEnv *env,
+  jobject  jerrorInfo,
+  int errorNo,
+  String^ exceptionString
+) {
+  jclass objectClass;
+  jfieldID fieldID;
+
+  objectClass = env->GetObjectClass(jerrorInfo);
+  fieldID = env->GetFieldID(objectClass, "errorNo", "I");
+  env->SetIntField (jerrorInfo, fieldID, errorNo);
+
+  pin_ptr<const wchar_t> wchExceptionString = PtrToStringChars(exceptionString);
+  jstring jexceptionString = env->NewString((const jchar*)wchExceptionString, exceptionString->Length);
+  fieldID = env->GetFieldID(objectClass, "exceptionString", "Ljava/lang/String;");
+  env->SetObjectField(jerrorInfo, fieldID, jexceptionString);
+}
+
+
+// Loading Clr Assembly. Note that we do not use ManagerLogger in this method since the
+// logger assembly needs to be loaded by this method before it can be used.
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_loadClrAssembly
+(
+  JNIEnv *env,
+  jclass  tobj,
+  jstring jfileName) {
+  try {
+    Console::Write("+Java_org_apache_reef_javabridge_NativeInterop_loadClrAssembly: ");
+    const wchar_t* charAsmName = UnicodeCppStringFromJavaString (env, jfileName);
+    int len = env->GetStringLength(jfileName);
+    wchar_t* fileName = (wchar_t* )_alloca((len + 2) * sizeof(wchar_t));
+    memcpy(fileName, charAsmName, (len + 2)* sizeof(wchar_t));
+    fileName[len] = 0;
+    String^ asmName = ManagedStringFromJavaString(env, jfileName);
+    Console::WriteLine("loading " + asmName);
+
+    BINARY_TYPE binaryType = IsManagedBinary(fileName);
+    if (binaryType == BINARY_TYPE_CLR) {
+      System::Reflection::Assembly^ asm1 = Assembly::LoadFrom(asmName);
+      AssemblyUtil::Add(asm1);
+    }
+    else if (binaryType == BINARY_TYPE_NATIVE) {
+      HANDLE handle = LoadLibraryW(fileName);
+    }
+  }
+  catch (System::Exception^ ex) {
+    // We do not propagate the exception back to Java to stop driver here
+    // since failure to load an assembly is not necesary devastating
+    Console::Write("Exceptions in Java_org_apache_reef_javabridge_NativeInterop_loadClrAssembly");
+    Console::Write(ex->Message);
+    Console::Write(ex->StackTrace);
+  }
+
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    CallClrSystemOnStartHandler
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT jlongArray JNICALL Java_org_apache_reef_javabridge_NativeInterop_CallClrSystemOnStartHandler
+(JNIEnv * env, jclass jclassx, jstring dateTimeString, jstring httpServerPort) {
+  try {
+    ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_CallClrSystemOnStartHandler");
+    const wchar_t* charConfig = UnicodeCppStringFromJavaString (env, dateTimeString);
+    int lenConfig = env->GetStringLength(dateTimeString);
+    String^  strConfig = Marshal::PtrToStringUni((IntPtr)(unsigned short*) charConfig, lenConfig);
+    DateTime dt = DateTime::Now;
+
+	const wchar_t* charPort = UnicodeCppStringFromJavaString (env, httpServerPort);
+    int lenPort = env->GetStringLength(httpServerPort);
+    String^  strPort = Marshal::PtrToStringUni((IntPtr)(unsigned short*) charPort, lenPort);
+
+    array<unsigned long long>^ handlers = ClrSystemHandlerWrapper::Call_ClrSystemStartHandler_OnStart(dt, strPort);
+    return JavaLongArrayFromManagedLongArray(env, handlers);
+  }
+  catch (System::Exception^ ex) {
+    // we cannot get error back to java here since we don't have an object to call back (although we idealy should...)
+    ManagedLog::LOGGER->LogError("Exceptions in Java_org_apache_reef_javabridge_NativeInterop_CallClrSystemOnStartHandler", ex);
+    return NULL;
+  }
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    ClrSystemAllocatedEvaluatorHandlerOnNext
+ * Signature: (JLorg/apache/reef/javabridge/AllocatedEvaluatorBridge;Lorg/apache/reef/javabridge/InteropLogger;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemAllocatedEvaluatorHandlerOnNext
+(JNIEnv *env, jclass cls, jlong handle, jobject jallocatedEvaluatorBridge, jobject jlogger) {
+  ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemAllocatedEvaluatorHandlerOnNext:");
+  AllocatedEvaluatorClr2Java^ allocatedEval = gcnew AllocatedEvaluatorClr2Java(env, jallocatedEvaluatorBridge);
+  try {
+    ClrSystemHandlerWrapper::Call_ClrSystemAllocatedEvaluatorHandler_OnNext(handle, allocatedEval);
+  }
+  catch (System::Exception^ ex) {
+    String^ errorMessage = "Exception in Call_ClrSystemAllocatedEvaluatorHandler_OnNext";
+    ManagedLog::LOGGER->LogError(errorMessage, ex);
+    allocatedEval -> OnError(errorMessage);
+  }
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    ClrSystemActiveContextHandlerOnNext
+ * Signature: (JLorg/apache/reef/javabridge/ActiveContextBridge;Lorg/apache/reef/javabridge/InteropLogger;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemActiveContextHandlerOnNext
+(JNIEnv *env, jclass cls, jlong handle, jobject jactiveContextBridge, jobject jlogger) {
+  ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemActiveContextHandlerOnNext");
+  ActiveContextClr2Java^ activeContextBrdige = gcnew ActiveContextClr2Java(env, jactiveContextBridge);
+  try {
+    ClrSystemHandlerWrapper::Call_ClrSystemActiveContextHandler_OnNext(handle, activeContextBrdige);
+  }
+  catch (System::Exception^ ex) {
+    String^ errorMessage = "Exception in Call_ClrSystemActiveContextHandler_OnNext";
+    ManagedLog::LOGGER->LogError(errorMessage, ex);
+    activeContextBrdige -> OnError(errorMessage);
+  }
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    ClrSystemEvaluatorRequstorHandlerOnNext
+ * Signature: (JLorg/apache/reef/javabridge/EvaluatorRequstorBridge;Lorg/apache/reef/javabridge/InteropLogger;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemEvaluatorRequstorHandlerOnNext
+(JNIEnv *env, jclass cls, jlong handle, jobject jevaluatorRequestorBridge, jobject jlogger) {
+  ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemEvaluatorRequstorHandlerOnNext");
+  EvaluatorRequestorClr2Java^ evaluatorRequestorBridge = gcnew EvaluatorRequestorClr2Java(env, jevaluatorRequestorBridge);
+  try {
+    ClrSystemHandlerWrapper::Call_ClrSystemEvaluatorRequestor_OnNext(handle, evaluatorRequestorBridge);
+  }
+  catch (System::Exception^ ex) {
+    String^ errorMessage = "Exception in Call_ClrSystemEvaluatorRequestor_OnNext";
+    ManagedLog::LOGGER->LogError(errorMessage, ex);
+    evaluatorRequestorBridge -> OnError(errorMessage);
+  }
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    ClrSystemTaskMessageHandlerOnNext
+ * Signature: (J[BLorg/apache/reef/javabridge/TaskMessageBridge;Lorg/apache/reef/javabridge/InteropLogger;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemTaskMessageHandlerOnNext
+(JNIEnv *env, jclass cls, jlong handle, jbyteArray jmessage, jobject jtaskMessageBridge, jobject jlogger) {
+  ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemTaskMessageHandlerOnNext");
+  TaskMessageClr2Java^ taskMesageBridge = gcnew TaskMessageClr2Java(env, jtaskMessageBridge);
+  array<byte>^ message = ManagedByteArrayFromJavaByteArray(env, jmessage);
+  try {
+    ClrSystemHandlerWrapper::Call_ClrSystemTaskMessage_OnNext(handle, taskMesageBridge, message);
+  }
+  catch (System::Exception^ ex) {
+    String^ errorMessage = "Exception in Call_ClrSystemTaskMessage_OnNext";
+    ManagedLog::LOGGER->LogError(errorMessage, ex);
+    taskMesageBridge -> OnError(errorMessage);
+  }
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    ClrSysteFailedTaskHandlerOnNext
+ * Signature: (JLorg/apache/reef/javabridge/FailedTaskBridge;Lorg/apache/reef/javabridge/InteropLogger;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemFailedTaskHandlerOnNext
+(JNIEnv *env , jclass cls, jlong handler, jobject jfailedTask, jobject jlogger) {
+  ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemFailedTaskHandlerOnNext");
+  FailedTaskClr2Java^ failedTaskBridge = gcnew FailedTaskClr2Java(env, jfailedTask);
+  try {
+    ClrSystemHandlerWrapper::Call_ClrSystemFailedTask_OnNext(handler, failedTaskBridge);
+  }
+  catch (System::Exception^ ex) {
+    String^ errorMessage = "Exception in Call_ClrSystemTaskMessage_OnNext";
+    ManagedLog::LOGGER->LogError(errorMessage, ex);
+    failedTaskBridge -> OnError(errorMessage);
+  }
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    ClrSysteFailedTaskHandlerOnNext
+ * Signature: (JLorg.apache.reef.javabridge/FailedTaskBridge;Lorg.apache.reef.javabridge/InteropLogger;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemRunningTaskHandlerOnNext
+(JNIEnv *env , jclass cls, jlong handler, jobject jrunningTask, jobject jlogger) {
+  ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemRunningTaskHandlerOnNext");
+  RunningTaskClr2Java^ runningTaskBridge = gcnew RunningTaskClr2Java(env, jrunningTask);
+  try {
+    ClrSystemHandlerWrapper::Call_ClrSystemRunningTask_OnNext(handler, runningTaskBridge);
+  }
+  catch (System::Exception^ ex) {
+    String^ errorMessage = "Exception in Call_ClrSystemRunningTask_OnNext";
+    ManagedLog::LOGGER->LogError(errorMessage, ex);
+    runningTaskBridge -> OnError(errorMessage);
+  }
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    ClrSystemFailedEvaluatorHandlerOnNext
+ * Signature: (JLorg/apache/reef/javabridge/FailedEvaluatorBridge;Lorg/apache/reef/javabridge/InteropLogger;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemFailedEvaluatorHandlerOnNext
+(JNIEnv *env , jclass cls, jlong handler, jobject jfailedEvaluator, jobject jlogger) {
+  ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemFailedEvaluatorHandlerOnNext");
+  FailedEvaluatorClr2Java^ failedEvaluatorBridge = gcnew FailedEvaluatorClr2Java(env, jfailedEvaluator);
+  try {
+    ClrSystemHandlerWrapper::Call_ClrSystemFailedEvaluator_OnNext(handler, failedEvaluatorBridge);
+  }
+  catch (System::Exception^ ex) {
+    String^ errorMessage = "Exception in Call_ClrSystemFailedEvaluator_OnNext";
+    ManagedLog::LOGGER->LogError(errorMessage, ex);
+    failedEvaluatorBridge -> OnError(errorMessage);
+  }
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    ClrSystemHttpServerEventHandlerOnHttpRequest
+ * Signature: (JLorg/apache/reef/javabridge/HttpServerEventBridge;Lorg/apache/reef/javabridge/InteropLogger;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemHttpServerHandlerOnNext
+(JNIEnv *env , jclass cls, jlong handler, jobject jhttpServerEventBridge, jobject jlogger) {
+  ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemHttpServerHandlerOnNext");
+  HttpServerClr2Java^ httpServerClr2Java = gcnew HttpServerClr2Java(env, jhttpServerEventBridge);
+  try {
+    ClrSystemHandlerWrapper::Call_ClrSystemHttpServer_OnNext(handler, httpServerClr2Java);
+  }
+  catch (System::Exception^ ex) {
+    String^ errorMessage = "Exception in Call_ClrSystemHttpServer_OnNext";
+    ManagedLog::LOGGER->LogError(errorMessage, ex);
+    httpServerClr2Java -> OnError(errorMessage);
+  }
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    ClrSystemCompletedTaskHandlerOnNext
+ * Signature: (JLorg/apache/reef/javabridge/CompletedTaskBridge;Lorg/apache/reef/javabridge/InteropLogger;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemCompletedTaskHandlerOnNext
+(JNIEnv *env , jclass cls, jlong handler, jobject jcompletedTask, jobject jlogger) {
+  ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemCompletedTaskHandlerOnNext");
+  CompletedTaskClr2Java^ completedTaskBridge = gcnew CompletedTaskClr2Java(env, jcompletedTask);
+  try {
+    ClrSystemHandlerWrapper::Call_ClrSystemCompletedTask_OnNext(handler, completedTaskBridge);
+  }
+  catch (System::Exception^ ex) {
+    String^ errorMessage = "Exception in Call_ClrSystemCompletedTask_OnNext";
+    ManagedLog::LOGGER->LogError(errorMessage, ex);
+    completedTaskBridge -> OnError(errorMessage);
+  }
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    ClrBufferedLog
+ * Signature: (ILjava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrBufferedLog
+(JNIEnv *env, jclass cls, jint logLevel, jstring message) {
+  try {
+    if (!JavaClrBridge::LoggerWrapper::initialized) {
+      ManagedLog::LOGGER->Log("Initializing CLRBufferedLogHandler in java bridge...");
+      JavaClrBridge::LoggerWrapper::logger->Listeners->Add(gcnew System::Diagnostics::ConsoleTraceListener());
+      JavaClrBridge::LoggerWrapper::initialized = true;
+    }
+
+    System::Diagnostics::TraceEventType eventType;
+    switch (logLevel) {
+    case 0:
+      eventType = System::Diagnostics::TraceEventType::Stop;
+      break;
+    case 1:
+      eventType = System::Diagnostics::TraceEventType::Error;
+      break;
+    case 2:
+      eventType = System::Diagnostics::TraceEventType::Warning;
+      break;
+    case 3:
+      eventType = System::Diagnostics::TraceEventType::Information;
+      break;
+    case 4:
+      eventType = System::Diagnostics::TraceEventType::Verbose;
+      break;
+    default:
+      eventType = System::Diagnostics::TraceEventType::Information;
+      break;
+
+    }
+
+    String^ msg = ManagedStringFromJavaString(env, message);
+    msg = System::String::Concat(System::DateTime::Now, msg);
+    JavaClrBridge::LoggerWrapper::logger->TraceEvent(eventType, 0, msg);
+  }
+  catch (System::Exception^ ex) {
+    ManagedLog::LOGGER->LogError("Exception in Java_javabridge_NativeInterop_ClrBufferedLog", ex);
+  }
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    ClrSystemSupendedTaskHandlerOnNext
+ * Signature: (JLorg/apache/reef/javabridge/SuspendedTaskBridge;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemSupendedTaskHandlerOnNext
+(JNIEnv *env , jclass cls, jlong handler, jobject jsuspendedTask) {
+  ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemSupendedTaskHandlerOnNext");
+  SuspendedTaskClr2Java^ suspendedTaskBridge = gcnew SuspendedTaskClr2Java(env, jsuspendedTask);
+  try {
+    ClrSystemHandlerWrapper::Call_ClrSystemSuspendedTask_OnNext(handler, suspendedTaskBridge);
+  }
+  catch (System::Exception^ ex) {
+    String^ errorMessage = "Exception in Call_ClrSystemSuspendedTask_OnNext";
+    ManagedLog::LOGGER->LogError(errorMessage, ex);
+    suspendedTaskBridge -> OnError(errorMessage);
+  }
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    ClrSystemCompletdEvaluatorHandlerOnNext
+ * Signature: (JLorg/apache/reef/javabridge/CompletedEvaluatorBridge;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemCompletdEvaluatorHandlerOnNext
+(JNIEnv *env , jclass cls, jlong handler, jobject jcompletedEvaluator) {
+  ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemCompletdEvaluatorHandlerOnNext");
+  CompletedEvaluatorClr2Java^ completedEvaluatorBridge = gcnew CompletedEvaluatorClr2Java(env, jcompletedEvaluator);
+  try {
+    ClrSystemHandlerWrapper::Call_ClrSystemCompletedEvaluator_OnNext(handler, completedEvaluatorBridge);
+  }
+  catch (System::Exception^ ex) {
+    String^ errorMessage = "Exception in Call_ClrSystemSuspendedTask_OnNext";
+    ManagedLog::LOGGER->LogError(errorMessage, ex);
+    completedEvaluatorBridge -> OnError(errorMessage);
+  }
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    ClrSystemClosedContextHandlerOnNext
+ * Signature: (JLorg/apache/reef/javabridge/ClosedContextBridge;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemClosedContextHandlerOnNext
+(JNIEnv *env , jclass cls, jlong handler, jobject jclosedContext) {
+  ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemClosedContextHandlerOnNext");
+  ClosedContextClr2Java^ closedContextBridge = gcnew ClosedContextClr2Java(env, jclosedContext);
+  try {
+    ClrSystemHandlerWrapper::Call_ClrSystemClosedContext_OnNext(handler, closedContextBridge);
+  }
+  catch (System::Exception^ ex) {
+    String^ errorMessage = "Exception in Call_ClrSystemClosedContext_OnNext";
+    ManagedLog::LOGGER->LogError(errorMessage, ex);
+    closedContextBridge -> OnError(errorMessage);
+  }
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    ClrSystemFailedContextHandlerOnNext
+ * Signature: (JLorg/apache/reef/javabridge/FailedContextBridge;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemFailedContextHandlerOnNext
+(JNIEnv *env , jclass cls, jlong handler, jobject jfailedContext) {
+  ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemFailedContextHandlerOnNext");
+  FailedContextClr2Java^ failedContextBridge = gcnew FailedContextClr2Java(env, jfailedContext);
+  try {
+    ClrSystemHandlerWrapper::Call_ClrSystemFailedContext_OnNext(handler, failedContextBridge);
+  }
+  catch (System::Exception^ ex) {
+    String^ errorMessage = "Exception in Call_ClrSystemFailedContext_OnNext";
+    ManagedLog::LOGGER->LogError(errorMessage, ex);
+    failedContextBridge -> OnError(errorMessage);
+  }
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    ClrSystemContextMessageHandlerOnNext
+ * Signature: (JLorg/apache/reef/javabridge/ContextMessageBridge;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemContextMessageHandlerOnNext
+(JNIEnv *env , jclass cls, jlong handler, jobject jcontextMessage) {
+  ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemContextMessageHandlerOnNext");
+  ContextMessageClr2Java^ contextMessageBridge = gcnew ContextMessageClr2Java(env, jcontextMessage);
+  try {
+    ClrSystemHandlerWrapper::Call_ClrSystemContextMessage_OnNext(handler, contextMessageBridge);
+  }
+  catch (System::Exception^ ex) {
+    String^ errorMessage = "Exception in Call_ClrSystemContextMessage_OnNext";
+    ManagedLog::LOGGER->LogError(errorMessage, ex);
+    contextMessageBridge -> OnError(errorMessage);
+  }
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    ClrSystemDriverRestartHandlerOnNext
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemDriverRestartHandlerOnNext
+(JNIEnv *env , jclass cls, jlong handler) {
+  ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemDriverRestartHandlerOnNext");
+  try {
+    ClrSystemHandlerWrapper::Call_ClrSystemDriverRestart_OnNext(handler);
+  }
+  catch (System::Exception^ ex) {
+    String^ errorMessage = "Exception in Call_ClrSystemContextMessage_OnNext";
+    ManagedLog::LOGGER->LogError(errorMessage, ex);
+    // we do not call back to Java for exception in .NET restart handler
+  }
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    ClrSystemDriverRestartActiveContextHandlerOnNext
+ * Signature: (JLorg/apache/reef/javabridge/ActiveContextBridge;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemDriverRestartActiveContextHandlerOnNext
+(JNIEnv *env, jclass cls, jlong handle, jobject jactiveContextBridge) {
+  ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemDriverRestartActiveContextHandlerOnNext");
+  ActiveContextClr2Java^ activeContextBrdige = gcnew ActiveContextClr2Java(env, jactiveContextBridge);
+  try {
+    ClrSystemHandlerWrapper::Call_ClrSystemDriverRestartActiveContextHandler_OnNext(handle, activeContextBrdige);
+  }
+  catch (System::Exception^ ex) {
+    String^ errorMessage = "Exception in Call_ClrSystemDriverRestartActiveContextHandler_OnNext";
+    ManagedLog::LOGGER -> LogError(errorMessage, ex);
+    activeContextBrdige -> OnError(errorMessage);
+  }
+}
+
+/*
+ * Class:     org_apache_reef_javabridge_NativeInterop
+ * Method:    ClrSystemDriverRestartRunningTaskHandlerOnNext
+ * Signature: (JLorg/apache/reef/javabridge/RunningTaskBridge;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_reef_javabridge_NativeInterop_ClrSystemDriverRestartRunningTaskHandlerOnNext
+(JNIEnv *env , jclass cls, jlong handler, jobject jrunningTask) {
+  ManagedLog::LOGGER->Log("+Java_org_apache_reef_javabridge_NativeInterop_ClrSystemDriverRestartRunningTaskHandlerOnNext");
+  RunningTaskClr2Java^ runningTaskBridge = gcnew RunningTaskClr2Java(env, jrunningTask);
+  try {
+    ClrSystemHandlerWrapper::Call_ClrSystemDriverRestartRunningTask_OnNext(handler, runningTaskBridge);
+  }
+  catch (System::Exception^ ex) {
+    String^ errorMessage = "Exception in Call_ClrSystemDriverRestartRunningTask_OnNext";
+    ManagedLog::LOGGER->LogError(errorMessage, ex);
+    runningTaskBridge -> OnError(errorMessage);
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.h
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.h b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.h
new file mode 100644
index 0000000..61d9d0a
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.h
@@ -0,0 +1,33 @@
+/**
+ * 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.
+ */
+// JavaClrBridge.h
+
+#pragma once
+
+using namespace System;
+
+namespace JavaClrBridge {
+    ref class LoggerWrapper
+    {
+    public:
+        static System::Diagnostics::TraceSource^ logger = 
+            gcnew System::Diagnostics::TraceSource("JavaCLRBridgeLogger", System::Diagnostics::SourceLevels::All);
+        static bool initialized = false;
+    };
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.sln
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.sln b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.sln
new file mode 100644
index 0000000..d4b2aec
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.sln
@@ -0,0 +1,56 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "JavaClrBridge", "JavaClrBridge.vcxproj", "{2825FD53-350B-4294-8CFC-8DD2F4F4F285}"
+	ProjectSection(ProjectDependencies) = postProject
+		{443A7B61-5C91-4F67-9FCD-81BC6FABFDBD} = {443A7B61-5C91-4F67-9FCD-81BC6FABFDBD}
+	EndProjectSection
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClrHandler", "..\..\..\CSharp\CSharp\ClrHandler\ClrHandler.csproj", "{443A7B61-5C91-4F67-9FCD-81BC6FABFDBD}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Debug|Mixed Platforms = Debug|Mixed Platforms
+		Debug|Win32 = Debug|Win32
+		Debug|x64 = Debug|x64
+		Release|Any CPU = Release|Any CPU
+		Release|Mixed Platforms = Release|Mixed Platforms
+		Release|Win32 = Release|Win32
+		Release|x64 = Release|x64
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{2825FD53-350B-4294-8CFC-8DD2F4F4F285}.Debug|Any CPU.ActiveCfg = Debug|Win32
+		{2825FD53-350B-4294-8CFC-8DD2F4F4F285}.Debug|Mixed Platforms.ActiveCfg = Release|x64
+		{2825FD53-350B-4294-8CFC-8DD2F4F4F285}.Debug|Mixed Platforms.Build.0 = Release|x64
+		{2825FD53-350B-4294-8CFC-8DD2F4F4F285}.Debug|Mixed Platforms.Deploy.0 = Release|x64
+		{2825FD53-350B-4294-8CFC-8DD2F4F4F285}.Debug|Win32.ActiveCfg = Debug|Win32
+		{2825FD53-350B-4294-8CFC-8DD2F4F4F285}.Debug|Win32.Build.0 = Debug|Win32
+		{2825FD53-350B-4294-8CFC-8DD2F4F4F285}.Debug|x64.ActiveCfg = Debug|x64
+		{2825FD53-350B-4294-8CFC-8DD2F4F4F285}.Debug|x64.Build.0 = Debug|x64
+		{2825FD53-350B-4294-8CFC-8DD2F4F4F285}.Release|Any CPU.ActiveCfg = Release|Win32
+		{2825FD53-350B-4294-8CFC-8DD2F4F4F285}.Release|Mixed Platforms.ActiveCfg = Release|x64
+		{2825FD53-350B-4294-8CFC-8DD2F4F4F285}.Release|Mixed Platforms.Build.0 = Release|x64
+		{2825FD53-350B-4294-8CFC-8DD2F4F4F285}.Release|Win32.ActiveCfg = Release|Win32
+		{2825FD53-350B-4294-8CFC-8DD2F4F4F285}.Release|Win32.Build.0 = Release|Win32
+		{2825FD53-350B-4294-8CFC-8DD2F4F4F285}.Release|x64.ActiveCfg = Release|x64
+		{2825FD53-350B-4294-8CFC-8DD2F4F4F285}.Release|x64.Build.0 = Release|x64
+		{443A7B61-5C91-4F67-9FCD-81BC6FABFDBD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{443A7B61-5C91-4F67-9FCD-81BC6FABFDBD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{443A7B61-5C91-4F67-9FCD-81BC6FABFDBD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+		{443A7B61-5C91-4F67-9FCD-81BC6FABFDBD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+		{443A7B61-5C91-4F67-9FCD-81BC6FABFDBD}.Debug|Win32.ActiveCfg = Debug|Any CPU
+		{443A7B61-5C91-4F67-9FCD-81BC6FABFDBD}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{443A7B61-5C91-4F67-9FCD-81BC6FABFDBD}.Debug|x64.Build.0 = Debug|Any CPU
+		{443A7B61-5C91-4F67-9FCD-81BC6FABFDBD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{443A7B61-5C91-4F67-9FCD-81BC6FABFDBD}.Release|Any CPU.Build.0 = Release|Any CPU
+		{443A7B61-5C91-4F67-9FCD-81BC6FABFDBD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+		{443A7B61-5C91-4F67-9FCD-81BC6FABFDBD}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+		{443A7B61-5C91-4F67-9FCD-81BC6FABFDBD}.Release|Win32.ActiveCfg = Release|Any CPU
+		{443A7B61-5C91-4F67-9FCD-81BC6FABFDBD}.Release|x64.ActiveCfg = Release|Any CPU
+		{443A7B61-5C91-4F67-9FCD-81BC6FABFDBD}.Release|x64.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.vcxproj
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.vcxproj b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.vcxproj
new file mode 100644
index 0000000..08412d1
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.vcxproj
@@ -0,0 +1,173 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup Condition="'$(Configuration)'==''">
+    <Configuration>Release</Configuration>
+  </PropertyGroup>
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="DefaultDirectories">
+    <JAVA_HOME Condition=" '$(JAVA_HOME)' == '' ">c:\progra~1\java\jdk1.7.0_40</JAVA_HOME>
+  </PropertyGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{2825FD53-350B-4294-8CFC-8DD2F4F4F285}</ProjectGuid>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <Keyword>ManagedCProj</Keyword>
+    <RootNamespace>Microsoft.Reef.Interop</RootNamespace>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v110</PlatformToolset>
+    <CLRSupport>true</CLRSupport>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v110</PlatformToolset>
+    <CLRSupport>true</CLRSupport>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <PlatformToolset>v110</PlatformToolset>
+    <CLRSupport>true</CLRSupport>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>DynamicLibrary</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <PlatformToolset>v110</PlatformToolset>
+    <CLRSupport>true</CLRSupport>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <LinkIncremental>true</LinkIncremental>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <LinkIncremental>true</LinkIncremental>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <LinkIncremental>false</LinkIncremental>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <LinkIncremental>false</LinkIncremental>
+  </PropertyGroup>
+  <ItemDefinitionGroup>
+    <ClCompile>
+      <AdditionalUsingDirectories>..\..\..\..\..\target\classes</AdditionalUsingDirectories>
+      <AdditionalIncludeDirectories>..\..\..\..\..\..\reef-bridge-java\target\classes;$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32</AdditionalIncludeDirectories>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>false</GenerateDebugInformation>
+      <OutputFile>..\..\..\..\..\target\classes\$(TargetName)$(TargetExt)</OutputFile>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PrecompiledHeader>Use</PrecompiledHeader>
+    </ClCompile>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+      <PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PrecompiledHeader>NotUsing</PrecompiledHeader>
+    </ClCompile>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PrecompiledHeader>NotUsing</PrecompiledHeader>
+    </ClCompile>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <PreprocessorDefinitions>WIN32;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PrecompiledHeader>NotUsing</PrecompiledHeader>
+    </ClCompile>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="BinaryUtil.h" />
+    <ClInclude Include="Clr2JavaImpl.h" />
+    <ClInclude Include="InteropAssemblies.h" />
+    <ClInclude Include="InteropLogger.h" />
+    <ClInclude Include="InteropReturnInfo.h" />
+    <ClInclude Include="InteropUtil.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="ActiveContextClr2Java.cpp" />
+    <ClCompile Include="AllocatedEvaluatorClr2Java.cpp" />
+    <ClCompile Include="AssemblyInfo.cpp" />
+    <ClCompile Include="AssemblyUtil.cpp" />
+    <ClCompile Include="BinaryUtil.cpp" />
+    <ClCompile Include="ClosedContextClr2Java.cpp" />
+    <ClCompile Include="CommonUtilities.cpp" />
+    <ClCompile Include="CompletedEvaluatorClr2Java.cpp" />
+    <ClCompile Include="CompletedTaskClr2Java.cpp" />
+    <ClCompile Include="ContextMessageClr2Java.cpp" />
+    <ClCompile Include="EvaluatorRequestorClr2Java.cpp" />
+    <ClCompile Include="FailedContextClr2Java.cpp" />
+    <ClCompile Include="FailedEvaluatorClr2Java.cpp" />
+    <ClCompile Include="FailedTaskClr2Java.cpp" />
+    <ClCompile Include="HttpServerClr2Java.cpp" />
+    <ClCompile Include="InteropLogger.cpp" />
+    <ClCompile Include="InteropReturnInfo.cpp" />
+    <ClCompile Include="InteropUtil.cpp" />
+    <ClCompile Include="JavaClrBridge.cpp" />
+    <ClCompile Include="RunningTaskClr2Java.cpp" />
+    <ClCompile Include="SuspendedTaskClr2Java.cpp" />
+    <ClCompile Include="TaskMessageClr2Java.cpp" />
+  </ItemGroup>
+  <ItemGroup>
+    <Text Include="ReadMe.txt" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.vcxproj.filters
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.vcxproj.filters b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.vcxproj.filters
new file mode 100644
index 0000000..5421846
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.vcxproj.filters
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup>
+    <Filter Include="Source Files">
+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+    </Filter>
+    <Filter Include="Header Files">
+      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+    </Filter>
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="InteropUtil.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="InteropAssemblies.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="InteropReturnInfo.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="InteropLogger.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Clr2JavaImpl.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="BinaryUtil.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="JavaClrBridge.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="AssemblyInfo.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="InteropUtil.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="AssemblyUtil.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="InteropReturnInfo.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="InteropLogger.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="AllocatedEvaluatorClr2Java.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="ActiveContextClr2Java.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="EvaluatorRequestorClr2Java.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="TaskMessageClr2Java.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="BinaryUtil.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="FailedTaskClr2Java.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="FailedEvaluatorClr2Java.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="HttpServerClr2Java.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="CompletedTaskClr2Java.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="RunningTaskClr2Java.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="SuspendedTaskClr2Java.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="CompletedEvaluatorClr2Java.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="ClosedContextClr2Java.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="CommonUtilities.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="FailedContextClr2Java.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="ContextMessageClr2Java.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+  </ItemGroup>
+  <ItemGroup>
+    <Text Include="ReadMe.txt" />
+  </ItemGroup>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ManagedLogger.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ManagedLogger.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ManagedLogger.cpp
new file mode 100644
index 0000000..62e30b3
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ManagedLogger.cpp
@@ -0,0 +1,47 @@
+/**
+ * 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.
+ */
+#include "Clr2JavaImpl.h"
+
+using namespace JavaClrBridge;
+
+namespace Microsoft
+{
+	namespace Reef
+	{
+		namespace Driver
+		{
+			namespace Bridge
+			{				
+				ManagedLogger::ManagedLogger(String^ className)
+				{
+					_logger = BridgeLogger::GetLogger(className);	
+				}
+				BridgeLogger^  ManagedLogger::GetLogger(String^ className)
+				{
+					if(_logger == nullptr)
+					{
+						_logger = BridgeLogger::GetLogger(className);
+					}
+					return _logger;
+				}
+
+			}
+		}
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ReadMe.txt
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ReadMe.txt b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ReadMe.txt
new file mode 100644
index 0000000..4e1b52f
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ReadMe.txt
@@ -0,0 +1,57 @@
+====
+    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.
+====
+
+========================================================================
+    DYNAMIC LINK LIBRARY : JavaClrBridge Project Overview
+========================================================================
+
+AppWizard has created this JavaClrBridge DLL for you.  
+
+This file contains a summary of what you will find in each of the files that
+make up your JavaClrBridge application.
+
+JavaClrBridge.vcxproj
+    This is the main project file for VC++ projects generated using an Application Wizard. 
+    It contains information about the version of Visual C++ that generated the file, and 
+    information about the platforms, configurations, and project features selected with the
+    Application Wizard.
+
+JavaClrBridge.vcxproj.filters
+    This is the filters file for VC++ projects generated using an Application Wizard. 
+    It contains information about the association between the files in your project 
+    and the filters. This association is used in the IDE to show grouping of files with
+    similar extensions under a specific node (for e.g. ".cpp" files are associated with the
+    "Source Files" filter).
+
+JavaClrBridge.cpp
+    This is the main DLL source file.
+
+JavaClrBridge.h
+    This file contains a class declaration.
+
+AssemblyInfo.cpp
+	Contains custom attributes for modifying assembly metadata.
+
+/////////////////////////////////////////////////////////////////////////////
+Other notes:
+
+AppWizard uses "TODO:" to indicate parts of the source code you
+should add to or customize.
+
+/////////////////////////////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/RunningTaskClr2Java.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/RunningTaskClr2Java.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/RunningTaskClr2Java.cpp
new file mode 100644
index 0000000..7ef6f08
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/RunningTaskClr2Java.cpp
@@ -0,0 +1,90 @@
+/**
+ * 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.
+ */
+#include "Clr2JavaImpl.h"
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Driver {
+      namespace Bridge {
+        ref class ManagedLog {
+          internal:
+            static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>");
+        };
+        RunningTaskClr2Java::RunningTaskClr2Java(JNIEnv *env, jobject jobjectRunningTask) {
+          ManagedLog::LOGGER->LogStart("RunningTaskClr2Java::RunningTaskClr2Java");
+
+          pin_ptr<JavaVM*> pJavaVm = &_jvm;
+          if (env->GetJavaVM(pJavaVm) != 0) {
+            ManagedLog::LOGGER->LogError("Failed to get JavaVM", nullptr);
+          }
+          _jobjectRunningTask = reinterpret_cast<jobject>(env->NewGlobalRef(jobjectRunningTask));
+
+          jclass jclassRunningTask = env->GetObjectClass (_jobjectRunningTask);
+          jmethodID jmidGetId = env->GetMethodID(jclassRunningTask, "getId", "()Ljava/lang/String;");
+
+          _jstringId = reinterpret_cast<jstring>(env->NewGlobalRef(env -> CallObjectMethod(_jobjectRunningTask, jmidGetId)));
+          ManagedLog::LOGGER->LogStop("RunningTaskClr2Java::RunningTaskClr2Java");
+        }
+
+        IActiveContextClr2Java^ RunningTaskClr2Java::GetActiveContext() {
+          ManagedLog::LOGGER->LogStart("RunningTaskClr2Java::GetActiveContext");
+
+          JNIEnv *env = RetrieveEnv(_jvm);
+
+          jclass jclassRunningTask = env->GetObjectClass(_jobjectRunningTask);
+          jfieldID jidActiveContext = env->GetFieldID(jclassRunningTask, "jactiveContext", "Lorg/apache/reef/javabridge/ActiveContextBridge;");
+          jobject jobjectActiveContext = env->GetObjectField(_jobjectRunningTask, jidActiveContext);
+          ManagedLog::LOGGER->LogStop("RunningTaskClr2Java::GetActiveContext");
+
+          return gcnew ActiveContextClr2Java(env, jobjectActiveContext);
+        }
+
+        String^ RunningTaskClr2Java::GetId() {
+          ManagedLog::LOGGER->Log("RunningTaskClr2Java::GetId");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          return ManagedStringFromJavaString(env, _jstringId);
+        }
+
+        void RunningTaskClr2Java::Send(array<byte>^ message) {
+          ManagedLog::LOGGER->LogStart("RunningTaskClr2Java::Send");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          jclass jclassRunningTask = env->GetObjectClass(_jobjectRunningTask);
+          jmethodID jmidSend = env->GetMethodID(jclassRunningTask, "send", "([B)V");
+
+
+          if (jmidSend == NULL) {
+            ManagedLog::LOGGER->Log("jmidSend is NULL");
+            return;
+          }
+          env->CallObjectMethod(
+            _jobjectRunningTask,
+            jmidSend,
+            JavaByteArrayFromManagedByteArray(env, message));
+          ManagedLog::LOGGER->LogStop("RunningTaskClr2Java::Send");
+        }
+
+        void RunningTaskClr2Java::OnError(String^ message) {
+          ManagedLog::LOGGER->Log("RunningTaskClr2Java::OnError");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          HandleClr2JavaError(env, message, _jobjectRunningTask);
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/SuspendedTaskClr2Java.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/SuspendedTaskClr2Java.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/SuspendedTaskClr2Java.cpp
new file mode 100644
index 0000000..695e2b3
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/SuspendedTaskClr2Java.cpp
@@ -0,0 +1,83 @@
+/**
+ * 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.
+ */
+#include "Clr2JavaImpl.h"
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Driver {
+      namespace Bridge {
+        ref class ManagedLog {
+          internal:
+            static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>");
+        };
+
+        SuspendedTaskClr2Java::SuspendedTaskClr2Java(JNIEnv *env, jobject jobjectSuspendedTask) {
+          ManagedLog::LOGGER->LogStart("SuspendedTaskClr2Java::SuspendedTaskClr2Java");
+          pin_ptr<JavaVM*> pJavaVm = &_jvm;
+          if (env->GetJavaVM(pJavaVm) != 0) {
+            ManagedLog::LOGGER->LogError("Failed to get JavaVM", nullptr);
+          }
+          _jobjectSuspendedTask = reinterpret_cast<jobject>(env->NewGlobalRef(jobjectSuspendedTask));
+
+          jclass jclassSuspendedTask = env->GetObjectClass (_jobjectSuspendedTask);
+          jfieldID jidTaskId = env->GetFieldID(jclassSuspendedTask, "taskId", "Ljava/lang/String;");
+          _jstringId = reinterpret_cast<jstring>(env->NewGlobalRef(env->GetObjectField(_jobjectSuspendedTask, jidTaskId)));
+          ManagedLog::LOGGER->LogStop("SuspendedTaskClr2Java::SuspendedTaskClr2Java");
+        }
+
+        IActiveContextClr2Java^ SuspendedTaskClr2Java::GetActiveContext() {
+          ManagedLog::LOGGER->LogStart("SuspendedTaskClr2Java::GetActiveContext");
+          JNIEnv *env = RetrieveEnv(_jvm);
+
+          jclass jclassSuspendedTask = env->GetObjectClass (_jobjectSuspendedTask);
+          jfieldID jidActiveContext = env->GetFieldID(jclassSuspendedTask, "jactiveContext", "Lorg/apache/reef/javabridge/ActiveContextBridge;");
+          jobject jobjectActiveContext = env->GetObjectField(_jobjectSuspendedTask, jidActiveContext);
+          ManagedLog::LOGGER->LogStop("SuspendedTaskClr2Java::GetActiveContext");
+          return gcnew ActiveContextClr2Java(env, jobjectActiveContext);
+        }
+
+        String^ SuspendedTaskClr2Java::GetId() {
+          ManagedLog::LOGGER->Log("SuspendedTaskClr2Java::GetId");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          return ManagedStringFromJavaString(env, _jstringId);
+        }
+
+        array<byte>^ SuspendedTaskClr2Java::Get() {
+          ManagedLog::LOGGER->Log("SuspendedTaskClr2Java::Get");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          jclass jclassSuspendedTask = env->GetObjectClass (_jobjectSuspendedTask);
+          jmethodID jmidGet = env->GetMethodID(jclassSuspendedTask, "get", "()[B");
+
+          if (jmidGet == NULL) {
+            ManagedLog::LOGGER->Log("jmidGet is NULL");
+            return nullptr;
+          }
+          jbyteArray jMessage = (jbyteArray) env->CallObjectMethod(_jobjectSuspendedTask, jmidGet);
+          return ManagedByteArrayFromJavaByteArray(env, jMessage);
+        }
+
+        void SuspendedTaskClr2Java::OnError(String^ message) {
+          ManagedLog::LOGGER->Log("SuspendedTaskClr2Java::OnError");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          HandleClr2JavaError(env, message, _jobjectSuspendedTask);
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/TaskMessageClr2Java.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/TaskMessageClr2Java.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/TaskMessageClr2Java.cpp
new file mode 100644
index 0000000..01d9471
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/TaskMessageClr2Java.cpp
@@ -0,0 +1,58 @@
+/**
+ * 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.
+ */
+#include "Clr2JavaImpl.h"
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Driver {
+      namespace Bridge {
+        ref class ManagedLog {
+          internal:
+            static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>");
+        };
+
+        TaskMessageClr2Java::TaskMessageClr2Java(JNIEnv *env, jobject jtaskMessage) {
+          ManagedLog::LOGGER->LogStart("TaskMessageClr2Java::TaskMessageClr2Java");
+          pin_ptr<JavaVM*> pJavaVm = &_jvm;
+          if (env->GetJavaVM(pJavaVm) != 0) {
+            ManagedLog::LOGGER->LogError("Failed to get JavaVM", nullptr);
+          }
+          _jobjectTaskMessage = reinterpret_cast<jobject>(env->NewGlobalRef(jtaskMessage));
+
+          jclass jclassTaskMessage = env->GetObjectClass (_jobjectTaskMessage);
+          jfieldID jidTaskId = env->GetFieldID(jclassTaskMessage, "taskId", "Ljava/lang/String;");
+          _jstringId = reinterpret_cast<jstring>(env->NewGlobalRef(env->GetObjectField(_jobjectTaskMessage, jidTaskId)));
+          ManagedLog::LOGGER->LogStop("TaskMessageClr2Java::TaskMessageClr2Java");
+        }
+
+        void TaskMessageClr2Java::OnError(String^ message) {
+          ManagedLog::LOGGER->Log("TaskMessageClr2Java::OnError");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          HandleClr2JavaError(env, message, _jobjectTaskMessage);
+        }
+
+        String^ TaskMessageClr2Java::GetId() {
+          ManagedLog::LOGGER->Log("TaskMessageClr2Java::GetId");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          return ManagedStringFromJavaString(env, _jstringId);
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/pom.xml b/lang/java/reef-bridge-project/reef-bridge-java/pom.xml
new file mode 100644
index 0000000..c383190
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/pom.xml
@@ -0,0 +1,116 @@
+<?xml version="1.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.
+-->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+         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>
+    <artifactId>reef-bridge-java</artifactId>
+    <name>REEF Bridge Java</name>
+    <description>Bridge between JVM and CLR.</description>
+
+
+    <parent>
+        <groupId>org.apache.reef</groupId>
+        <artifactId>reef-bridge-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-local</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-yarn</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-io</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-checkpoint</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-webserver</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.avro</groupId>
+            <artifactId>avro</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-jar-plugin</artifactId>
+                <configuration>
+                    <archive>
+                        <manifest>
+                            <addClasspath>false</addClasspath>
+                            <classpathPrefix>lib/</classpathPrefix>
+                            <mainClass>org.apache.reef.javabridge.JavaBridge</mainClass>
+                        </manifest>
+                    </archive>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-antrun-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>process-classes</phase>
+                        <goals>
+                            <goal>run</goal>
+                        </goals>
+                        <configuration>
+                            <exportAntProperties>true</exportAntProperties>
+                            <target>
+                                <property name="runtime_classpath" refid="maven.compile.classpath"/>
+                                <exec executable="javah">
+                                    <arg value="-cp"/>
+                                    <arg value="${runtime_classpath}"/>
+                                    <arg value="-d"/>
+                                    <arg value="${project.build.directory}/classes"/>
+                                    <arg value="org.apache.reef.javabridge.NativeInterop"/>
+                                </exec>
+                            </target>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ActiveContextBridge.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ActiveContextBridge.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ActiveContextBridge.java
new file mode 100644
index 0000000..a0dedf5
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ActiveContextBridge.java
@@ -0,0 +1,80 @@
+/**
+ * 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.reef.javabridge;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.io.naming.Identifiable;
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.formats.AvroConfigurationSerializer;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class ActiveContextBridge extends NativeBridge implements Identifiable {
+  private static final Logger LOG = Logger.getLogger(ActiveContextBridge.class.getName());
+
+  private ActiveContext jactiveContext;
+
+  private AvroConfigurationSerializer serializer;
+
+  private String contextId;
+
+  private String evaluatorId;
+
+  public ActiveContextBridge(ActiveContext activeContext) {
+    jactiveContext = activeContext;
+    serializer = new AvroConfigurationSerializer();
+    contextId = activeContext.getId();
+    evaluatorId = activeContext.getEvaluatorId();
+  }
+
+  public void submitTaskString(final String taskConfigurationString) {
+
+    if (taskConfigurationString.isEmpty()) {
+      throw new RuntimeException("empty taskConfigurationString provided.");
+    }
+    ClassHierarchy clrClassHierarchy = Utilities.loadClassHierarchy(NativeInterop.CLASS_HIERARCHY_FILENAME);
+    Configuration taskConfiguration;
+    try {
+      taskConfiguration = serializer.fromString(taskConfigurationString, clrClassHierarchy);
+    } catch (final Exception e) {
+      final String message = "Unable to de-serialize CLR  task configurations using class hierarchy.";
+      LOG.log(Level.SEVERE, message, e);
+      throw new RuntimeException(message, e);
+    }
+    jactiveContext.submitTask(taskConfiguration);
+  }
+
+  public String getEvaluatorDescriptorSring() {
+    final String descriptorString = Utilities.getEvaluatorDescriptorString(jactiveContext.getEvaluatorDescriptor());
+    LOG.log(Level.FINE, "active context - serialized evaluator descriptor: " + descriptorString);
+    return descriptorString;
+  }
+
+  @Override
+  public void close() {
+    jactiveContext.close();
+  }
+
+  @Override
+  public String getId() {
+    return contextId;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/AllocatedEvaluatorBridge.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/AllocatedEvaluatorBridge.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/AllocatedEvaluatorBridge.java
new file mode 100644
index 0000000..5d88355
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/AllocatedEvaluatorBridge.java
@@ -0,0 +1,141 @@
+/**
+ * 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.reef.javabridge;
+
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.formats.AvroConfigurationSerializer;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class AllocatedEvaluatorBridge extends NativeBridge {
+
+  private static final Logger LOG = Logger.getLogger(AllocatedEvaluatorBridge.class.getName());
+
+  private final AllocatedEvaluator jallocatedEvaluator;
+  private final AvroConfigurationSerializer serializer;
+  private final ClassHierarchy clrClassHierarchy;
+  private final String evaluatorId;
+  private final String nameServerInfo;
+
+  public AllocatedEvaluatorBridge(final AllocatedEvaluator allocatedEvaluator, final String serverInfo) {
+    jallocatedEvaluator = allocatedEvaluator;
+    serializer = new AvroConfigurationSerializer();
+    clrClassHierarchy = Utilities.loadClassHierarchy(NativeInterop.CLASS_HIERARCHY_FILENAME);
+    evaluatorId = allocatedEvaluator.getId();
+    nameServerInfo = serverInfo;
+  }
+
+  public void submitContextAndTaskString(final String contextConfigurationString, final String taskConfigurationString) {
+    if (contextConfigurationString.isEmpty()) {
+      throw new RuntimeException("empty contextConfigurationString provided.");
+    }
+    if (taskConfigurationString.isEmpty()) {
+      throw new RuntimeException("empty taskConfigurationString provided.");
+    }
+    Configuration contextConfiguration;
+    Configuration taskConfiguration;
+    try {
+      contextConfiguration = serializer.fromString(contextConfigurationString, clrClassHierarchy);
+      taskConfiguration = serializer.fromString(taskConfigurationString, clrClassHierarchy);
+    } catch (final Exception e) {
+      final String message = "Unable to de-serialize CLR context or task configurations using class hierarchy.";
+      LOG.log(Level.SEVERE, message, e);
+      throw new RuntimeException(message, e);
+    }
+    jallocatedEvaluator.submitContextAndTask(contextConfiguration, taskConfiguration);
+  }
+
+  public void submitContextString(final String contextConfigurationString) {
+    if (contextConfigurationString.isEmpty()) {
+      throw new RuntimeException("empty contextConfigurationString provided.");
+    }
+    Configuration contextConfiguration;
+    try {
+      contextConfiguration = serializer.fromString(contextConfigurationString, clrClassHierarchy);
+    } catch (final Exception e) {
+      final String message = "Unable to de-serialize CLR context configurations using class hierarchy.";
+      LOG.log(Level.SEVERE, message, e);
+      throw new RuntimeException(message, e);
+    }
+    jallocatedEvaluator.submitContext(contextConfiguration);
+  }
+
+  public void submitContextAndServiceString(final String contextConfigurationString, final String serviceConfigurationString) {
+    if (contextConfigurationString.isEmpty()) {
+      throw new RuntimeException("empty contextConfigurationString provided.");
+    }
+    if (serviceConfigurationString.isEmpty()) {
+      throw new RuntimeException("empty serviceConfigurationString provided.");
+    }
+
+    Configuration contextConfiguration;
+    Configuration servicetConfiguration;
+    try {
+      contextConfiguration = serializer.fromString(contextConfigurationString, clrClassHierarchy);
+      servicetConfiguration = serializer.fromString(serviceConfigurationString, clrClassHierarchy);
+    } catch (final Exception e) {
+      final String message = "Unable to de-serialize CLR context or service  configurations using class hierarchy.";
+      LOG.log(Level.SEVERE, message, e);
+      throw new RuntimeException(message, e);
+    }
+    jallocatedEvaluator.submitContextAndService(contextConfiguration, servicetConfiguration);
+  }
+
+  public void submitContextAndServiceAndTaskString(
+      final String contextConfigurationString,
+      final String serviceConfigurationString,
+      final String taskConfigurationString) {
+    if (contextConfigurationString.isEmpty()) {
+      throw new RuntimeException("empty contextConfigurationString provided.");
+    }
+    if (serviceConfigurationString.isEmpty()) {
+      throw new RuntimeException("empty serviceConfigurationString provided.");
+    }
+    if (taskConfigurationString.isEmpty()) {
+      throw new RuntimeException("empty taskConfigurationString provided.");
+    }
+    Configuration contextConfiguration;
+    Configuration servicetConfiguration;
+    Configuration taskConfiguration;
+    try {
+      contextConfiguration = serializer.fromString(contextConfigurationString, clrClassHierarchy);
+      servicetConfiguration = serializer.fromString(serviceConfigurationString, clrClassHierarchy);
+      taskConfiguration = serializer.fromString(taskConfigurationString, clrClassHierarchy);
+    } catch (final Exception e) {
+      final String message = "Unable to de-serialize CLR context or service or task configurations using class hierarchy.";
+      LOG.log(Level.SEVERE, message, e);
+      throw new RuntimeException(message, e);
+    }
+    jallocatedEvaluator.submitContextAndServiceAndTask(contextConfiguration, servicetConfiguration, taskConfiguration);
+  }
+
+  public String getEvaluatorDescriptorSring() {
+    String descriptorString = Utilities.getEvaluatorDescriptorString(jallocatedEvaluator.getEvaluatorDescriptor());
+    LOG.log(Level.INFO, "allocated evaluator - serialized evaluator descriptor: " + descriptorString);
+    return descriptorString;
+  }
+
+  @Override
+  public void close() {
+    jallocatedEvaluator.close();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ClosedContextBridge.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ClosedContextBridge.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ClosedContextBridge.java
new file mode 100644
index 0000000..62f9ce7
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ClosedContextBridge.java
@@ -0,0 +1,81 @@
+/**
+ * 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.reef.javabridge;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ClosedContext;
+import org.apache.reef.driver.evaluator.EvaluatorDescriptor;
+import org.apache.reef.util.Optional;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class ClosedContextBridge extends NativeBridge implements ClosedContext {
+
+  private static final Logger LOG = Logger.getLogger(ClosedContextBridge.class.getName());
+
+  private final ClosedContext jcloseContext;
+  private final ActiveContextBridge parentContext;
+  private final String contextId;
+  private final String evaluatorId;
+  private final EvaluatorDescriptor evaluatorDescriptor;
+
+  public ClosedContextBridge(final ClosedContext closedContext) {
+    jcloseContext = closedContext;
+    parentContext = new ActiveContextBridge(closedContext.getParentContext());
+    contextId = closedContext.getId();
+    evaluatorId = closedContext.getEvaluatorId();
+    evaluatorDescriptor = closedContext.getEvaluatorDescriptor();
+  }
+
+  @Override
+  public String getId() {
+    return contextId;
+  }
+
+  @Override
+  public String getEvaluatorId() {
+    return evaluatorId;
+  }
+
+  @Override
+  public Optional<String> getParentId() {
+    return Optional.of(parentContext.getId());
+  }
+
+  @Override
+  public EvaluatorDescriptor getEvaluatorDescriptor() {
+    return evaluatorDescriptor;
+  }
+
+  @Override
+  public void close() throws Exception {
+  }
+
+  public String getEvaluatorDescriptorSring() {
+    String descriptorString = Utilities.getEvaluatorDescriptorString(evaluatorDescriptor);
+    LOG.log(Level.INFO, "Closed Context - serialized evaluator descriptor: " + descriptorString);
+    return descriptorString;
+  }
+
+  @Override
+  public ActiveContext getParentContext() {
+    return jcloseContext.getParentContext();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/CompletedEvaluatorBridge.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/CompletedEvaluatorBridge.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/CompletedEvaluatorBridge.java
new file mode 100644
index 0000000..0e300fd
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/CompletedEvaluatorBridge.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.javabridge;
+
+import org.apache.reef.driver.evaluator.CompletedEvaluator;
+import org.apache.reef.io.naming.Identifiable;
+
+public class CompletedEvaluatorBridge extends NativeBridge implements Identifiable {
+
+  private final CompletedEvaluator jcompletedEvaluator;
+
+  private final String evaluatorId;
+
+  public CompletedEvaluatorBridge(CompletedEvaluator completedEvaluator) {
+    jcompletedEvaluator = completedEvaluator;
+    evaluatorId = completedEvaluator.getId();
+  }
+
+  @Override
+  public String getId() {
+    return evaluatorId;
+  }
+
+  @Override
+  public void close() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/CompletedTaskBridge.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/CompletedTaskBridge.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/CompletedTaskBridge.java
new file mode 100644
index 0000000..c95ca14
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/CompletedTaskBridge.java
@@ -0,0 +1,40 @@
+/**
+ * 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.reef.javabridge;
+
+import org.apache.reef.driver.task.CompletedTask;
+
+public class CompletedTaskBridge extends NativeBridge {
+
+  private CompletedTask jcompletedTask;
+
+  private String taskId;
+
+  private ActiveContextBridge jactiveContext;
+
+  public CompletedTaskBridge(CompletedTask completedTask) {
+    jcompletedTask = completedTask;
+    taskId = completedTask.getId();
+    jactiveContext = new ActiveContextBridge(completedTask.getActiveContext());
+  }
+
+  @Override
+  public void close() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ContextMessageBridge.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ContextMessageBridge.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ContextMessageBridge.java
new file mode 100644
index 0000000..eca4ba8
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/ContextMessageBridge.java
@@ -0,0 +1,56 @@
+/**
+ * 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.reef.javabridge;
+
+import org.apache.reef.driver.context.ContextMessage;
+
+public class ContextMessageBridge extends NativeBridge implements ContextMessage {
+
+  private ContextMessage jcontextMessage;
+  private String contextMessageId;
+  private String messageSourceId;
+  private byte[] message;
+
+  public ContextMessageBridge(ContextMessage contextMessage) {
+    jcontextMessage = contextMessage;
+    contextMessageId = contextMessage.getId();
+    messageSourceId = contextMessage.getMessageSourceID();
+    message = contextMessage.get();
+  }
+
+  @Override
+  public void close() throws Exception {
+
+  }
+
+  @Override
+  public byte[] get() {
+    return message;
+  }
+
+  @Override
+  public String getId() {
+    return contextMessageId;
+  }
+
+  @Override
+  public String getMessageSourceID() {
+    return messageSourceId;
+  }
+}


[02/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/EStage.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/EStage.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/EStage.java
new file mode 100644
index 0000000..5e79d39
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/EStage.java
@@ -0,0 +1,27 @@
+/**
+ * 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.reef.wake;
+
+/**
+ * Stage that executes an event handler
+ *
+ * @param <T> type
+ */
+public interface EStage<T> extends EventHandler<T>, Stage {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/EventHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/EventHandler.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/EventHandler.java
new file mode 100644
index 0000000..871e64e
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/EventHandler.java
@@ -0,0 +1,34 @@
+/**
+ * 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.reef.wake;
+
+/**
+ * Handler to process an event
+ *
+ * @param <T> type
+ */
+public interface EventHandler<T> {
+
+  /**
+   * Handles an event
+   *
+   * @param value an event
+   */
+  public void onNext(T value);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/Identifiable.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/Identifiable.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/Identifiable.java
new file mode 100644
index 0000000..784dafb
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/Identifiable.java
@@ -0,0 +1,30 @@
+/**
+ * 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.reef.wake;
+
+public interface Identifiable {
+
+  /**
+   * Returns an identifier of this object
+   *
+   * @return an identifier of this object
+   */
+  public Identifier getId();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/Identifier.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/Identifier.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/Identifier.java
new file mode 100644
index 0000000..377b23e
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/Identifier.java
@@ -0,0 +1,54 @@
+/**
+ * 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.reef.wake;
+
+/*
+ * An identifier class for REEF.  Identifiers are a generic naming primitive
+ * that carry some information about the type of the object they point to.
+ * Typical examples are server sockets, filenames, and requests.
+ * 
+ * Identifier constructors should take zero arguments, or take a single string.
+ * 
+ */
+public interface Identifier {
+
+  /**
+   * Returns a hash code for the object
+   *
+   * @return a hash code value for this object
+   */
+  public int hashCode();
+
+  /**
+   * Checks that another object is equal to this object
+   *
+   * @param o another object
+   * @return true if the object is the same as the object argument; false,
+   * otherwise
+   */
+  public boolean equals(Object o);
+
+  /**
+   * Return a string representation of this object. This method should return a
+   * URL-style string, that begins with "type://", where "type" is chosen to
+   * uniquely identify this type of identifier.
+   */
+  public String toString();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/IdentifierFactory.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/IdentifierFactory.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/IdentifierFactory.java
new file mode 100644
index 0000000..828eda9
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/IdentifierFactory.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.wake;
+
+public interface IdentifierFactory {
+
+  /**
+   * Creates a RemoteIdentifier object
+   *
+   * @param str a string
+   * @return an identifier
+   */
+  public Identifier getNewInstance(String str);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/IdentifierParser.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/IdentifierParser.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/IdentifierParser.java
new file mode 100644
index 0000000..a2e7df9
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/IdentifierParser.java
@@ -0,0 +1,55 @@
+/**
+ * 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.reef.wake;
+
+import org.apache.reef.tang.ExternalConstructor;
+import org.apache.reef.wake.impl.DefaultIdentifierFactory;
+import org.apache.reef.wake.remote.impl.SocketRemoteIdentifier;
+import org.apache.reef.wake.storage.FileIdentifier;
+
+import javax.inject.Inject;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class IdentifierParser implements ExternalConstructor<Identifier> {
+  private static final IdentifierFactory factory;
+
+  // TODO: Modify tang to allow this to use a factory pattern.
+  static {
+    Map<String, Class<? extends Identifier>> map = new ConcurrentHashMap<>();
+
+    map.put("socket", SocketRemoteIdentifier.class);
+    map.put("file", FileIdentifier.class);
+
+    factory = new DefaultIdentifierFactory(map);
+  }
+
+  final Identifier id;
+
+  @Inject
+  IdentifierParser(String s) {
+    id = factory.getNewInstance(s);
+  }
+
+  @Override
+  public Identifier newInstance() {
+    return id;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/Stage.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/Stage.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/Stage.java
new file mode 100644
index 0000000..df79d0f
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/Stage.java
@@ -0,0 +1,25 @@
+/**
+ * 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.reef.wake;
+
+/**
+ * Stage is an execution unit for events and provides a way to reclaim its resources
+ */
+public interface Stage extends AutoCloseable {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/StageConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/StageConfiguration.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/StageConfiguration.java
new file mode 100644
index 0000000..0ccbb3a
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/StageConfiguration.java
@@ -0,0 +1,68 @@
+/**
+ * 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.reef.wake;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.rx.Observer;
+
+import java.util.concurrent.ExecutorService;
+
+/**
+ * Configuration options for Wake Stage
+ */
+public final class StageConfiguration {
+
+  @NamedParameter(doc = "The stage name.")
+  public static final class StageName implements Name<String> {
+  }
+
+  @NamedParameter(doc = "The event handler for the stage.")
+  public static final class StageHandler implements Name<EventHandler<?>> {
+  }
+
+  @NamedParameter(doc = "The error handler for the stage.")
+  public static final class ErrorHandler implements Name<EventHandler<Throwable>> {
+  }
+
+  @NamedParameter(doc = "The number of threads for the stage.")
+  public static final class NumberOfThreads implements Name<Integer> {
+  }
+
+  @NamedParameter(doc = "The capacity for the stage.")
+  public static final class Capacity implements Name<Integer> {
+  }
+
+  @NamedParameter(doc = "The executor service for the stage.")
+  public static final class StageExecutorService implements Name<ExecutorService> {
+  }
+
+  @NamedParameter(doc = "The initial delay for periodic events of the timer stage.")
+  public static final class TimerInitialDelay implements Name<Long> {
+  }
+
+  @NamedParameter(doc = "The period for periodic events of the timer stage.")
+  public static final class TimerPeriod implements Name<Long> {
+  }
+
+  @NamedParameter(doc = "The observer for the stage.")
+  public static final class StageObserver implements Name<Observer<?>> {
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/WakeConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/WakeConfiguration.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/WakeConfiguration.java
new file mode 100644
index 0000000..7adee0b
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/WakeConfiguration.java
@@ -0,0 +1,62 @@
+/**
+ * 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.reef.wake;
+
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.formats.ConfigurationFile;
+import org.apache.reef.wake.exception.WakeRuntimeException;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Wake parameter configuration
+ */
+public final class WakeConfiguration {
+  private final static Logger LOG = Logger.getLogger(WakeConfiguration.class.getName());
+
+  @Inject
+  public WakeConfiguration(final @Parameter(FileName.class) String confFileName) {
+    if (confFileName.equals("")) {
+      LOG.log(Level.WARNING, "The Wake configuration file is not specified.");
+    } else {
+      Tang t = Tang.Factory.getTang();
+      JavaConfigurationBuilder cb = t.newConfigurationBuilder();
+      try {
+        ConfigurationFile.addConfiguration(cb, new File(confFileName));
+      } catch (BindException e) {
+        throw new WakeRuntimeException(e);
+      } catch (IOException e) {
+        throw new WakeRuntimeException(e);
+      }
+    }
+  }
+
+  @NamedParameter(doc = "Configuration file name", default_value = "")
+  public final static class FileName implements Name<String> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/WakeParameters.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/WakeParameters.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/WakeParameters.java
new file mode 100644
index 0000000..897cc08
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/WakeParameters.java
@@ -0,0 +1,46 @@
+/**
+ * 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.reef.wake;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/*
+ * Default parameters for Wake
+ */
+public final class WakeParameters {
+
+  public final static int MAX_FRAME_LENGTH = 1 * 1024 * 1024;
+
+  public final static long EXECUTOR_SHUTDOWN_TIMEOUT = 1000;
+
+  public final static long REMOTE_EXECUTOR_SHUTDOWN_TIMEOUT = 10000;
+
+  @NamedParameter(doc = "Maximum frame length unit", default_value = "" + MAX_FRAME_LENGTH)
+  public final static class MaxFrameLength implements Name<Integer> {
+  }
+
+  @NamedParameter(doc = "Executor shutdown timeout", default_value = "" + EXECUTOR_SHUTDOWN_TIMEOUT)
+  public final static class ExecutorShutdownTimeout implements Name<Integer> {
+  }
+
+  @NamedParameter(doc = "Remote send timeout", default_value = "" + REMOTE_EXECUTOR_SHUTDOWN_TIMEOUT)
+  public final static class RemoteSendTimeout implements Name<Integer> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/accumulate/CombinerStage.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/accumulate/CombinerStage.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/accumulate/CombinerStage.java
new file mode 100644
index 0000000..63b4d30
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/accumulate/CombinerStage.java
@@ -0,0 +1,161 @@
+/**
+ * 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.reef.wake.examples.accumulate;
+
+
+import org.apache.reef.wake.Stage;
+import org.apache.reef.wake.rx.Observer;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentSkipListMap;
+
+public class CombinerStage<K extends Comparable<K>, V> implements Stage {
+
+  private final Combiner<K, V> c;
+  private final Observer<Map.Entry<K, V>> o;
+  private final OutputThread worker = new OutputThread();
+  private final ConcurrentSkipListMap<K, V> register = new ConcurrentSkipListMap<>();
+  private volatile boolean done = false;
+
+  public CombinerStage(Combiner<K, V> c, Observer<Map.Entry<K, V>> o) {
+    this.c = c;
+    this.o = o;
+    worker.start();
+  }
+
+  public Observer<Map.Entry<K, V>> wireIn() {
+    return new Observer<Map.Entry<K, V>>() {
+      @Override
+      public void onNext(Map.Entry<K, V> pair) {
+        V old;
+        V newVal;
+        boolean wasEmpty = register.isEmpty();
+        boolean succ = false;
+
+        while (!succ) {
+          old = register.get(pair.getKey());
+          newVal = c.combine(pair.getKey(), old, pair.getValue());
+          if (old == null) {
+            succ = (null == register.putIfAbsent(pair.getKey(), newVal));
+          } else {
+            succ = register.replace(pair.getKey(), old, newVal);
+          }
+        }
+
+        if (wasEmpty) {
+          synchronized (register) {
+            register.notify();
+          }
+        }
+      }
+
+      @Override
+      public void onError(Exception error) {
+        o.onError(error);
+      }
+
+      @Override
+      public void onCompleted() {
+        synchronized (register) {
+          done = true;
+          if (register.isEmpty()) {
+            register.notify();
+          }
+        }
+      }
+    };
+  }
+
+  @Override
+  public void close() throws Exception {
+    worker.join();
+  }
+
+  public interface Combiner<K extends Comparable<K>, V> {
+    V combine(K key, V old, V cur);
+  }
+
+  public static class Pair<K extends Comparable<K>, V> implements Map.Entry<K, V>, Comparable<Map.Entry<K, V>> {
+    private final K k;
+    private final V v;
+
+    public Pair(K k, V v) {
+      this.k = k;
+      this.v = v;
+    }
+
+    @Override
+    public int compareTo(Map.Entry<K, V> arg0) {
+      return k.compareTo(arg0.getKey());
+    }
+
+    @Override
+    public K getKey() {
+      return k;
+    }
+
+    @Override
+    public V getValue() {
+      return v;
+    }
+
+    @Override
+    public V setValue(V value) {
+      throw new UnsupportedOperationException();
+    }
+  }
+
+  private class OutputThread extends Thread {
+    public OutputThread() {
+      super("grouper-output-thread");
+    }
+
+    @Override
+    public void run() {
+      while (true) {
+        if (register.isEmpty()) {
+          synchronized (register) {
+            while (register.isEmpty() && !done) {
+              try {
+                register.wait();
+              } catch (InterruptedException e) {
+                throw new IllegalStateException(e);
+              }
+            }
+            if (done) {
+              break;
+            }
+          }
+        }
+        Map.Entry<K, V> cursor = register.pollFirstEntry();
+        while (cursor != null) {
+          o.onNext(cursor);
+          K nextKey = register.higherKey(cursor.getKey());
+
+          /* If there is more than one OutputThread worker then the remove() -> null case
+           * must be handled
+           */
+          cursor = (nextKey == null) ? null : new Pair<>(nextKey, register.remove(nextKey));
+        }
+      }
+      o.onCompleted();
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/BlockingJoin.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/BlockingJoin.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/BlockingJoin.java
new file mode 100644
index 0000000..a5f0ba6
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/BlockingJoin.java
@@ -0,0 +1,95 @@
+/**
+ * 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.reef.wake.examples.join;
+
+import org.apache.reef.wake.rx.Observer;
+import org.apache.reef.wake.rx.StaticObservable;
+
+import java.util.concurrent.ConcurrentSkipListSet;
+
+
+public class BlockingJoin implements StaticObservable {
+  private final Observer<TupleEvent> out;
+  private final ConcurrentSkipListSet<TupleEvent> left = new ConcurrentSkipListSet<>();
+  boolean leftDone = false;
+
+  public BlockingJoin(Observer<TupleEvent> out) {
+    this.out = out;
+  }
+
+  private synchronized void tellEveryoneLeftIsDone() {
+    leftDone = true;
+    notifyAll();
+  }
+
+  private synchronized void waitUntilLeftIsDone() {
+    while (!leftDone) {
+      try {
+        wait();
+      } catch (InterruptedException e) {
+        throw new IllegalStateException(
+            "No support for interrupted threads here!", e);
+      }
+    }
+  }
+
+  public Observer<TupleEvent> wireLeft() {
+    return new Observer<TupleEvent>() {
+
+      @Override
+      public void onNext(TupleEvent value) {
+        left.add(value);
+      }
+
+      @Override
+      public void onError(Exception error) {
+
+      }
+
+      @Override
+      public void onCompleted() {
+        tellEveryoneLeftIsDone();
+      }
+
+    };
+  }
+
+  public Observer<TupleEvent> wireRight() {
+    return new Observer<TupleEvent>() {
+
+      @Override
+      public void onNext(TupleEvent value) {
+        if (!leftDone) waitUntilLeftIsDone();
+        if (left.contains(value)) {
+          out.onNext(value);
+        }
+      }
+
+      @Override
+      public void onError(Exception error) {
+      }
+
+      @Override
+      public void onCompleted() {
+        waitUntilLeftIsDone();
+        out.onCompleted();
+      }
+    };
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/EventPrinter.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/EventPrinter.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/EventPrinter.java
new file mode 100644
index 0000000..812be3a
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/EventPrinter.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.wake.examples.join;
+
+import org.apache.reef.wake.rx.Observer;
+
+public class EventPrinter<T> implements Observer<T> {
+
+  @Override
+  public void onNext(T value) {
+    System.out.println(this + ": " + value);
+  }
+
+  @Override
+  public void onError(Exception error) {
+    System.err.println(this + ": " + error);
+  }
+
+  @Override
+  public void onCompleted() {
+    System.out.println(this + ": done!");
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/NonBlockingJoin.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/NonBlockingJoin.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/NonBlockingJoin.java
new file mode 100644
index 0000000..3aa5647
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/NonBlockingJoin.java
@@ -0,0 +1,121 @@
+/**
+ * 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.reef.wake.examples.join;
+
+import org.apache.reef.wake.rx.Observer;
+import org.apache.reef.wake.rx.StaticObservable;
+
+import java.util.concurrent.ConcurrentSkipListSet;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+
+public class NonBlockingJoin implements StaticObservable {
+  private final AtomicBoolean leftDone = new AtomicBoolean(false);
+  private final AtomicBoolean completed = new AtomicBoolean(false);
+  private final AtomicBoolean sentCompleted = new AtomicBoolean(false);
+
+  private final Observer<TupleEvent> out;
+
+  private final ConcurrentSkipListSet<TupleEvent> leftTable = new ConcurrentSkipListSet<TupleEvent>();
+  private final ConcurrentSkipListSet<TupleEvent> rightTable = new ConcurrentSkipListSet<TupleEvent>();
+
+  public NonBlockingJoin(Observer<TupleEvent> out) {
+    this.out = out;
+  }
+
+  private void drainRight() {
+    TupleEvent t;
+    if (leftDone.get()) {
+      while ((t = rightTable.pollFirst()) != null) {
+        if (leftTable.contains(t)) {
+          out.onNext(t);
+        }
+      }
+      if (completed.get()) {
+        // There cannot be any more additions to rightTable after
+        // completed is set to true, so this ensures that rightTable is
+        // really empty. (Someone could have inserted into it during the
+        // race between the previous while loop and the check of
+        // completed.)
+        while ((t = rightTable.pollFirst()) != null) {
+          if (leftTable.contains(t)) {
+            out.onNext(t);
+          }
+        }
+        if (sentCompleted.getAndSet(true) == false) {
+          out.onCompleted();
+        }
+      }
+    }
+  }
+
+  public Observer<TupleEvent> wireLeft() {
+    return new Observer<TupleEvent>() {
+
+      @Override
+      public void onNext(TupleEvent value) {
+        leftTable.add(value);
+      }
+
+      @Override
+      public void onError(Exception error) {
+        leftTable.clear();
+        rightTable.clear();
+        out.onError(error);
+      }
+
+      @Override
+      public void onCompleted() {
+        leftDone.set(true);
+        drainRight();
+      }
+
+    };
+  }
+
+  public Observer<TupleEvent> wireRight() {
+    return new Observer<TupleEvent>() {
+
+      @Override
+      public void onNext(TupleEvent value) {
+        if (leftTable.contains(value)) {
+          out.onNext(value);
+        } else if (!leftDone.get()) {
+          rightTable.add(value);
+        }
+        drainRight();
+      }
+
+      @Override
+      public void onError(Exception error) {
+        leftTable.clear();
+        rightTable.clear();
+        out.onError(error);
+      }
+
+      @Override
+      public void onCompleted() {
+        completed.set(true);
+        drainRight();
+      }
+    };
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/TupleEvent.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/TupleEvent.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/TupleEvent.java
new file mode 100644
index 0000000..978b2de
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/TupleEvent.java
@@ -0,0 +1,45 @@
+/**
+ * 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.reef.wake.examples.join;
+
+
+public class TupleEvent implements Comparable<TupleEvent> {
+  private final int key;
+  private final String val;
+
+  public TupleEvent(int key, String val) {
+    this.key = key;
+    this.val = val;
+  }
+
+  @Override
+  public int compareTo(TupleEvent o) {
+    int keycmp = Integer.compare(key, o.key);
+    if (keycmp != 0) {
+      return keycmp;
+    }
+    return val.compareTo(o.val);
+  }
+
+  @Override
+  public String toString() {
+    return "(" + key + ", " + val + ")";
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/TupleSource.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/TupleSource.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/TupleSource.java
new file mode 100644
index 0000000..378ef3d
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/TupleSource.java
@@ -0,0 +1,58 @@
+/**
+ * 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.reef.wake.examples.join;
+
+import org.apache.reef.wake.Stage;
+import org.apache.reef.wake.rx.Observer;
+import org.apache.reef.wake.rx.StaticObservable;
+
+public class TupleSource implements StaticObservable, Stage {
+  final Thread[] threads;
+  final Observer<TupleEvent> out;
+
+  public TupleSource(final Observer<TupleEvent> out, final int max, final int numThreads, final boolean evenOnly) {
+    this.out = out;
+    threads = new Thread[numThreads];
+    for (int i = 0; i < numThreads; i++) {
+      final int threadid = i;
+      threads[i] = new Thread(new Runnable() {
+        @Override
+        public void run() {
+          for (int i = 0; i < max / ((evenOnly ? 2 : 1) * numThreads); i++) {
+            int j = i * numThreads + threadid;
+            if (evenOnly) {
+              j *= 2;
+            }
+            out.onNext(new TupleEvent(j, j + ""));
+          }
+        }
+
+      });
+      threads[i].start();
+    }
+  }
+
+  @Override
+  public void close() throws Exception {
+    for (Thread t : threads) {
+      t.join();
+    }
+    out.onCompleted();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/package-info.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/package-info.java
new file mode 100644
index 0000000..4012f98
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/join/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.reef.wake.examples.join;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/p2p/EventSource.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/p2p/EventSource.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/p2p/EventSource.java
new file mode 100644
index 0000000..202b321
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/p2p/EventSource.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.wake.examples.p2p;
+
+/**
+ * The pull side of the interface: Clients implement this and register it with
+ * the PullToPush class.
+ *
+ * @param <T> the type of the event
+ */
+public interface EventSource<T> {
+
+  /**
+   * @return a event or null if no more messages are available.
+   */
+  public T getNext();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/p2p/Pull2Push.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/p2p/Pull2Push.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/p2p/Pull2Push.java
new file mode 100644
index 0000000..78e5bbe
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/p2p/Pull2Push.java
@@ -0,0 +1,94 @@
+/**
+ * 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.reef.wake.examples.p2p;
+
+import org.apache.reef.wake.EventHandler;
+
+import java.util.LinkedList;
+import java.util.Queue;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Performs a Pull-to-Push conversion in Wake.
+ * <p/>
+ * The class pulls from a set of event sources, and pushes to a single
+ * EventHandler. If the downstream event handler blocks, this will block,
+ * providing a simple rate limiting scheme.
+ * <p/>
+ * The EventSources are managed in a basic Queue.
+ *
+ * @param <T> the message type
+ */
+public final class Pull2Push<T> implements Runnable, AutoCloseable {
+
+  private final EventHandler<T> output; // The downstream EventHandler
+  private final Queue<EventSource<T>> sources = new LinkedList<>(); // The upstream event sources
+  private boolean closed = false;
+
+  /**
+   * @param output the EventHandler that receives the messages from this
+   *               Pull2Push.
+   */
+  public Pull2Push(final EventHandler<T> output) {
+    this.output = output;
+  }
+
+  /**
+   * Registers an event source.
+   *
+   * @param source The source that will be added to the queue of this
+   *               Pull2Push
+   */
+  public final void register(final EventSource<T> source) {
+    this.sources.add(source);
+  }
+
+  /**
+   * Executes the message loop.
+   */
+  @Override
+  public void run() {
+
+    while (!this.closed) {
+      // Grab the next available message source, if any
+      final EventSource<T> nextSource = sources.poll();
+      if (null != nextSource) {
+        // Grab the next message from that source, if any
+        final T message = nextSource.getNext();
+        if (null != message) {
+          // Add the source to the end of the queue again.
+          sources.add(nextSource);
+          // Send the message. Note that this may block depending on the underlying EventHandler.
+          this.output.onNext(message);
+        } else {
+          // The message source has returned null as the next message. We drop the message source in that case.
+          Logger.getLogger(Pull2Push.class.getName()).log(Level.INFO, "Droping message source {0} from the queue", nextSource.toString());
+        }
+      } else {
+        // No source where available. We could put a wait() here.
+      }
+    }
+  }
+
+  @Override
+  public void close() throws Exception {
+    this.closed = true;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/p2p/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/p2p/package-info.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/p2p/package-info.java
new file mode 100644
index 0000000..773a20f
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/p2p/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * A simple pull to push adapter.
+ */
+package org.apache.reef.wake.examples.p2p;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/package-info.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/package-info.java
new file mode 100644
index 0000000..e02a934
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/examples/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.reef.wake.examples;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/exception/WakeRuntimeException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/exception/WakeRuntimeException.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/exception/WakeRuntimeException.java
new file mode 100644
index 0000000..87aa414
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/exception/WakeRuntimeException.java
@@ -0,0 +1,56 @@
+/**
+ * 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.reef.wake.exception;
+
+/**
+ * Wake runtime exception
+ */
+public class WakeRuntimeException extends RuntimeException {
+
+  private static final long serialVersionUID = 1L;
+
+  /**
+   * Constructs a new runtime wake exception with the specified detail message and cause
+   *
+   * @param s the detailed message
+   * @param e the cause
+   */
+  public WakeRuntimeException(final String s, final Throwable e) {
+    super(s, e);
+  }
+
+  /**
+   * Constructs a new runtime stage exception with the specified detail message
+   *
+   * @param s the detailed message
+   */
+  public WakeRuntimeException(final String s) {
+    super(s);
+  }
+
+  /**
+   * Constructs a new runtime stage exception with the specified cause
+   *
+   * @param e the cause
+   */
+  public WakeRuntimeException(final Throwable e) {
+    super(e);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/exception/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/exception/package-info.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/exception/package-info.java
new file mode 100644
index 0000000..90fddee
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/exception/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.reef.wake.exception;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/BlockingEventHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/BlockingEventHandler.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/BlockingEventHandler.java
new file mode 100644
index 0000000..c5da7a5
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/BlockingEventHandler.java
@@ -0,0 +1,79 @@
+/**
+ * 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.reef.wake.impl;
+
+import org.apache.reef.wake.EventHandler;
+
+import java.util.ArrayList;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * An EventHandler that blocks until a set number of Events has been received.
+ * Once they have been received, the downstream event handler is called with an
+ * Iterable of the events spooled.
+ * <p/>
+ * onNext is thread safe
+ *
+ * @param <T> type of events
+ * @see BlockingSignalEventHandler
+ */
+public final class BlockingEventHandler<T> implements EventHandler<T> {
+
+  private final int expectedSize;
+  private final EventHandler<Iterable<T>> destination;
+  private final AtomicInteger cursor;
+  // TODO: a queue is likely overly conservative given that we only need
+  // to preserve order of those pairs of events that didn't race (have an ordering)
+  private BlockingQueue<T> events = new LinkedBlockingQueue<>();
+
+  public BlockingEventHandler(final int expectedSize, final EventHandler<Iterable<T>> destination) {
+    this.expectedSize = expectedSize;
+    this.destination = destination;
+    this.cursor = new AtomicInteger(0);
+  }
+
+  @Override
+  public final void onNext(final T event) {
+    this.events.add(event);
+    int newCursor = this.cursor.incrementAndGet();
+
+    if (newCursor % expectedSize == 0) {
+      // FIXME: There is a race here where the person draining the events might
+      // not include their event as the last one. I'm going to assume this does not
+      // matter, since all events will still be drained exactly once by someone in
+      // the proper order
+
+      ArrayList<T> nonConcurrent = new ArrayList<>(expectedSize);
+      synchronized (events) {
+
+        // drainTo(maxElements) does not suffice because it has undefined behavior for
+        // any modifications (a better spec would possibly be undefined behavior except for appends)
+
+        // TODO: a non-locking implementation will simply atomically update the head of the 
+        // queue to index=expectedSize, so that the drainer may drain without synchronization
+        for (int i = 0; i < expectedSize; i++) {
+          nonConcurrent.add(events.poll());
+        }
+      }
+      this.destination.onNext(nonConcurrent);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/BlockingSignalEventHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/BlockingSignalEventHandler.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/BlockingSignalEventHandler.java
new file mode 100644
index 0000000..e590852
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/BlockingSignalEventHandler.java
@@ -0,0 +1,56 @@
+/**
+ * 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.reef.wake.impl;
+
+import org.apache.reef.wake.EventHandler;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * An EventHandler that blocks until a set number of Events has been received.
+ * Once they have been received, the downstream event handler is called with
+ * the <i>last event</i> received. The handler resets atomically to start
+ * receiving the next batch of events.
+ * <p/>
+ * onNext is thread safe
+ *
+ * @param <T> type of events
+ * @see BlockingEventHandler
+ */
+public final class BlockingSignalEventHandler<T> implements EventHandler<T> {
+
+  private final int expectedSize;
+  private final EventHandler<T> destination;
+  private final AtomicInteger cursor;
+
+  public BlockingSignalEventHandler(final int expectedSize, final EventHandler<T> destination) {
+    this.expectedSize = expectedSize;
+    this.destination = destination;
+    this.cursor = new AtomicInteger(0);
+  }
+
+  @Override
+  public final void onNext(final T event) {
+    int newSize = this.cursor.incrementAndGet();
+
+    if (newSize % expectedSize == 0) {
+      this.destination.onNext(event);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/DefaultIdentifierFactory.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/DefaultIdentifierFactory.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/DefaultIdentifierFactory.java
new file mode 100644
index 0000000..a186659
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/DefaultIdentifierFactory.java
@@ -0,0 +1,90 @@
+/**
+ * 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.reef.wake.impl;
+
+import org.apache.reef.wake.Identifier;
+import org.apache.reef.wake.IdentifierFactory;
+import org.apache.reef.wake.remote.exception.RemoteRuntimeException;
+import org.apache.reef.wake.remote.impl.SocketRemoteIdentifier;
+
+import javax.inject.Inject;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Default remote identifier factory that creates a specific remote identifier
+ * from a string representation
+ * <p/>
+ * A string representation is broken into two parts type and type-specific details separated by "://"
+ * A remote identifier implementation should implement a constructor that accepts a string.
+ * The factory invokes a proper constructor by reflection.
+ */
+public class DefaultIdentifierFactory implements IdentifierFactory {
+
+  // map between type and remote identifier class
+  private final Map<String, Class<? extends Identifier>> typeToClazzMap;
+
+  /**
+   * Constructs a default remote identifier factory
+   */
+  @Inject
+  public DefaultIdentifierFactory() {
+    typeToClazzMap = new HashMap<>();
+    typeToClazzMap.put("socket", SocketRemoteIdentifier.class);
+  }
+
+  /**
+   * Constructs a default remote identifier factory
+   *
+   * @param typeToClazzMap the map of type strings to classes of remote identifiers
+   */
+  public DefaultIdentifierFactory(Map<String, Class<? extends Identifier>> typeToClazzMap) {
+    this.typeToClazzMap = typeToClazzMap;
+  }
+
+  /**
+   * Creates a new remote identifier instance
+   *
+   * @param str a string representation
+   * @return a remote identifier
+   * @throws RemoteRuntimeException
+   */
+  @Override
+  public Identifier getNewInstance(String str) {
+    int index = str.indexOf("://");
+    if (index < 0)
+      throw new RemoteRuntimeException("Invalid name " + str);
+    String type = str.substring(0, index);
+    Class<? extends Identifier> clazz = typeToClazzMap.get(type);
+    Class<?>[] argTypes = {String.class};
+    Constructor<? extends Identifier> constructor;
+    try {
+      constructor = clazz.getDeclaredConstructor(argTypes);
+      Object[] args = new Object[1];
+      args[0] = str.substring(index + 3);
+      return constructor.newInstance(args);
+    } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+      e.printStackTrace();
+      throw new RemoteRuntimeException(e);
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/DefaultThreadFactory.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/DefaultThreadFactory.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/DefaultThreadFactory.java
new file mode 100644
index 0000000..71c123e
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/DefaultThreadFactory.java
@@ -0,0 +1,85 @@
+/**
+ * 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.reef.wake.impl;
+
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * A default thread factory implementation that names created threads
+ */
+public final class DefaultThreadFactory implements ThreadFactory {
+  private static final AtomicInteger poolNumber = new AtomicInteger(1);
+  private final ThreadGroup group;
+  private final AtomicInteger threadNumber = new AtomicInteger(1);
+  private final String prefix;
+  private Thread.UncaughtExceptionHandler uncaughtExceptionHandler;
+
+  /**
+   * Constructs a default thread factory
+   *
+   * @param prefix the name prefix of the created thread
+   */
+  public DefaultThreadFactory(String prefix) {
+    SecurityManager s = System.getSecurityManager();
+    this.group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
+    this.prefix = prefix + "-pool-" + poolNumber.getAndIncrement() + "-thread-";
+    this.uncaughtExceptionHandler = null;
+  }
+
+  /**
+   * Constructs a default thread factory
+   *
+   * @param prefix                   the name prefix of the created thread
+   * @param uncaughtExceptionHandler the uncaught exception handler of the created thread
+   */
+  public DefaultThreadFactory(String prefix, Thread.UncaughtExceptionHandler uncaughtExceptionHandler) {
+    SecurityManager s = System.getSecurityManager();
+    this.group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
+    this.prefix = prefix + "-pool-" + poolNumber.getAndIncrement() + "-thread-";
+    this.uncaughtExceptionHandler = uncaughtExceptionHandler;
+  }
+
+  /**
+   * Sets a uncaught exception handler
+   *
+   * @param uncaughtExceptionHandler the uncaught exception handler
+   */
+  public void setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler uncaughtExceptionHandler) {
+    this.uncaughtExceptionHandler = uncaughtExceptionHandler;
+  }
+
+  /**
+   * Creates a new thread
+   *
+   * @param r the runnable
+   */
+  @Override
+  public Thread newThread(Runnable r) {
+    Thread t = new Thread(group, r, prefix + threadNumber.getAndIncrement(), 0);
+    if (t.isDaemon())
+      t.setDaemon(false);
+    if (t.getPriority() != Thread.NORM_PRIORITY)
+      t.setPriority(Thread.NORM_PRIORITY);
+    if (uncaughtExceptionHandler != null)
+      t.setUncaughtExceptionHandler(uncaughtExceptionHandler);
+    return t;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/ForkPoolStage.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/ForkPoolStage.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/ForkPoolStage.java
new file mode 100644
index 0000000..214beb8
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/ForkPoolStage.java
@@ -0,0 +1,103 @@
+/**
+ * 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.reef.wake.impl;
+
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.AbstractEStage;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.StageConfiguration;
+
+import javax.inject.Inject;
+import java.util.concurrent.ForkJoinTask;
+import java.util.logging.Logger;
+
+/**
+ * This Wake event handling stage uses a {@link ForkJoinPool}
+ * to submit tasks. The advantage is that underlying workers
+ * have separate queues instead of sharing one. The queues are load
+ * balanced with work stealing.
+ * <p/>
+ * The pool is provided to the constructor, so multiple stages
+ * may use the same pool.
+ * <p/>
+ * Some advantage in throughput over other stage implementations should be seen
+ * when one wake stage is submitting to another using the same
+ * {@link WakeSharedPool}. In this case, the new event may be executed
+ * directly by that thread.
+ *
+ * @param <T> type of events
+ */
+public class ForkPoolStage<T> extends AbstractEStage<T> {
+  private static final Logger LOG = Logger.getLogger(ForkPoolStage.class.getName());
+
+  private final EventHandler<T> handler;
+  private final WakeSharedPool pool;
+
+  @Inject
+  public ForkPoolStage(@Parameter(StageConfiguration.StageName.class) String stageName,
+                       @Parameter(StageConfiguration.StageHandler.class) EventHandler<T> handler,
+                       WakeSharedPool sharedPool
+  ) {
+    super(stageName);
+    this.pool = sharedPool;
+    this.handler = handler;
+    //TODO: should WakeSharedPool register its stages?
+
+    StageManager.instance().register(this);
+  }
+
+  @Inject
+  public ForkPoolStage(@Parameter(StageConfiguration.StageHandler.class) EventHandler<T> handler,
+                       WakeSharedPool sharedPool) {
+    this(ForkPoolStage.class.getName(), handler, sharedPool);
+  }
+
+  @Override
+  public void onNext(final T value) {
+    beforeOnNext();
+    pool.submit(new ForkJoinTask<T>() {
+      @Override
+      public T getRawResult() {
+        // tasks have no results because they are events
+        // this may be used for extensions
+        return null;
+      }
+
+      @Override
+      protected void setRawResult(T value) {
+        // tasks have no results because they are events
+        // this may be used for extensions
+      }
+
+      @Override
+      protected boolean exec() {
+        handler.onNext(value);
+        afterOnNext();
+        return true;
+      }
+    });
+  }
+
+
+  @Override
+  public void close() throws Exception {
+    LOG.warning("close(): " + pool.getClass().getName() + " " + pool + " must really be close()'d");
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/IndependentIterationsThreadPoolStage.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/IndependentIterationsThreadPoolStage.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/IndependentIterationsThreadPoolStage.java
new file mode 100644
index 0000000..557d82c
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/IndependentIterationsThreadPoolStage.java
@@ -0,0 +1,80 @@
+/**
+ * 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.reef.wake.impl;
+
+import org.apache.reef.wake.AbstractEStage;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Logger;
+
+/**
+ * This stage uses a thread pool to schedule events in parallel.
+ * Should be used when input events are already materialized in a List and
+ * can be fired in any order.
+ *
+ * @param numThreads  fixed number of threads available in the pool
+ * @param granularity maximum number of events executed serially. The right choice will balance task spawn overhead with parallelism.
+ */
+public class IndependentIterationsThreadPoolStage<T> extends AbstractEStage<List<T>> {
+
+  final private int granularity;
+  private EventHandler<T> handler;
+  private ExecutorService executor;
+
+  public IndependentIterationsThreadPoolStage(EventHandler<T> handler, int numThreads, int granularity) {
+    super(handler.getClass().getName());
+    this.handler = handler;
+    this.executor = Executors.newFixedThreadPool(numThreads);
+    this.granularity = granularity;
+  }
+
+  private Runnable newTask(final List<T> iterations) {
+    return new Runnable() {
+      @Override
+      public void run() {
+        for (T e : iterations) {
+          handler.onNext(e);
+        }
+      }
+    };
+  }
+
+  @Override
+  public void onNext(final List<T> iterations) {
+    Logger.getAnonymousLogger().info("Execute new task [" + iterations.size());
+    final int size = iterations.size();
+    for (int i = 0; i < size; i += granularity) {
+      int toIndex = i + granularity;
+      toIndex = toIndex > size ? size : toIndex;
+      executor.execute(newTask(iterations.subList(i, toIndex)));
+    }
+  }
+
+  @Override
+  public void close() throws Exception {
+    executor.shutdown();
+    executor.awaitTermination(1000, TimeUnit.DAYS);
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/LoggingEventHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/LoggingEventHandler.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/LoggingEventHandler.java
new file mode 100644
index 0000000..86269a4
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/LoggingEventHandler.java
@@ -0,0 +1,49 @@
+/**
+ * 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.reef.wake.impl;
+
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A logging event handler
+ *
+ * @param <T> type
+ */
+public class LoggingEventHandler<T> implements EventHandler<T> {
+  private static final Logger LOG = Logger.getLogger(LoggingEventHandler.class.getName());
+
+  @Inject
+  public LoggingEventHandler() {
+  }
+
+  /**
+   * Logs the event
+   *
+   * @param value an event
+   */
+  @Override
+  public void onNext(T value) {
+    LOG.log(Level.FINE, "{0}", value);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/LoggingUtils.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/LoggingUtils.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/LoggingUtils.java
new file mode 100644
index 0000000..b85c37c
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/LoggingUtils.java
@@ -0,0 +1,52 @@
+/**
+ * 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.reef.wake.impl;
+
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Utility for logging
+ */
+public class LoggingUtils {
+
+  /**
+   * Sets the logging level
+   *
+   * @param level the logging level
+   */
+  public static void setLoggingLevel(Level level) {
+    Handler[] handlers = Logger.getLogger("").getHandlers();
+    ConsoleHandler ch = null;
+    for (Handler h : handlers) {
+      if (h instanceof ConsoleHandler) {
+        ch = (ConsoleHandler) h;
+        break;
+      }
+    }
+    if (ch == null) {
+      ch = new ConsoleHandler();
+      Logger.getLogger("").addHandler(ch);
+    }
+    ch.setLevel(level);
+    Logger.getLogger("").setLevel(level);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/LoggingVoidEventHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/LoggingVoidEventHandler.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/LoggingVoidEventHandler.java
new file mode 100644
index 0000000..d9f923f
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/LoggingVoidEventHandler.java
@@ -0,0 +1,47 @@
+/**
+ * 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.reef.wake.impl;
+
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A logging void event handler
+ */
+public class LoggingVoidEventHandler implements EventHandler<Void> {
+  private static final Logger LOG = Logger.getLogger(LoggingVoidEventHandler.class.getName());
+
+  @Inject
+  public LoggingVoidEventHandler() {
+  }
+
+  /**
+   * Logs the event
+   *
+   * @param value an event
+   */
+  @Override
+  public void onNext(Void value) {
+    LOG.log(Level.FINE, "Logging void event handler");
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/MergingEventHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/MergingEventHandler.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/MergingEventHandler.java
new file mode 100644
index 0000000..548ef0d
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/MergingEventHandler.java
@@ -0,0 +1,152 @@
+/**
+ * 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.reef.wake.impl;
+
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * An EventHandler combines two events of different types into a single Pair of events.
+ * Handler will block until both events are received.
+ * <p/>
+ * onNext is thread safe
+ *
+ * @param <L> type of event
+ * @param <R> type of event
+ * @see BlockingEventHandler
+ */
+@Unit
+public final class MergingEventHandler<L, R> {
+
+  private static Logger LOG = Logger.getLogger(MergingEventHandler.class.getName());
+  public final EventHandler<L> left = new Left();
+  public final EventHandler<R> right = new Right();
+  private final Object mutex = new Object();
+  private final EventHandler<Pair<L, R>> destination;
+  private L leftEvent;
+  private R rightEvent;
+
+  @Inject
+  public MergingEventHandler(final EventHandler<Pair<L, R>> destination) {
+    this.destination = destination;
+    reset();
+  }
+
+  /*
+   * Not thread safe. Must be externally synchronized.
+   */
+  private void reset() {
+    rightEvent = null;
+    leftEvent = null;
+  }
+
+  public static class Pair<S1, S2> {
+    public final S1 first;
+    public final S2 second;
+
+    private Pair(S1 s1, S2 s2) {
+      this.first = s1;
+      this.second = s2;
+    }
+  }
+
+  private class Left implements EventHandler<L> {
+
+    @Override
+    public void onNext(final L event) {
+
+      L leftRef = null;
+      R rightRef = null;
+
+      synchronized (mutex) {
+
+        while (leftEvent != null) {
+          try {
+            mutex.wait();
+          } catch (final InterruptedException e) {
+            LOG.log(Level.SEVERE, "Wait interrupted.", e);
+          }
+        }
+
+        if (LOG.isLoggable(Level.FINEST)) {
+          LOG.log(Level.FINEST, "{0} producing left {1}",
+              new Object[]{Thread.currentThread(), event});
+        }
+
+        leftEvent = event;
+        leftRef = event;
+
+        if (rightEvent != null) {
+          rightRef = rightEvent;
+          reset();
+          mutex.notifyAll();
+        }
+      }
+
+      if (rightRef != null) {
+        // I get to fire the event
+        destination.onNext(new Pair<L, R>(leftRef, rightRef));
+      }
+    }
+  }
+
+  private class Right implements EventHandler<R> {
+
+    @Override
+    public void onNext(final R event) {
+
+      L leftRef = null;
+      R rightRef = null;
+
+      synchronized (mutex) {
+
+        while (rightEvent != null) {
+          try {
+            mutex.wait();
+          } catch (final InterruptedException e) {
+            LOG.log(Level.SEVERE, "Wait interrupted.", e);
+          }
+        }
+
+        if (LOG.isLoggable(Level.FINEST)) {
+          LOG.log(Level.FINEST, "{0} producing right {1}",
+              new Object[]{Thread.currentThread(), event});
+        }
+
+        rightEvent = event;
+        rightRef = event;
+
+        if (leftEvent != null) {
+          leftRef = leftEvent;
+          reset();
+          mutex.notifyAll();
+        }
+      }
+
+      if (leftRef != null) {
+        // I get to fire the event
+        destination.onNext(new Pair<L, R>(leftRef, rightRef));
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/MissingStartHandlerHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/MissingStartHandlerHandler.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/MissingStartHandlerHandler.java
new file mode 100644
index 0000000..6debd97
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/impl/MissingStartHandlerHandler.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.wake.impl;
+
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The EventHandler used as the default for the Clock.StartHandler event.
+ */
+public class MissingStartHandlerHandler implements EventHandler<StartTime> {
+
+  @Inject
+  private MissingStartHandlerHandler() {
+  }
+
+  @Override
+  public void onNext(final StartTime value) {
+    Logger.getLogger(MissingStartHandlerHandler.class.toString())
+        .log(Level.WARNING,
+            "No binding to Clock.StartHandler. It is likely that the clock will immediately go idle and close.");
+  }
+}


[47/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/EvaluatorRequestorBridge.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/EvaluatorRequestorBridge.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/EvaluatorRequestorBridge.java
new file mode 100644
index 0000000..a712fc4
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/EvaluatorRequestorBridge.java
@@ -0,0 +1,76 @@
+/**
+ * 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.reef.javabridge;
+
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.util.logging.LoggingScope;
+import org.apache.reef.util.logging.LoggingScopeFactory;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public final class EvaluatorRequestorBridge extends NativeBridge {
+  private static final Logger LOG = Logger.getLogger(EvaluatorRequestorBridge.class.getName());
+  private final boolean isBlocked;
+  private final EvaluatorRequestor jevaluatorRequestor;
+  private final LoggingScopeFactory loggingScopeFactory;
+
+  // accumulate how many evaluators have been submitted through this instance
+  // of EvaluatorRequestorBridge
+  private int clrEvaluatorsNumber;
+
+  public EvaluatorRequestorBridge(final EvaluatorRequestor evaluatorRequestor, final boolean isBlocked, final LoggingScopeFactory loggingScopeFactory) {
+    this.jevaluatorRequestor = evaluatorRequestor;
+    this.clrEvaluatorsNumber = 0;
+    this.isBlocked = isBlocked;
+    this.loggingScopeFactory = loggingScopeFactory;
+  }
+
+  public void submit(final int evaluatorsNumber, final int memory, final int virtualCore, final String rack) {
+    if (this.isBlocked) {
+      throw new RuntimeException("Cannot request additional Evaluator, this is probably because the Driver has crashed and restarted, and cannot ask for new container due to YARN-2433.");
+    }
+
+    if (rack != null && !rack.isEmpty()) {
+      LOG.log(Level.WARNING, "Ignoring rack preference.");
+    }
+
+    try (final LoggingScope ls = loggingScopeFactory.evaluatorRequestSubmitToJavaDriver(evaluatorsNumber)) {
+      clrEvaluatorsNumber += evaluatorsNumber;
+
+      final EvaluatorRequest request = EvaluatorRequest.newBuilder()
+        .setNumber(evaluatorsNumber)
+        .setMemory(memory)
+        .setNumberOfCores(virtualCore)
+        .build();
+
+      LOG.log(Level.FINE, "submitting evaluator request {0}", request);
+      jevaluatorRequestor.submit(request);
+    }
+  }
+
+  public int getEvaluatorNumber() {
+    return clrEvaluatorsNumber;
+  }
+
+  @Override
+  public void close() {
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/FailedContextBridge.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/FailedContextBridge.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/FailedContextBridge.java
new file mode 100644
index 0000000..dfed7f7
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/FailedContextBridge.java
@@ -0,0 +1,83 @@
+/**
+ * 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.reef.javabridge;
+
+import org.apache.reef.driver.context.ContextBase;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.driver.evaluator.EvaluatorDescriptor;
+import org.apache.reef.util.Optional;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class FailedContextBridge extends NativeBridge implements ContextBase {
+
+  private static final Logger LOG = Logger.getLogger(FailedContextBridge.class.getName());
+
+  private final ActiveContextBridge parentContext;
+  private final EvaluatorDescriptor evaluatorDescriptor;
+  private final String evaluatorId;
+  private final String contextId;
+  private final String parentContextId;
+  private final FailedContext jfailedContext;
+
+  public FailedContextBridge(final FailedContext failedContext) {
+    jfailedContext = failedContext;
+    evaluatorDescriptor = failedContext.getEvaluatorDescriptor();
+    evaluatorId = failedContext.getEvaluatorId();
+    contextId = failedContext.getId();
+    parentContext = failedContext.getParentContext().isPresent() ?
+        new ActiveContextBridge(failedContext.getParentContext().get()) : null;
+    parentContextId = parentContext != null ? parentContext.getId() : null;
+  }
+
+  @Override
+  public void close() throws Exception {
+  }
+
+  @Override
+  public String getId() {
+    return contextId;
+  }
+
+  @Override
+  public String getEvaluatorId() {
+    return evaluatorId;
+  }
+
+  @Override
+  public Optional<String> getParentId() {
+    if (parentContextId != null) {
+      return Optional.of(parentContextId);
+    } else {
+      return Optional.empty();
+    }
+  }
+
+  @Override
+  public EvaluatorDescriptor getEvaluatorDescriptor() {
+    return evaluatorDescriptor;
+  }
+
+  public String getEvaluatorDescriptorSring() {
+    String descriptorString = Utilities.getEvaluatorDescriptorString(evaluatorDescriptor);
+    LOG.log(Level.INFO, "Failed Context - serialized evaluator descriptor: " + descriptorString);
+    return descriptorString;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/FailedEvaluatorBridge.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/FailedEvaluatorBridge.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/FailedEvaluatorBridge.java
new file mode 100644
index 0000000..bae4946
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/FailedEvaluatorBridge.java
@@ -0,0 +1,47 @@
+/**
+ * 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.reef.javabridge;
+
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.driver.evaluator.FailedEvaluator;
+import org.apache.reef.util.logging.LoggingScopeFactory;
+
+import java.util.logging.Logger;
+
+public class FailedEvaluatorBridge extends NativeBridge {
+  private static final Logger LOG = Logger.getLogger(FailedEvaluatorBridge.class.getName());
+  private FailedEvaluator jfailedEvaluator;
+  private EvaluatorRequestorBridge evaluatorRequestorBridge;
+  private String evaluatorId;
+
+  public FailedEvaluatorBridge(FailedEvaluator failedEvaluator, EvaluatorRequestor evaluatorRequestor, boolean blockedForAdditionalEvaluator, final LoggingScopeFactory loggingScopeFactory) {
+    jfailedEvaluator = failedEvaluator;
+    evaluatorId = failedEvaluator.getId();
+    evaluatorRequestorBridge = new EvaluatorRequestorBridge(evaluatorRequestor, blockedForAdditionalEvaluator, loggingScopeFactory);
+  }
+
+  public int getNewlyRequestedEvaluatorNumber() {
+    return evaluatorRequestorBridge.getEvaluatorNumber();
+  }
+
+  @Override
+  public void close() {
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/FailedTaskBridge.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/FailedTaskBridge.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/FailedTaskBridge.java
new file mode 100644
index 0000000..30383ca
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/FailedTaskBridge.java
@@ -0,0 +1,60 @@
+/**
+ * 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.reef.javabridge;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.task.FailedTask;
+import org.apache.reef.util.Optional;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class FailedTaskBridge extends NativeBridge {
+  private static final Logger LOG = Logger.getLogger(FailedTaskBridge.class.getName());
+
+  private FailedTask jfailedTask;
+  private ActiveContextBridge jactiveContext;
+
+  public FailedTaskBridge(FailedTask failedTask) {
+    jfailedTask = failedTask;
+    Optional<ActiveContext> activeContext = failedTask.getActiveContext();
+    jactiveContext = activeContext.isPresent() ? new ActiveContextBridge(activeContext.get()) : null;
+  }
+
+  public String getFailedTaskString() {
+    final String description = jfailedTask.getDescription().isPresent() ? jfailedTask.getDescription().get().replace("=", "").replace(",", "") : "";
+    final String cause = jfailedTask.getReason().isPresent() ? jfailedTask.getReason().get().toString().replace("=", "").replace(",", "") : "";
+    final String data = jfailedTask.getData().isPresent() ? new String(jfailedTask.getData().get()).replace("=", "").replace(",", "") : "";
+
+    // TODO: deserialize/serialize with proper Avro schema
+    final String poorSerializedString = "Identifier=" + jfailedTask.getId().replace("=", "").replace(",", "")
+        + ", Message=" + jfailedTask.getMessage().replace("=", "").replace(",", "")
+        + ", Description=" + description
+        + ", Cause=" + cause
+        + ", Data=" + data;
+
+    LOG.log(Level.INFO, "serialized failed task " + poorSerializedString);
+    return poorSerializedString;
+  }
+
+  @Override
+  public void close() {
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/HttpServerEventBridge.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/HttpServerEventBridge.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/HttpServerEventBridge.java
new file mode 100644
index 0000000..3e8a4e5
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/HttpServerEventBridge.java
@@ -0,0 +1,79 @@
+/**
+ * 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.reef.javabridge;
+
+public final class HttpServerEventBridge extends NativeBridge {
+  private String queryString;
+  private byte[] queryRequestData;
+  private byte[] queryResponseData;
+  private String queryResult;
+  private String uriSpecification;
+
+  public HttpServerEventBridge(final String queryStr) {
+    this.queryString = queryStr;
+  }
+
+  public HttpServerEventBridge(final byte[] queryRequestData) {
+    this.queryRequestData = queryRequestData;
+  }
+
+  public final String getQueryString() {
+    return queryString;
+  }
+
+  public final void setQueryString(final String queryStr) {
+    this.queryString = queryStr;
+  }
+
+  public final String getQueryResult() {
+    return queryResult;
+  }
+
+  public final void setQueryResult(final String queryResult) {
+    this.queryResult = queryResult;
+  }
+
+  public final String getUriSpecification() {
+    return uriSpecification;
+  }
+
+  public final void setUriSpecification(final String uriSpecification) {
+    this.uriSpecification = uriSpecification;
+  }
+
+  public final byte[] getQueryRequestData() {
+    return queryRequestData;
+  }
+
+  public final void setQueryRequestData(final byte[] queryRequestData) {
+    this.queryRequestData = queryRequestData;
+  }
+
+  public final byte[] getQueryResponseData() {
+    return queryResponseData;
+  }
+
+  public final void setQueryResponseData(final byte[] responseData) {
+    queryResponseData = responseData;
+  }
+
+  @Override
+  public void close() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/InteropLogger.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/InteropLogger.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/InteropLogger.java
new file mode 100644
index 0000000..8bfbdfa
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/InteropLogger.java
@@ -0,0 +1,55 @@
+/**
+ * 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.reef.javabridge;
+
+import java.util.HashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class InteropLogger {
+  private static final Logger LOG = Logger.getLogger("InteropLogger");
+  HashMap<Integer, Level> levelHashMap;
+
+  {
+    levelHashMap = new HashMap<Integer, Level>();
+    levelHashMap.put(Level.OFF.intValue(), Level.OFF);
+    levelHashMap.put(Level.SEVERE.intValue(), Level.SEVERE);
+    levelHashMap.put(Level.WARNING.intValue(), Level.WARNING);
+    levelHashMap.put(Level.INFO.intValue(), Level.INFO);
+
+    levelHashMap.put(Level.CONFIG.intValue(), Level.CONFIG);
+    levelHashMap.put(Level.FINE.intValue(), Level.FINE);
+    levelHashMap.put(Level.FINER.intValue(), Level.FINER);
+
+    levelHashMap.put(Level.FINEST.intValue(), Level.FINEST);
+    levelHashMap.put(Level.ALL.intValue(), Level.ALL);
+  }
+
+  public void Log(int intLevel, String message) {
+    if (levelHashMap.containsKey(intLevel)) {
+      Level level = levelHashMap.get(intLevel);
+      LOG.log(level, message);
+    } else {
+
+      LOG.log(Level.WARNING, "Level " + intLevel + " is not a valid Log level");
+      LOG.log(Level.WARNING, message);
+    }
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/InteropReturnInfo.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/InteropReturnInfo.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/InteropReturnInfo.java
new file mode 100644
index 0000000..8ef59d6
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/InteropReturnInfo.java
@@ -0,0 +1,52 @@
+/**
+ * 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.reef.javabridge;
+
+import java.util.ArrayList;
+
+public class InteropReturnInfo {
+
+  int returnCode;
+  ArrayList<String> exceptionList = new ArrayList<String>();
+
+  public void addExceptionString(String exceptionString) {
+    exceptionList.add(exceptionString);
+  }
+
+  public boolean hasExceptions() {
+    return !exceptionList.isEmpty();
+  }
+
+  public ArrayList<String> getExceptionList() {
+    return exceptionList;
+  }
+
+  public int getReturnCode() {
+    return returnCode;
+  }
+
+  public void setReturnCode(int rc) {
+    returnCode = rc;
+  }
+
+  public void reset() {
+    exceptionList = new ArrayList<String>();
+    returnCode = 0;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/JavaBridge.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/JavaBridge.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/JavaBridge.java
new file mode 100644
index 0000000..ba438d8
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/JavaBridge.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.javabridge;
+
+public class JavaBridge {
+  private final static String CPP_BRIDGE = "JavaClrBridge";
+
+  static {
+    try {
+      System.loadLibrary(CPP_BRIDGE);
+    } catch (UnsatisfiedLinkError e) {
+    }
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/LibLoader.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/LibLoader.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/LibLoader.java
new file mode 100644
index 0000000..fa8b459
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/LibLoader.java
@@ -0,0 +1,154 @@
+/**
+ * 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.reef.javabridge;
+
+import org.apache.commons.compress.utils.IOUtils;
+import org.apache.reef.runtime.common.files.REEFFileNames;
+import org.apache.reef.util.logging.LoggingScope;
+import org.apache.reef.util.logging.LoggingScopeFactory;
+
+import javax.inject.Inject;
+import java.io.*;
+import java.util.Date;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Loading CLR libraries
+ */
+public class LibLoader {
+
+  private static final Logger LOG = Logger.getLogger(LibLoader.class.getName());
+
+  private static final String LIB_BIN = "/";
+  private static final String DLL_EXTENSION = ".dll";
+  private static final String USER_DIR = "user.dir";
+  private static final String[] MANAGED_DLLS = {
+      "ClrHandler",
+      "msvcr110",
+  };
+
+  private final LoggingScopeFactory loggingScopeFactory;
+
+  private final REEFFileNames reefFileNames;
+
+  @Inject
+  private LibLoader(final LoggingScopeFactory loggingScopeFactory, final REEFFileNames reefFileNames) {
+    this.loggingScopeFactory = loggingScopeFactory;
+    this.reefFileNames = reefFileNames;
+  }
+
+  /**
+   * Load CLR libraries
+   */
+  public void loadLib() throws IOException {
+    LOG.log(Level.INFO, "Loading DLLs for driver at time {0}." + new Date().toString());
+    try (final LoggingScope lb = loggingScopeFactory.loadLib()) {
+      final String tempLoadDir = System.getProperty(USER_DIR) + this.reefFileNames.getLoadDir();
+      LOG.log(Level.INFO, "load Folder: " + tempLoadDir);
+      new File(tempLoadDir).mkdir();
+
+      loadFromReefJar(this.reefFileNames.getCppBridge(), false);
+
+      loadLibFromGlobal();
+
+      for (int i = 0; i < MANAGED_DLLS.length; i++) {
+        loadFromReefJar(MANAGED_DLLS[i], true);
+      }
+    }
+    LOG.log(Level.INFO, "Done loading DLLs for Driver at time {0}." + new Date().toString());
+  }
+
+  /**
+   * Load assemblies at global folder
+   */
+  private void loadLibFromGlobal() {
+    final String globalFilePath = System.getProperty(USER_DIR) + this.reefFileNames.getReefGlobal();
+    final File[] files = new File(globalFilePath).listFiles(new FilenameFilter() {
+      public boolean accept(File dir, String name) {
+        return name.toLowerCase().endsWith(DLL_EXTENSION);
+      }
+    });
+
+    LOG.log(Level.INFO, "Total dll files to load from {0} is {1}.", new Object[] {globalFilePath, files.length} );
+    for (int i = 0; i < files.length; i++) {
+      try {
+        LOG.log(Level.INFO, "file to load : " + files[i].toString());
+        NativeInterop.loadClrAssembly(files[i].toString());
+      } catch (final Exception e) {
+        LOG.log(Level.SEVERE, "exception in loading dll library: ", files[i].toString());
+        throw e;
+      }
+    }
+  }
+
+  /**
+   * Get file from jar file and copy it to temp dir and loads the library to memory
+  **/
+  private void loadFromReefJar(String name, final boolean managed) throws IOException {
+
+    name = name + DLL_EXTENSION;
+    try {
+      File fileOut = null;
+      // get input file from jar
+      final String path = this.reefFileNames.getReefDriverAppDllDir() + name;
+      LOG.log(Level.INFO, "Source file path: " + path);
+      final java.net.URL url = NativeInterop.class.getClass().getResource(path);
+      if (url != null) {
+        LOG.log(Level.INFO, "Source file: " + url.getPath());
+      }
+      try (final InputStream in = NativeInterop.class.getResourceAsStream(path)) {
+        //copy to /reef/CLRLoadingDirectory
+        final String tempLoadDir = System.getProperty(USER_DIR) + this.reefFileNames.getLoadDir();
+        fileOut = new File(tempLoadDir + LIB_BIN + name);
+        LOG.log(Level.INFO, "Destination file: " + fileOut.toString());
+        if (null == in) {
+          LOG.log(Level.WARNING, "Cannot find " + path);
+          return;
+        }
+        try (final OutputStream out = new FileOutputStream(fileOut) ) {
+          IOUtils.copy(in, out);
+        }
+      }
+      loadAssembly(fileOut, managed);
+    } catch (final FileNotFoundException e) {
+      LOG.log(Level.SEVERE, "File not find exception: ", name);
+      throw e;
+    } catch (IOException e) {
+      LOG.log(Level.SEVERE, "File copy error: ", name);
+      throw e;
+    }
+  }
+
+  /**
+   * load assembly
+   * @param fileOut
+   * @param managed
+   */
+  private void loadAssembly(final File fileOut, final boolean managed) {
+    if (managed) {
+      NativeInterop.loadClrAssembly(fileOut.toString());
+      LOG.log(Level.INFO, "Loading DLL managed done");
+    } else {
+      System.load(fileOut.toString());
+      LOG.log(Level.INFO, "Loading DLL not managed done");
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/NativeBridge.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/NativeBridge.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/NativeBridge.java
new file mode 100644
index 0000000..4249ba7
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/NativeBridge.java
@@ -0,0 +1,32 @@
+/**
+ * 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.reef.javabridge;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public abstract class NativeBridge implements AutoCloseable {
+
+  private static final Logger LOG = Logger.getLogger(ActiveContextBridge.class.getName());
+
+  public void onError(String errorMessage) {
+    LOG.log(Level.SEVERE, "Bridge received error from CLR: " + errorMessage);
+    throw new RuntimeException("Bridge received error from CLR: " + errorMessage);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/NativeInterop.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/NativeInterop.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/NativeInterop.java
new file mode 100644
index 0000000..9fe61c1
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/NativeInterop.java
@@ -0,0 +1,166 @@
+/**
+ * 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.reef.javabridge;
+
+import java.util.HashMap;
+
+public class NativeInterop {
+  public static final String CLASS_HIERARCHY_FILENAME = "clrClassHierarchy.bin";
+  public static final String GLOBAL_LIBRARIES_FILENAME = "userSuppliedGlobalLibraries.txt";
+  public static final String EvaluatorRequestorKey = "EvaluatorRequestor";
+  public static final String AllocatedEvaluatorKey = "AllocatedEvaluator";
+  public static final String ActiveContextKey = "ActiveContext";
+  public static final String TaskMessageKey = "TaskMessage";
+  public static final String FailedTaskKey = "FailedTask";
+  public static final String FailedEvaluatorKey = "FailedEvaluator";
+  public static final String HttpServerKey = "HttpServerKey";
+  public static final String CompletedTaskKey = "CompletedTask";
+  public static final String RunningTaskKey = "RunningTask";
+  public static final String SuspendedTaskKey = "SuspendedTask";
+  public static final String CompletedEvaluatorKey = "CompletedEvaluator";
+  public static final String ClosedContextKey = "ClosedContext";
+  public static final String FailedContextKey = "FailedContext";
+  public static final String ContextMessageKey = "ContextMessage";
+  public static final String DriverRestartKey = "DriverRestart";
+  public static final String DriverRestartActiveContextKey = "DriverRestartActiveContext";
+  public static final String DriverRestartRunningTaskKey = "DriverRestartRunningTask";
+  public static final HashMap<String, Integer> Handlers = new HashMap<String, Integer>() {
+    {
+      put(EvaluatorRequestorKey, 0);
+      put(AllocatedEvaluatorKey, 1);
+      put(ActiveContextKey, 2);
+      put(TaskMessageKey, 3);
+      put(FailedTaskKey, 4);
+      put(FailedEvaluatorKey, 5);
+      put(HttpServerKey, 6);
+      put(CompletedTaskKey, 7);
+      put(RunningTaskKey, 8);
+      put(SuspendedTaskKey, 9);
+      put(CompletedEvaluatorKey, 10);
+      put(ClosedContextKey, 11);
+      put(FailedContextKey, 12);
+      put(ContextMessageKey, 13);
+      put(DriverRestartKey, 14);
+      put(DriverRestartActiveContextKey, 15);
+      put(DriverRestartRunningTaskKey, 16);
+    }
+  };
+
+  public static final int nHandlers = 17;
+
+  public static native void loadClrAssembly(String filePath);
+
+  public static native void ClrBufferedLog(int level, String message);
+
+  public static native long[] CallClrSystemOnStartHandler(String dateTime, String httpServerPortNumber);
+
+  public static native void ClrSystemAllocatedEvaluatorHandlerOnNext(
+      long handle,
+      AllocatedEvaluatorBridge javaEvaluatorBridge,
+      InteropLogger interopLogger
+  );
+
+  public static native void ClrSystemActiveContextHandlerOnNext(
+      long handle,
+      ActiveContextBridge javaActiveContextBridge,
+      InteropLogger interopLogger
+  );
+
+  public static native void ClrSystemEvaluatorRequstorHandlerOnNext(
+      long handle,
+      EvaluatorRequestorBridge javaEvluatorRequstorBridge,
+      InteropLogger interopLogger
+  );
+
+  public static native void ClrSystemTaskMessageHandlerOnNext(
+      long handle,
+      byte[] mesage,
+      TaskMessageBridge javaTaskMessageBridge,
+      InteropLogger interopLogger
+  );
+
+  public static native void ClrSystemFailedTaskHandlerOnNext(
+      long handle,
+      FailedTaskBridge failedTaskBridge,
+      InteropLogger interopLogger
+  );
+
+  public static native void ClrSystemHttpServerHandlerOnNext(
+      long handle,
+      HttpServerEventBridge httpServerEventBridge,
+      InteropLogger interopLogger
+  );
+
+  public static native void ClrSystemFailedEvaluatorHandlerOnNext(
+      long handle,
+      FailedEvaluatorBridge failedEvaluatorBridge,
+      InteropLogger interopLogger
+  );
+
+  public static native void ClrSystemCompletedTaskHandlerOnNext(
+      long handle,
+      CompletedTaskBridge completedTaskBridge,
+      InteropLogger interopLogger
+  );
+
+  public static native void ClrSystemRunningTaskHandlerOnNext(
+      long handle,
+      RunningTaskBridge runningTaskBridge,
+      InteropLogger interopLogger
+  );
+
+  public static native void ClrSystemSupendedTaskHandlerOnNext(
+      long handle,
+      SuspendedTaskBridge suspendedTaskBridge
+  );
+
+  public static native void ClrSystemCompletdEvaluatorHandlerOnNext(
+      long handle,
+      CompletedEvaluatorBridge completedEvaluatorBridge
+  );
+
+  public static native void ClrSystemClosedContextHandlerOnNext(
+      long handle,
+      ClosedContextBridge closedContextBridge
+  );
+
+  public static native void ClrSystemFailedContextHandlerOnNext(
+      long handle,
+      FailedContextBridge failedContextBridge
+  );
+
+  public static native void ClrSystemContextMessageHandlerOnNext(
+      long handle,
+      ContextMessageBridge contextMessageBridge
+  );
+
+  public static native void ClrSystemDriverRestartHandlerOnNext(
+      long handle
+  );
+
+  public static native void ClrSystemDriverRestartActiveContextHandlerOnNext(
+      long handle,
+      ActiveContextBridge activeContextBridge
+  );
+
+  public static native void ClrSystemDriverRestartRunningTaskHandlerOnNext(
+      long handle,
+      RunningTaskBridge runningTaskBridge
+  );
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/RunningTaskBridge.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/RunningTaskBridge.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/RunningTaskBridge.java
new file mode 100644
index 0000000..301c4fc
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/RunningTaskBridge.java
@@ -0,0 +1,49 @@
+/**
+ * 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.reef.javabridge;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.task.RunningTask;
+
+import java.util.logging.Logger;
+
+public class RunningTaskBridge extends NativeBridge {
+  private static final Logger LOG = Logger.getLogger(RunningTaskBridge.class.getName());
+
+  final private RunningTask jrunningTask;
+  final private ActiveContextBridge jactiveContext;
+
+  public RunningTaskBridge(RunningTask runningTask) {
+    jrunningTask = runningTask;
+    final ActiveContext activeContext = runningTask.getActiveContext();
+    jactiveContext = new ActiveContextBridge(activeContext);
+  }
+
+  public final String getId() {
+    return jrunningTask.getId();
+  }
+
+  public final void send(final byte[] message) {
+    jrunningTask.send(message);
+  }
+
+  @Override
+  public void close() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/SuspendedTaskBridge.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/SuspendedTaskBridge.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/SuspendedTaskBridge.java
new file mode 100644
index 0000000..16fa3d3
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/SuspendedTaskBridge.java
@@ -0,0 +1,54 @@
+/**
+ * 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.reef.javabridge;
+
+import org.apache.reef.driver.task.SuspendedTask;
+import org.apache.reef.io.Message;
+import org.apache.reef.io.naming.Identifiable;
+
+public class SuspendedTaskBridge extends NativeBridge implements Identifiable, Message {
+
+  private final SuspendedTask jsuspendedTask;
+  private final String taskId;
+  private final ActiveContextBridge jactiveContext;
+
+  public SuspendedTaskBridge(SuspendedTask suspendedTask) {
+    jsuspendedTask = suspendedTask;
+    taskId = suspendedTask.getId();
+    jactiveContext = new ActiveContextBridge(jsuspendedTask.getActiveContext());
+  }
+
+  public ActiveContextBridge getActiveContext() {
+    return jactiveContext;
+  }
+
+  @Override
+  public void close() {
+  }
+
+  @Override
+  public String getId() {
+    return taskId;
+  }
+
+  @Override
+  public byte[] get() {
+    return jsuspendedTask.get();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/TaskMessageBridge.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/TaskMessageBridge.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/TaskMessageBridge.java
new file mode 100644
index 0000000..25b0478
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/TaskMessageBridge.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.javabridge;
+
+import org.apache.reef.driver.task.TaskMessage;
+
+public class TaskMessageBridge extends NativeBridge {
+  private TaskMessage jtaskMessage;
+  private String taskId;
+
+  // we don't really need to pass this around, just have this as place holder for future.
+  public TaskMessageBridge(TaskMessage taskMessage) {
+    jtaskMessage = taskMessage;
+    taskId = taskMessage.getId();
+  }
+
+  @Override
+  public void close() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/Utilities.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/Utilities.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/Utilities.java
new file mode 100644
index 0000000..e6d0849
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/Utilities.java
@@ -0,0 +1,57 @@
+/**
+ * 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.reef.javabridge;
+
+import org.apache.reef.driver.evaluator.EvaluatorDescriptor;
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.implementation.protobuf.ProtocolBufferClassHierarchy;
+import org.apache.reef.tang.proto.ClassHierarchyProto;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+public class Utilities {
+  public static ClassHierarchy loadClassHierarchy(String classHierarchyFile) {
+    Path p = Paths.get(classHierarchyFile);
+    if (!Files.exists(p)) {
+      p = Paths.get(System.getProperty("user.dir") + "/reef/global/" + classHierarchyFile);
+    }
+    if (!Files.exists(p)) {
+      throw new RuntimeException("cannot find file " + p.toAbsolutePath());
+    }
+    try (final InputStream chin = new FileInputStream(p.toAbsolutePath().toString())) {
+      final ClassHierarchyProto.Node root = ClassHierarchyProto.Node.parseFrom(chin);
+      final ClassHierarchy ch = new ProtocolBufferClassHierarchy(root);
+      return ch;
+    } catch (final IOException e) {
+      final String message = "Unable to load class hierarchy from " + classHierarchyFile;
+      throw new RuntimeException(message, e);
+    }
+  }
+
+  public static String getEvaluatorDescriptorString(EvaluatorDescriptor evaluatorDescriptor) {
+    InetSocketAddress socketAddress = evaluatorDescriptor.getNodeDescriptor().getInetSocketAddress();
+    return "IP=" + socketAddress.getAddress() + ", Port=" + socketAddress.getPort() + ", HostName=" + socketAddress.getHostName() + ", Memory=" + evaluatorDescriptor.getMemory() + ", Core=" + evaluatorDescriptor.getNumberOfCores();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/JobClient.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/JobClient.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/JobClient.java
new file mode 100644
index 0000000..62bfac1
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/JobClient.java
@@ -0,0 +1,322 @@
+/**
+ * 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.reef.javabridge.generic;
+
+import org.apache.reef.client.*;
+import org.apache.reef.io.network.naming.NameServerConfiguration;
+import org.apache.reef.javabridge.NativeInterop;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Configurations;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.formats.AvroConfigurationSerializer;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.util.EnvironmentUtils;
+import org.apache.reef.util.logging.LoggingScope;
+import org.apache.reef.util.logging.LoggingScopeFactory;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.webserver.HttpHandlerConfiguration;
+import org.apache.reef.webserver.HttpServerReefEventHandler;
+import org.apache.reef.webserver.ReefEventStateManager;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Clr Bridge Client.
+ */
+@Unit
+public class JobClient {
+
+  /**
+   * Standard java logger.
+   */
+  private static final Logger LOG = Logger.getLogger(JobClient.class.getName());
+
+  /**
+   * Reference to the REEF framework.
+   * This variable is injected automatically in the constructor.
+   */
+  private final REEF reef;
+
+  /**
+   * Job Driver configuration.
+   */
+  private Configuration driverConfiguration;
+  private ConfigurationModule driverConfigModule;
+
+  /**
+   * A reference to the running job that allows client to send messages back to the job driver
+   */
+  private RunningJob runningJob;
+
+  /**
+   * Set to false when job driver is done.
+   */
+  private boolean isBusy = true;
+
+  private int driverMemory;
+
+  private String driverId;
+
+  private String jobSubmissionDirectory = "reefTmp/job_" + System.currentTimeMillis();
+
+  /**
+   * A factory that provides LoggingScope
+   */
+  private final LoggingScopeFactory loggingScopeFactory;
+  /**
+   * Clr Bridge client.
+   * Parameters are injected automatically by TANG.
+   *
+   * @param reef Reference to the REEF framework.
+   */
+  @Inject
+  JobClient(final REEF reef, final LoggingScopeFactory loggingScopeFactory) throws BindException {
+    this.loggingScopeFactory = loggingScopeFactory;
+    this.reef = reef;
+    this.driverConfigModule = getDriverConfiguration();
+  }
+
+  public static ConfigurationModule getDriverConfiguration() {
+    return EnvironmentUtils.addClasspath(DriverConfiguration.CONF, DriverConfiguration.GLOBAL_LIBRARIES)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, JobDriver.AllocatedEvaluatorHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_FAILED, JobDriver.FailedEvaluatorHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_ACTIVE, JobDriver.ActiveContextHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_RESTART_CONTEXT_ACTIVE, JobDriver.DriverRestartActiveContextHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_CLOSED, JobDriver.ClosedContextHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_FAILED, JobDriver.FailedContextHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_MESSAGE, JobDriver.ContextMessageHandler.class)
+        .set(DriverConfiguration.ON_TASK_MESSAGE, JobDriver.TaskMessageHandler.class)
+        .set(DriverConfiguration.ON_TASK_FAILED, JobDriver.FailedTaskHandler.class)
+        .set(DriverConfiguration.ON_TASK_RUNNING, JobDriver.RunningTaskHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_RESTART_TASK_RUNNING, JobDriver.DriverRestartRunningTaskHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_RESTART_COMPLETED, JobDriver.DriverRestartCompletedHandler.class)
+        .set(DriverConfiguration.ON_TASK_COMPLETED, JobDriver.CompletedTaskHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_STARTED, JobDriver.StartHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_RESTARTED, JobDriver.RestartHandler.class)
+        .set(DriverConfiguration.ON_TASK_SUSPENDED, JobDriver.SuspendedTaskHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_COMPLETED, JobDriver.CompletedEvaluatorHandler.class);
+  }
+
+  private static Configuration getNameServerConfiguration() {
+    return NameServerConfiguration.CONF
+        .set(NameServerConfiguration.NAME_SERVICE_PORT, 0)
+        .build();
+  }
+
+  /**
+   * @return the driver-side configuration to be merged into the DriverConfiguration to enable the HTTP server.
+   */
+  public static Configuration getHTTPConfiguration() {
+    Configuration httpHandlerConfiguration = HttpHandlerConfiguration.CONF
+        .set(HttpHandlerConfiguration.HTTP_HANDLERS, HttpServerReefEventHandler.class)
+        .build();
+
+    Configuration driverConfigurationForHttpServer = DriverServiceConfiguration.CONF
+        .set(DriverServiceConfiguration.ON_EVALUATOR_ALLOCATED, ReefEventStateManager.AllocatedEvaluatorStateHandler.class)
+        .set(DriverServiceConfiguration.ON_CONTEXT_ACTIVE, ReefEventStateManager.ActiveContextStateHandler.class)
+        .set(DriverServiceConfiguration.ON_DRIVER_RESTART_CONTEXT_ACTIVE, ReefEventStateManager.DrivrRestartActiveContextStateHandler.class)
+        .set(DriverServiceConfiguration.ON_TASK_RUNNING, ReefEventStateManager.TaskRunningStateHandler.class)
+        .set(DriverServiceConfiguration.ON_DRIVER_RESTART_TASK_RUNNING, ReefEventStateManager.DriverRestartTaskRunningStateHandler.class)
+        .set(DriverServiceConfiguration.ON_DRIVER_STARTED, ReefEventStateManager.StartStateHandler.class)
+        .set(DriverServiceConfiguration.ON_DRIVER_STOP, ReefEventStateManager.StopStateHandler.class)
+        .build();
+    return Configurations.merge(httpHandlerConfiguration, driverConfigurationForHttpServer);
+  }
+
+  public void addCLRFiles(final File folder) throws BindException {
+    try (final LoggingScope ls = this.loggingScopeFactory.getNewLoggingScope("JobClient::addCLRFiles")) {
+      ConfigurationModule result = this.driverConfigModule;
+      for (final File f : folder.listFiles()) {
+        if (f.canRead() && f.exists() && f.isFile()) {
+          result = result.set(DriverConfiguration.GLOBAL_FILES, f.getAbsolutePath());
+        }
+      }
+
+      // set the driver memory, id and job submission directory
+      this.driverConfigModule = result
+          .set(DriverConfiguration.DRIVER_MEMORY, this.driverMemory)
+          .set(DriverConfiguration.DRIVER_IDENTIFIER, this.driverId)
+          .set(DriverConfiguration.DRIVER_JOB_SUBMISSION_DIRECTORY, this.jobSubmissionDirectory);
+
+
+      Path globalLibFile = Paths.get(NativeInterop.GLOBAL_LIBRARIES_FILENAME);
+      if (!Files.exists(globalLibFile)) {
+        LOG.log(Level.FINE, "Cannot find global classpath file at: {0}, assume there is none.", globalLibFile.toAbsolutePath());
+      } else {
+        String globalLibString = "";
+        try {
+          globalLibString = new String(Files.readAllBytes(globalLibFile));
+        } catch (final Exception e) {
+          LOG.log(Level.WARNING, "Cannot read from {0}, global libraries not added  " + globalLibFile.toAbsolutePath());
+        }
+
+        for (final String s : globalLibString.split(",")) {
+          File f = new File(s);
+          this.driverConfigModule = this.driverConfigModule.set(DriverConfiguration.GLOBAL_LIBRARIES, f.getPath());
+        }
+      }
+
+      this.driverConfiguration = Configurations.merge(this.driverConfigModule.build(), getHTTPConfiguration(), getNameServerConfiguration());
+    }
+  }
+
+  /**
+   * Launch the job driver.
+   *
+   * @throws org.apache.reef.tang.exceptions.BindException configuration error.
+   */
+  public void submit(final File clrFolder, final boolean submitDriver, final Configuration clientConfig) {
+    try (final LoggingScope ls = this.loggingScopeFactory.driverSubmit(submitDriver)) {
+      try {
+        addCLRFiles(clrFolder);
+      } catch (final BindException e) {
+        LOG.log(Level.FINE, "Failed to bind", e);
+      }
+      if (submitDriver) {
+        this.reef.submit(this.driverConfiguration);
+      } else {
+        File driverConfig = new File(System.getProperty("user.dir") + "/driver.config");
+        try {
+          new AvroConfigurationSerializer().toFile(Configurations.merge(this.driverConfiguration, clientConfig), driverConfig);
+          LOG.log(Level.INFO, "Driver configuration file created at " + driverConfig.getAbsolutePath());
+        } catch (final IOException e) {
+          throw new RuntimeException("Cannot create driver configuration file at " + driverConfig.getAbsolutePath());
+        }
+      }
+    }
+  }
+
+  /**
+   * Set the driver memory
+   */
+  public void setDriverInfo(final String identifier, final int memory, final String jobSubmissionDirectory) {
+    if (identifier == null || identifier.isEmpty()) {
+      throw new RuntimeException("driver id cannot be null or empty");
+    }
+    if (memory <= 0) {
+      throw new RuntimeException("driver memory cannot be negative number: " + memory);
+    }
+    this.driverMemory = memory;
+    this.driverId = identifier;
+    if (jobSubmissionDirectory != null && !jobSubmissionDirectory.equals("empty")) {
+      this.jobSubmissionDirectory = jobSubmissionDirectory;
+    } else {
+      LOG.log(Level.FINE, "No job submission directory provided by CLR user, will use " + this.jobSubmissionDirectory);
+    }
+  }
+
+  /**
+   * Notify the process in waitForCompletion() method that the main process has finished.
+   */
+  private synchronized void stopAndNotify() {
+    this.runningJob = null;
+    this.isBusy = false;
+    this.notify();
+  }
+
+  /**
+   * Wait for the job driver to complete. This method is called from Launcher.main()
+   */
+  public void waitForCompletion(final int waitTime) {
+    LOG.info("Waiting for the Job Driver to complete: " + waitTime);
+    if (waitTime == 0) {
+      close(0);
+      return;
+    } else if (waitTime < 0) {
+      waitTillDone();
+    }
+    long endTime = System.currentTimeMillis() + waitTime * 1000;
+    close(endTime);
+  }
+
+  public void close(final long endTime) {
+    while (endTime > System.currentTimeMillis()) {
+      try {
+        Thread.sleep(1000);
+      } catch (final InterruptedException e) {
+        LOG.log(Level.SEVERE, "Thread sleep failed");
+      }
+    }
+    LOG.log(Level.INFO, "Done waiting.");
+    this.stopAndNotify();
+    reef.close();
+  }
+
+  private void waitTillDone() {
+    while (this.isBusy) {
+      try {
+        synchronized (this) {
+          this.wait();
+        }
+      } catch (final InterruptedException ex) {
+        LOG.log(Level.WARNING, "Waiting for result interrupted.", ex);
+      }
+    }
+    this.reef.close();
+  }
+
+  /**
+   * Receive notification from the job driver that the job had failed.
+   */
+  final class FailedJobHandler implements EventHandler<FailedJob> {
+    @Override
+    public void onNext(final FailedJob job) {
+      LOG.log(Level.SEVERE, "Failed job: " + job.getId(), job.getMessage());
+      stopAndNotify();
+    }
+  }
+
+  /**
+   * Receive notification from the job driver that the job had completed successfully.
+   */
+  final class CompletedJobHandler implements EventHandler<CompletedJob> {
+    @Override
+    public void onNext(final CompletedJob job) {
+      LOG.log(Level.INFO, "Completed job: {0}", job.getId());
+      stopAndNotify();
+    }
+  }
+
+  /**
+   * Receive notification that there was an exception thrown from the job driver.
+   */
+  final class RuntimeErrorHandler implements EventHandler<FailedRuntime> {
+    @Override
+    public void onNext(final FailedRuntime error) {
+      LOG.log(Level.SEVERE, "Error in job driver: " + error, error.getMessage());
+      stopAndNotify();
+    }
+  }
+
+  final class WakeErrorHandler implements EventHandler<Throwable> {
+    @Override
+    public void onNext(Throwable error) {
+      LOG.log(Level.SEVERE, "Error communicating with job driver, exiting... ", error);
+      stopAndNotify();
+    }
+  }
+}


[31/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/pom.xml b/lang/java/reef-examples/pom.xml
new file mode 100644
index 0000000..b2eb3b7
--- /dev/null
+++ b/lang/java/reef-examples/pom.xml
@@ -0,0 +1,365 @@
+<?xml version="1.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.
+-->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+         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>
+    <artifactId>reef-examples</artifactId>
+    <name>REEF Examples</name>
+
+    <parent>
+        <groupId>org.apache.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <dependencies>
+        <!-- REEF -->
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-local</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-yarn</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-mesos</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-io</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-checkpoint</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-webserver</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-poison</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <!-- End of REEF -->
+
+        <!-- HADOOP -->
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-common</artifactId>
+            <version>${hadoop.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-mapreduce-client-core</artifactId>
+            <version>${hadoop.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <!-- End of HADOOP -->
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-jdk14</artifactId>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+    </dependencies>
+
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-shade-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>shade</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <outputFile>
+                        ${project.build.directory}/${project.artifactId}-${project.version}-shaded.jar
+                    </outputFile>
+                    <filters>
+                        <filter>
+                            <artifact>*:*</artifact>
+                            <excludes>
+                                <exclude>yarn-default.xml</exclude>
+                                <exclude>yarn-version-info.properties</exclude>
+                                <exclude>core-default.xml</exclude>
+                                <exclude>LICENSE</exclude>
+                                <exclude>META-INF/*</exclude>
+                            </excludes>
+                        </filter>
+                    </filters>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+
+    <profiles>
+
+        <profile>
+            <id>HelloREEF</id>
+            <build>
+                <defaultGoal>exec:exec</defaultGoal>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <configuration>
+                            <executable>java</executable>
+                            <arguments>
+                                <argument>-classpath</argument>
+                                <classpath/>
+                                <argument>-Djava.util.logging.config.class=org.apache.reef.util.logging.Config
+                                </argument>
+                                <!-- <argument>-Dlog4j.debug=true</argument> -->
+                                <argument>-Dcom.microsoft.reef.runtime.local.folder=${project.build.directory}
+                                </argument>
+                                <argument>org.apache.reef.examples.hello.HelloREEF</argument>
+                            </arguments>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+        <profile>
+            <id>HelloREEFHttp</id>
+            <build>
+                <defaultGoal>exec:exec</defaultGoal>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <configuration>
+                            <executable>java</executable>
+                            <arguments>
+                                <argument>-classpath</argument>
+                                <classpath/>
+                                <argument>-Djava.util.logging.config.class=org.apache.reef.util.logging.Config
+                                </argument>
+                                <!-- <argument>-Dlog4j.debug=true</argument> -->
+                                <argument>-Dcom.microsoft.reef.runtime.local.folder=${project.build.directory}
+                                </argument>
+                                <argument>org.apache.reef.examples.hellohttp.HelloREEFHttp</argument>
+                            </arguments>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+        <profile>
+            <id>HelloREEFNoClient</id>
+            <build>
+                <defaultGoal>exec:exec</defaultGoal>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <configuration>
+                            <executable>java</executable>
+                            <arguments>
+                                <argument>-classpath</argument>
+                                <classpath/>
+                                <argument>-Djava.util.logging.config.class=org.apache.reef.util.logging.Config
+                                </argument>
+                                <!-- <argument>-Dlog4j.debug=true</argument> -->
+                                <argument>-Dcom.microsoft.reef.runtime.local.folder=${project.build.directory}
+                                </argument>
+                                <argument>org.apache.reef.examples.hello.HelloREEFNoClient</argument>
+                            </arguments>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+        <profile>
+            <id>MatMult</id>
+            <build>
+                <defaultGoal>exec:exec</defaultGoal>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <configuration>
+                            <executable>java</executable>
+                            <arguments>
+                                <argument>-classpath</argument>
+                                <classpath/>
+                                <argument>-Djava.util.logging.config.class=org.apache.reef.util.logging.Config
+                                </argument>
+                                <argument>-Dcom.microsoft.reef.runtime.local.folder=${project.build.directory}
+                                </argument>
+                                <argument>org.apache.reef.examples.groupcomm.matmul.MatMultREEF</argument>
+                            </arguments>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+
+        <profile>
+            <id>RetainedEval</id>
+            <build>
+                <defaultGoal>exec:exec</defaultGoal>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <configuration>
+                            <executable>java</executable>
+                            <arguments>
+                                <argument>-classpath</argument>
+                                <classpath/>
+                                <argument>-Djava.util.logging.config.class=org.apache.reef.util.logging.Config
+                                </argument>
+                                <argument>-Dcom.microsoft.reef.runtime.local.folder=${project.build.directory}
+                                </argument>
+                                <argument>org.apache.reef.examples.retained_eval.Launch</argument>
+                                <!-- <argument>-cmd</argument>
+                                <argument>date</argument>
+                                <argument>-num_runs</argument>
+                                <argument>20</argument>
+                                <argument>-local</argument>
+                                <argument>true</argument> -->
+                            </arguments>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+        <profile>
+            <id>RetainedEval_yarn</id>
+            <build>
+                <defaultGoal>exec:exec</defaultGoal>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <configuration>
+                            <executable>java</executable>
+                            <arguments>
+                                <argument>-classpath</argument>
+                                <classpath/>
+                                <argument>-Djava.util.logging.config.class=org.apache.reef.util.logging.Config
+                                </argument>
+                                <argument>org.apache.reef.examples.retained_eval.Launch</argument>
+                                <argument>-cmd</argument>
+                                <argument>date</argument>
+                                <argument>-num_runs</argument>
+                                <argument>20</argument>
+                                <argument>-local</argument>
+                                <argument>false</argument>
+                            </arguments>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+
+        <profile>
+            <id>SuspendDemo</id>
+            <build>
+                <defaultGoal>exec:exec</defaultGoal>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <configuration>
+                            <executable>java</executable>
+                            <arguments>
+                                <argument>-classpath</argument>
+                                <classpath/>
+                                <argument>-Dcom.microsoft.reef.runtime.local.folder=${project.build.directory}
+                                </argument>
+                                <argument>-Djava.util.logging.config.class=org.apache.reef.util.logging.Config
+                                </argument>
+                                <argument>org.apache.reef.examples.suspend.Launch</argument>
+                                <argument>-delay</argument>
+                                <argument>1</argument>
+                                <argument>-cycles</argument>
+                                <argument>20</argument>
+                                <argument>-local</argument>
+                                <argument>true</argument>
+                            </arguments>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+
+        <profile>
+            <id>Pool</id>
+            <build>
+                <defaultGoal>exec:exec</defaultGoal>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <configuration>
+                            <executable>java</executable>
+                            <arguments>
+                                <argument>-classpath</argument>
+                                <classpath/>
+                                <argument>-Dcom.microsoft.reef.runtime.local.folder=${project.build.directory}
+                                </argument>
+                                <argument>-Djava.util.logging.config.class=org.apache.reef.util.logging.Config
+                                </argument>
+                                <argument>org.apache.reef.examples.pool.Launch</argument>
+                                <argument>-evaluators</argument>
+                                <argument>4</argument>
+                                <argument>-tasks</argument>
+                                <argument>100</argument>
+                                <argument>-delay</argument>
+                                <argument>1</argument>
+                                <argument>-local</argument>
+                                <argument>true</argument>
+                            </arguments>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/data/loading/DataLoadingREEF.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/data/loading/DataLoadingREEF.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/data/loading/DataLoadingREEF.java
new file mode 100644
index 0000000..a6e7544
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/data/loading/DataLoadingREEF.java
@@ -0,0 +1,128 @@
+/**
+ * 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.reef.examples.data.loading;
+
+import org.apache.hadoop.mapred.TextInputFormat;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.io.data.loading.api.DataLoadingRequestBuilder;
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.runtime.yarn.client.YarnClientConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.CommandLine;
+import org.apache.reef.util.EnvironmentUtils;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Client for the data loading demo app
+ */
+@ClientSide
+public class DataLoadingREEF {
+
+  private static final Logger LOG = Logger.getLogger(DataLoadingREEF.class.getName());
+
+  private static final int NUM_LOCAL_THREADS = 16;
+  private static final int NUM_SPLITS = 6;
+  private static final int NUM_COMPUTE_EVALUATORS = 2;
+
+  public static void main(final String[] args)
+      throws InjectionException, BindException, IOException {
+
+    final Tang tang = Tang.Factory.getTang();
+
+    final JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+
+    new CommandLine(cb)
+        .registerShortNameOfClass(Local.class)
+        .registerShortNameOfClass(TimeOut.class)
+        .registerShortNameOfClass(DataLoadingREEF.InputDir.class)
+        .processCommandLine(args);
+
+    final Injector injector = tang.newInjector(cb.build());
+
+    final boolean isLocal = injector.getNamedInstance(Local.class);
+    final int jobTimeout = injector.getNamedInstance(TimeOut.class) * 60 * 1000;
+    final String inputDir = injector.getNamedInstance(DataLoadingREEF.InputDir.class);
+
+    final Configuration runtimeConfiguration;
+    if (isLocal) {
+      LOG.log(Level.INFO, "Running Data Loading demo on the local runtime");
+      runtimeConfiguration = LocalRuntimeConfiguration.CONF
+          .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, NUM_LOCAL_THREADS)
+          .build();
+    } else {
+      LOG.log(Level.INFO, "Running Data Loading demo on YARN");
+      runtimeConfiguration = YarnClientConfiguration.CONF.build();
+    }
+
+    final EvaluatorRequest computeRequest = EvaluatorRequest.newBuilder()
+        .setNumber(NUM_COMPUTE_EVALUATORS)
+        .setMemory(512)
+        .setNumberOfCores(1)
+        .build();
+
+    final Configuration dataLoadConfiguration = new DataLoadingRequestBuilder()
+        .setMemoryMB(1024)
+        .setInputFormatClass(TextInputFormat.class)
+        .setInputPath(inputDir)
+        .setNumberOfDesiredSplits(NUM_SPLITS)
+        .setComputeRequest(computeRequest)
+        .setDriverConfigurationModule(DriverConfiguration.CONF
+            .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(LineCounter.class))
+            .set(DriverConfiguration.ON_CONTEXT_ACTIVE, LineCounter.ContextActiveHandler.class)
+            .set(DriverConfiguration.ON_TASK_COMPLETED, LineCounter.TaskCompletedHandler.class)
+            .set(DriverConfiguration.DRIVER_IDENTIFIER, "DataLoadingREEF"))
+        .build();
+
+    final LauncherStatus state =
+        DriverLauncher.getLauncher(runtimeConfiguration).run(dataLoadConfiguration, jobTimeout);
+
+    LOG.log(Level.INFO, "REEF job completed: {0}", state);
+  }
+
+  /**
+   * Command line parameter = true to run locally, or false to run on YARN.
+   */
+  @NamedParameter(doc = "Whether or not to run on the local runtime",
+      short_name = "local", default_value = "true")
+  public static final class Local implements Name<Boolean> {
+  }
+
+  @NamedParameter(doc = "Number of minutes before timeout",
+      short_name = "timeout", default_value = "2")
+  public static final class TimeOut implements Name<Integer> {
+  }
+
+  @NamedParameter(short_name = "input")
+  public static final class InputDir implements Name<String> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/data/loading/LineCounter.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/data/loading/LineCounter.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/data/loading/LineCounter.java
new file mode 100644
index 0000000..4b88bd1
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/data/loading/LineCounter.java
@@ -0,0 +1,126 @@
+/**
+ * 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.reef.examples.data.loading;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.task.CompletedTask;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.io.data.loading.api.DataLoadingService;
+import org.apache.reef.poison.PoisonedConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Driver side for the line counting demo that uses the data loading service.
+ */
+@DriverSide
+@Unit
+public class LineCounter {
+
+  private static final Logger LOG = Logger.getLogger(LineCounter.class.getName());
+
+  private final AtomicInteger ctrlCtxIds = new AtomicInteger();
+  private final AtomicInteger lineCnt = new AtomicInteger();
+  private final AtomicInteger completedDataTasks = new AtomicInteger();
+
+  private final DataLoadingService dataLoadingService;
+
+  @Inject
+  public LineCounter(final DataLoadingService dataLoadingService) {
+    this.dataLoadingService = dataLoadingService;
+    this.completedDataTasks.set(dataLoadingService.getNumberOfPartitions());
+  }
+
+  public class ContextActiveHandler implements EventHandler<ActiveContext> {
+
+    @Override
+    public void onNext(final ActiveContext activeContext) {
+
+      final String contextId = activeContext.getId();
+      LOG.log(Level.FINER, "Context active: {0}", contextId);
+
+      if (dataLoadingService.isDataLoadedContext(activeContext)) {
+
+        final String lcContextId = "LineCountCtxt-" + ctrlCtxIds.getAndIncrement();
+        LOG.log(Level.FINEST, "Submit LineCount context {0} to: {1}",
+            new Object[]{lcContextId, contextId});
+
+        final Configuration poisonedConfiguration = PoisonedConfiguration.CONTEXT_CONF
+            .set(PoisonedConfiguration.CRASH_PROBABILITY, "0.4")
+            .set(PoisonedConfiguration.CRASH_TIMEOUT, "1")
+            .build();
+
+        activeContext.submitContext(Tang.Factory.getTang()
+            .newConfigurationBuilder(poisonedConfiguration,
+                ContextConfiguration.CONF.set(ContextConfiguration.IDENTIFIER, lcContextId).build())
+            .build());
+
+      } else if (activeContext.getId().startsWith("LineCountCtxt")) {
+
+        final String taskId = "LineCountTask-" + ctrlCtxIds.getAndIncrement();
+        LOG.log(Level.FINEST, "Submit LineCount task {0} to: {1}", new Object[]{taskId, contextId});
+
+        try {
+          activeContext.submitTask(TaskConfiguration.CONF
+              .set(TaskConfiguration.IDENTIFIER, taskId)
+              .set(TaskConfiguration.TASK, LineCountingTask.class)
+              .build());
+        } catch (final BindException ex) {
+          LOG.log(Level.SEVERE, "Configuration error in " + contextId, ex);
+          throw new RuntimeException("Configuration error in " + contextId, ex);
+        }
+      } else {
+        LOG.log(Level.FINEST, "Line count Compute Task {0} -- Closing", contextId);
+        activeContext.close();
+      }
+    }
+  }
+
+  public class TaskCompletedHandler implements EventHandler<CompletedTask> {
+    @Override
+    public void onNext(final CompletedTask completedTask) {
+
+      final String taskId = completedTask.getId();
+      LOG.log(Level.FINEST, "Completed Task: {0}", taskId);
+
+      final byte[] retBytes = completedTask.get();
+      final String retStr = retBytes == null ? "No RetVal" : new String(retBytes);
+      LOG.log(Level.FINE, "Line count from {0} : {1}", new String[]{taskId, retStr});
+
+      lineCnt.addAndGet(Integer.parseInt(retStr));
+
+      if (completedDataTasks.decrementAndGet() <= 0) {
+        LOG.log(Level.INFO, "Total line count: {0}", lineCnt.get());
+      }
+
+      LOG.log(Level.FINEST, "Releasing Context: {0}", taskId);
+      completedTask.getActiveContext().close();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/data/loading/LineCountingTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/data/loading/LineCountingTask.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/data/loading/LineCountingTask.java
new file mode 100644
index 0000000..1d6ab8e
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/data/loading/LineCountingTask.java
@@ -0,0 +1,59 @@
+/**
+ * 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.reef.examples.data.loading;
+
+import org.apache.hadoop.io.LongWritable;
+import org.apache.hadoop.io.Text;
+import org.apache.reef.annotations.audience.TaskSide;
+import org.apache.reef.io.data.loading.api.DataSet;
+import org.apache.reef.io.network.util.Pair;
+import org.apache.reef.task.Task;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The task that iterates over the data set to count the number of records.
+ * Assumes TextInputFormat and that records represent lines.
+ */
+@TaskSide
+public class LineCountingTask implements Task {
+
+  private static final Logger LOG = Logger.getLogger(LineCountingTask.class.getName());
+
+  private final DataSet<LongWritable, Text> dataSet;
+
+  @Inject
+  public LineCountingTask(final DataSet<LongWritable, Text> dataSet) {
+    this.dataSet = dataSet;
+  }
+
+  @Override
+  public byte[] call(final byte[] memento) throws Exception {
+    LOG.log(Level.FINER, "LineCounting task started");
+    int numEx = 0;
+    for (final Pair<LongWritable, Text> keyValue : dataSet) {
+      // LOG.log(Level.FINEST, "Read line: {0}", keyValue);
+      ++numEx;
+    }
+    LOG.log(Level.FINER, "LineCounting task finished: read {0} lines", numEx);
+    return Integer.toString(numEx).getBytes();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloDriver.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloDriver.java
new file mode 100644
index 0000000..8344a44
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloDriver.java
@@ -0,0 +1,84 @@
+/**
+ * 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.reef.examples.hello;
+
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The Driver code for the Hello REEF Application
+ */
+@Unit
+public final class HelloDriver {
+
+  private static final Logger LOG = Logger.getLogger(HelloDriver.class.getName());
+
+  private final EvaluatorRequestor requestor;
+
+  /**
+   * Job driver constructor - instantiated via TANG.
+   *
+   * @param requestor evaluator requestor object used to create new evaluator containers.
+   */
+  @Inject
+  public HelloDriver(final EvaluatorRequestor requestor) {
+    this.requestor = requestor;
+    LOG.log(Level.FINE, "Instantiated 'HelloDriver'");
+  }
+
+  /**
+   * Handles the StartTime event: Request as single Evaluator.
+   */
+  public final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime startTime) {
+      HelloDriver.this.requestor.submit(EvaluatorRequest.newBuilder()
+          .setNumber(1)
+          .setMemory(64)
+          .setNumberOfCores(1)
+          .build());
+      LOG.log(Level.INFO, "Requested Evaluator.");
+    }
+  }
+
+  /**
+   * Handles AllocatedEvaluator: Submit the HelloTask
+   */
+  public final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+      LOG.log(Level.INFO, "Submitting HelloREEF task to AllocatedEvaluator: {0}", allocatedEvaluator);
+      final Configuration taskConfiguration = TaskConfiguration.CONF
+          .set(TaskConfiguration.IDENTIFIER, "HelloREEFTask")
+          .set(TaskConfiguration.TASK, HelloTask.class)
+          .build();
+      allocatedEvaluator.submitTask(taskConfiguration);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloREEF.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloREEF.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloREEF.java
new file mode 100644
index 0000000..ffaa304
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloREEF.java
@@ -0,0 +1,77 @@
+/**
+ * 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.reef.examples.hello;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.util.EnvironmentUtils;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The Client for Hello REEF example.
+ */
+public final class HelloREEF {
+
+  private static final Logger LOG = Logger.getLogger(HelloREEF.class.getName());
+
+  /**
+   * Number of milliseconds to wait for the job to complete.
+   */
+  private static final int JOB_TIMEOUT = 10000; // 10 sec.
+
+  /**
+   * @return the configuration of the HelloREEF driver.
+   */
+  public static Configuration getDriverConfiguration() {
+    return DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(HelloDriver.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "HelloREEF")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, HelloDriver.StartHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HelloDriver.EvaluatorAllocatedHandler.class)
+        .build();
+  }
+
+  public static LauncherStatus runHelloReef(final Configuration runtimeConf, final int timeOut)
+      throws BindException, InjectionException {
+    final Configuration driverConf = getDriverConfiguration();
+    return DriverLauncher.getLauncher(runtimeConf).run(driverConf, timeOut);
+  }
+
+  /**
+   * Start Hello REEF job. Runs method runHelloReef().
+   *
+   * @param args command line parameters.
+   * @throws BindException      configuration error.
+   * @throws InjectionException configuration error.
+   */
+  public static void main(final String[] args) throws BindException, InjectionException {
+    final Configuration runtimeConfiguration = LocalRuntimeConfiguration.CONF
+        .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, 2)
+        .build();
+    final LauncherStatus status = runHelloReef(runtimeConfiguration, JOB_TIMEOUT);
+    LOG.log(Level.INFO, "REEF job completed: {0}", status);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloREEFMesos.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloREEFMesos.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloREEFMesos.java
new file mode 100644
index 0000000..b3b962b
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloREEFMesos.java
@@ -0,0 +1,55 @@
+/**
+ * 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.reef.examples.hello;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.runtime.mesos.client.MesosClientConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.InjectionException;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class HelloREEFMesos {
+  private static final Logger LOG = Logger.getLogger(HelloREEFMesos.class.getName());
+
+  private static Configuration getDriverConfiguration() {
+    return DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, HelloREEFMesos.class.getProtectionDomain().getCodeSource().getLocation().getFile())
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "HelloREEF")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, HelloDriver.StartHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HelloDriver.EvaluatorAllocatedHandler.class)
+        .build();
+  }
+
+  /**
+   * MASTER_IP(Mesos Master IP) is set to "localhost:5050".
+   * You may change it to suit your cluster environment.
+   */
+  public static void main(final String[] args) throws InjectionException {
+    final LauncherStatus status = DriverLauncher
+        .getLauncher(MesosClientConfiguration.CONF
+            .set(MesosClientConfiguration.MASTER_IP, "localhost:5050")
+            .build())
+        .run(getDriverConfiguration());
+    LOG.log(Level.INFO, "REEF job completed: {0}", status);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloREEFNoClient.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloREEFNoClient.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloREEFNoClient.java
new file mode 100644
index 0000000..066b336
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloREEFNoClient.java
@@ -0,0 +1,64 @@
+/**
+ * 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.reef.examples.hello;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.REEF;
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.util.EnvironmentUtils;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A main() for running hello REEF without a persistent client connection.
+ */
+public final class HelloREEFNoClient {
+
+  private static final Logger LOG = Logger.getLogger(HelloREEFNoClient.class.getName());
+
+  public static void runHelloReefWithoutClient(
+      final Configuration runtimeConf) throws InjectionException {
+
+    final REEF reef = Tang.Factory.getTang().newInjector(runtimeConf).getInstance(REEF.class);
+
+    final Configuration driverConf = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(HelloDriver.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "HelloREEF")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, HelloDriver.StartHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HelloDriver.EvaluatorAllocatedHandler.class)
+        .build();
+
+    reef.submit(driverConf);
+  }
+
+  public static void main(final String[] args) throws BindException, InjectionException {
+
+    final Configuration runtimeConfiguration = LocalRuntimeConfiguration.CONF
+        .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, 2)
+        .build();
+
+    runHelloReefWithoutClient(runtimeConfiguration);
+    LOG.log(Level.INFO, "Job Submitted");
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloReefYarn.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloReefYarn.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloReefYarn.java
new file mode 100644
index 0000000..a9d95a6
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloReefYarn.java
@@ -0,0 +1,70 @@
+/**
+ * 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.reef.examples.hello;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.runtime.yarn.client.YarnClientConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.InjectionException;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The Client for Hello REEF example.
+ */
+public final class HelloReefYarn {
+
+  private static final Logger LOG = Logger.getLogger(HelloReefYarn.class.getName());
+
+  /**
+   * Number of milliseconds to wait for the job to complete.
+   */
+  private static final int JOB_TIMEOUT = 30000; // 30 sec.
+
+
+  /**
+   * @return the configuration of the HelloREEF driver.
+   */
+  private static Configuration getDriverConfiguration() {
+    return DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, HelloReefYarn.class.getProtectionDomain().getCodeSource().getLocation().getFile())
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "HelloREEF")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, HelloDriver.StartHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HelloDriver.EvaluatorAllocatedHandler.class)
+        .build();
+  }
+
+  /**
+   * Start Hello REEF job. Runs method runHelloReef().
+   *
+   * @param args command line parameters.
+   * @throws org.apache.reef.tang.exceptions.BindException      configuration error.
+   * @throws org.apache.reef.tang.exceptions.InjectionException configuration error.
+   */
+  public static void main(final String[] args) throws InjectionException {
+
+    final LauncherStatus status = DriverLauncher
+        .getLauncher(YarnClientConfiguration.CONF.build())
+        .run(getDriverConfiguration(), JOB_TIMEOUT);
+    LOG.log(Level.INFO, "REEF job completed: {0}", status);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloTask.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloTask.java
new file mode 100644
index 0000000..a53fb8b
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/HelloTask.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.examples.hello;
+
+import org.apache.reef.task.Task;
+
+import javax.inject.Inject;
+
+/**
+ * A 'hello REEF' Task.
+ */
+public final class HelloTask implements Task {
+
+  @Inject
+  HelloTask() {
+  }
+
+  @Override
+  public final byte[] call(final byte[] memento) {
+    System.out.println("Hello, REEF!");
+    return null;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/package-info.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/package-info.java
new file mode 100644
index 0000000..66bc058
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hello/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * The Hello REEF example.
+ */
+package org.apache.reef.examples.hello;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hellohttp/HelloREEFHttp.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hellohttp/HelloREEFHttp.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hellohttp/HelloREEFHttp.java
new file mode 100644
index 0000000..a92499f
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hellohttp/HelloREEFHttp.java
@@ -0,0 +1,112 @@
+/**
+ * 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.reef.examples.hellohttp;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.DriverServiceConfiguration;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Configurations;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.util.EnvironmentUtils;
+import org.apache.reef.webserver.HttpHandlerConfiguration;
+import org.apache.reef.webserver.HttpServerReefEventHandler;
+import org.apache.reef.webserver.ReefEventStateManager;
+
+import java.util.logging.Logger;
+
+/**
+ * Example to run HelloREEF with a webserver.
+ */
+public final class HelloREEFHttp {
+  /**
+   * Number of milliseconds to wait for the job to complete.
+   */
+  public static final int JOB_TIMEOUT = 60 * 1000; // 60 sec.
+  private static final Logger LOG = Logger.getLogger(HelloREEFHttp.class.getName());
+
+  /**
+   * @return the driver-side configuration to be merged into the DriverConfiguration to enable the HTTP server.
+   */
+  public static Configuration getHTTPConfiguration() {
+    final Configuration httpHandlerConfiguration = HttpHandlerConfiguration.CONF
+        .set(HttpHandlerConfiguration.HTTP_HANDLERS, HttpServerReefEventHandler.class)
+        .set(HttpHandlerConfiguration.HTTP_HANDLERS, HttpServerShellCmdtHandler.class)
+        .build();
+    final Configuration driverConfigurationForHttpServer = DriverServiceConfiguration.CONF
+        .set(DriverServiceConfiguration.ON_EVALUATOR_ALLOCATED, ReefEventStateManager.AllocatedEvaluatorStateHandler.class)
+        .set(DriverServiceConfiguration.ON_CONTEXT_ACTIVE, ReefEventStateManager.ActiveContextStateHandler.class)
+        .set(DriverServiceConfiguration.ON_TASK_RUNNING, ReefEventStateManager.TaskRunningStateHandler.class)
+        .set(DriverServiceConfiguration.ON_DRIVER_STARTED, ReefEventStateManager.StartStateHandler.class)
+        .set(DriverServiceConfiguration.ON_DRIVER_STOP, ReefEventStateManager.StopStateHandler.class)
+        .build();
+    return Configurations.merge(httpHandlerConfiguration, driverConfigurationForHttpServer);
+  }
+
+  /**
+   * @return the configuration of the HelloREEF driver.
+   */
+  public static Configuration getDriverConfiguration() {
+    return DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(HttpShellJobDriver.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "HelloHTTP")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, HttpShellJobDriver.StartHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HttpShellJobDriver.AllocatedEvaluatorHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_FAILED, HttpShellJobDriver.FailedEvaluatorHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_ACTIVE, HttpShellJobDriver.ActiveContextHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_CLOSED, HttpShellJobDriver.ClosedContextHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_FAILED, HttpShellJobDriver.FailedContextHandler.class)
+        .set(DriverConfiguration.ON_TASK_COMPLETED, HttpShellJobDriver.CompletedTaskHandler.class)
+        .set(DriverConfiguration.ON_CLIENT_MESSAGE, HttpShellJobDriver.ClientMessageHandler.class)
+        .set(DriverConfiguration.ON_CLIENT_CLOSED, HttpShellJobDriver.HttpClientCloseHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_STOP, HttpShellJobDriver.StopHandler.class)
+        .build();
+  }
+
+  /**
+   * Run Hello Reef with merged configuration
+   *
+   * @param runtimeConf
+   * @param timeOut
+   * @return
+   * @throws BindException
+   * @throws InjectionException
+   */
+  public static LauncherStatus runHelloReef(final Configuration runtimeConf, final int timeOut)
+      throws BindException, InjectionException {
+    final Configuration driverConf = Configurations.merge(HelloREEFHttp.getDriverConfiguration(), getHTTPConfiguration());
+    return DriverLauncher.getLauncher(runtimeConf).run(driverConf, timeOut);
+  }
+
+  /**
+   * main program
+   *
+   * @param args
+   * @throws InjectionException
+   */
+  public static void main(final String[] args) throws InjectionException {
+    final Configuration runtimeConfiguration = LocalRuntimeConfiguration.CONF
+        .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, 3)
+        .build();
+    final LauncherStatus status = runHelloReef(runtimeConfiguration, HelloREEFHttp.JOB_TIMEOUT);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hellohttp/HelloREEFHttpYarn.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hellohttp/HelloREEFHttpYarn.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hellohttp/HelloREEFHttpYarn.java
new file mode 100644
index 0000000..f3b05de
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hellohttp/HelloREEFHttpYarn.java
@@ -0,0 +1,52 @@
+/**
+ * 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.reef.examples.hellohttp;
+
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.runtime.yarn.client.YarnClientConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * HelloREEFHttp for running on Yarn
+ */
+public class HelloREEFHttpYarn {
+
+  private static final Logger LOG = Logger.getLogger(HelloREEFHttpYarn.class.getName());
+
+  /**
+   * Start Hello REEF job. Runs method runHelloReef().
+   *
+   * @param args command line parameters.
+   * @throws org.apache.reef.tang.exceptions.BindException      configuration error.
+   * @throws org.apache.reef.tang.exceptions.InjectionException configuration error.
+   */
+  public static void main(final String[] args) throws BindException, InjectionException, IOException {
+
+    final Configuration runtimeConfiguration = YarnClientConfiguration.CONF.build();
+
+    final LauncherStatus status = HelloREEFHttp.runHelloReef(runtimeConfiguration, HelloREEFHttp.JOB_TIMEOUT);
+    LOG.log(Level.INFO, "REEF job completed: {0}", status);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hellohttp/HttpServerShellCmdtHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hellohttp/HttpServerShellCmdtHandler.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hellohttp/HttpServerShellCmdtHandler.java
new file mode 100644
index 0000000..ff22d81
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hellohttp/HttpServerShellCmdtHandler.java
@@ -0,0 +1,168 @@
+/**
+ * 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.reef.examples.hellohttp;
+
+import org.apache.reef.tang.InjectionFuture;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.util.CommandUtils;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.webserver.HttpHandler;
+import org.apache.reef.webserver.ParsedHttpRequest;
+
+import javax.inject.Inject;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Http Event handler for Shell Command
+ */
+@Unit
+class HttpServerShellCmdtHandler implements HttpHandler {
+  /**
+   * Standard Java logger.
+   */
+  private static final Logger LOG = Logger.getLogger(HttpServerShellCmdtHandler.class.getName());
+
+  private static final int WAIT_TIMEOUT = 10 * 1000;
+
+  private static final int WAIT_TIME = 50;
+
+  /**
+   * ClientMessageHandler
+   */
+  private final InjectionFuture<HttpShellJobDriver.ClientMessageHandler> messageHandler;
+
+  /**
+   * uri specification
+   */
+  private String uriSpecification = "Command";
+
+  /**
+   * output for command
+   */
+  private String cmdOutput = null;
+
+  /**
+   * HttpServerDistributedShellEventHandler constructor.
+   */
+  @Inject
+  public HttpServerShellCmdtHandler(final InjectionFuture<HttpShellJobDriver.ClientMessageHandler> messageHandler) {
+    this.messageHandler = messageHandler;
+  }
+
+  /**
+   * returns URI specification for the handler
+   *
+   * @return
+   */
+  @Override
+  public String getUriSpecification() {
+    return uriSpecification;
+  }
+
+  /**
+   * set URI specification
+   *
+   * @param s
+   */
+  public void setUriSpecification(final String s) {
+    uriSpecification = s;
+  }
+
+  /**
+   * it is called when receiving a http request
+   *
+   * @param parsedHttpRequest
+   * @param response
+   */
+  @Override
+  public final synchronized void onHttpRequest(final ParsedHttpRequest parsedHttpRequest, final HttpServletResponse response) throws IOException, ServletException {
+    LOG.log(Level.INFO, "HttpServeShellCmdtHandler in webserver onHttpRequest is called: {0}", parsedHttpRequest.getRequestUri());
+    final Map<String, List<String>> queries = parsedHttpRequest.getQueryMap();
+    final String queryStr = parsedHttpRequest.getQueryString();
+
+    if (parsedHttpRequest.getTargetEntity().equalsIgnoreCase("Evaluators")) {
+      final byte[] b = HttpShellJobDriver.CODEC.encode(queryStr);
+      LOG.log(Level.INFO, "HttpServeShellCmdtHandler call HelloDriver onCommand(): {0}", queryStr);
+      messageHandler.get().onNext(b);
+
+      notify();
+
+      final long endTime = System.currentTimeMillis() + WAIT_TIMEOUT;
+      while (cmdOutput == null) {
+        final long waitTime = endTime - System.currentTimeMillis();
+        if (waitTime <= 0) {
+          break;
+        }
+
+        try {
+          wait(WAIT_TIME);
+        } catch (final InterruptedException e) {
+          LOG.log(Level.WARNING, "HttpServeShellCmdtHandler onHttpRequest InterruptedException: {0}", e);
+        }
+      }
+      response.getOutputStream().write(cmdOutput.getBytes(Charset.forName("UTF-8")));
+      cmdOutput = null;
+    } else if (parsedHttpRequest.getTargetEntity().equalsIgnoreCase("Driver")) {
+      final String cmdOutput = CommandUtils.runCommand(queryStr);
+      response.getOutputStream().write(cmdOutput.getBytes(Charset.forName("UTF-8")));
+    }
+  }
+
+  /**
+   * called after shell command is completed
+   *
+   * @param message
+   */
+  public final synchronized void onHttpCallback(byte[] message) {
+    final long endTime = System.currentTimeMillis() + WAIT_TIMEOUT;
+    while (cmdOutput != null) {
+      final long waitTime = endTime - System.currentTimeMillis();
+      if (waitTime <= 0) {
+        break;
+      }
+
+      try {
+        wait(WAIT_TIME);
+      } catch (final InterruptedException e) {
+        LOG.log(Level.WARNING, "HttpServeShellCmdtHandler onHttpCallback InterruptedException: {0}", e);
+      }
+    }
+    LOG.log(Level.INFO, "HttpServeShellCmdtHandler OnCallback: {0}", HttpShellJobDriver.CODEC.decode(message));
+    cmdOutput = HttpShellJobDriver.CODEC.decode(message);
+
+    notify();
+  }
+
+  /**
+   * Handler for client to call back
+   */
+  final class ClientCallBackHandler implements EventHandler<byte[]> {
+    @Override
+    public void onNext(final byte[] message) {
+      HttpServerShellCmdtHandler.this.onHttpCallback(message);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hellohttp/HttpShellJobDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hellohttp/HttpShellJobDriver.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hellohttp/HttpShellJobDriver.java
new file mode 100644
index 0000000..44b62a3
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/hellohttp/HttpShellJobDriver.java
@@ -0,0 +1,364 @@
+/**
+ * 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.reef.examples.hellohttp;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ClosedContext;
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.driver.evaluator.FailedEvaluator;
+import org.apache.reef.driver.task.CompletedTask;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.examples.library.Command;
+import org.apache.reef.examples.library.ShellTask;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+import org.apache.reef.wake.time.event.StartTime;
+import org.apache.reef.wake.time.event.StopTime;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The Driver code for the Hello REEF Http Distributed Shell Application
+ */
+@Unit
+public final class HttpShellJobDriver {
+
+  /**
+   * String codec is used to encode the results
+   * before passing them back to the client.
+   */
+  public static final ObjectSerializableCodec<String> CODEC = new ObjectSerializableCodec<>();
+  private static final Logger LOG = Logger.getLogger(HttpShellJobDriver.class.getName());
+  /**
+   * Evaluator Requester
+   */
+  private final EvaluatorRequestor evaluatorRequestor;
+  /**
+   * Number of Evalutors to request (default is 1).
+   */
+  private final int numEvaluators = 2;
+  /**
+   * Shell execution results from each Evaluator.
+   */
+  private final List<String> results = new ArrayList<>();
+  /**
+   * Map from context ID to running evaluator context.
+   */
+  private final Map<String, ActiveContext> contexts = new HashMap<>();
+  /**
+   * Job driver state.
+   */
+  private State state = State.INIT;
+  /**
+   * First command to execute. Sometimes client can send us the first command
+   * before Evaluators are available; we need to store this command here.
+   */
+  private String cmd;
+  /**
+   * Number of evaluators/tasks to complete.
+   */
+  private int expectCount = 0;
+  /**
+   * Callback handler for http return message
+   */
+  private HttpServerShellCmdtHandler.ClientCallBackHandler httpCallbackHandler;
+
+  /**
+   * Job Driver Constructor
+   *
+   * @param requestor
+   * @param clientCallBackHandler
+   */
+  @Inject
+  public HttpShellJobDriver(final EvaluatorRequestor requestor, final HttpServerShellCmdtHandler.ClientCallBackHandler clientCallBackHandler) {
+    this.evaluatorRequestor = requestor;
+    this.httpCallbackHandler = clientCallBackHandler;
+    LOG.log(Level.FINE, "Instantiated 'HelloDriver'");
+  }
+
+  /**
+   * Construct the final result and forward it to the Client.
+   */
+  private void returnResults() {
+    final StringBuilder sb = new StringBuilder();
+    for (final String result : this.results) {
+      sb.append(result);
+    }
+    this.results.clear();
+    LOG.log(Level.INFO, "Return results to the client:\n{0}", sb);
+    httpCallbackHandler.onNext(CODEC.encode(sb.toString()));
+  }
+
+  /**
+   * Submit command to all available evaluators.
+   *
+   * @param command shell command to execute.
+   */
+  private void submit(final String command) {
+    LOG.log(Level.INFO, "Submit command {0} to {1} evaluators. state: {2}",
+        new Object[]{command, this.contexts.size(), this.state});
+    assert (this.state == State.READY);
+    this.expectCount = this.contexts.size();
+    this.state = State.WAIT_TASKS;
+    this.cmd = null;
+    for (final ActiveContext context : this.contexts.values()) {
+      this.submit(context, command);
+    }
+  }
+
+  /**
+   * Submit a Task that execute the command to a single Evaluator.
+   * This method is called from <code>submitTask(cmd)</code>.
+   */
+  private void submit(final ActiveContext context, final String command) {
+    try {
+      LOG.log(Level.INFO, "Send command {0} to context: {1}", new Object[]{command, context});
+      final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+      cb.addConfiguration(
+          TaskConfiguration.CONF
+              .set(TaskConfiguration.IDENTIFIER, context.getId() + "_task")
+              .set(TaskConfiguration.TASK, ShellTask.class)
+              .build()
+      );
+      cb.bindNamedParameter(Command.class, command);
+      context.submitTask(cb.build());
+    } catch (final BindException ex) {
+      LOG.log(Level.SEVERE, "Bad Task configuration for context: " + context.getId(), ex);
+      context.close();
+      throw new RuntimeException(ex);
+    }
+  }
+
+  /**
+   * Request the evaluators.
+   */
+  private synchronized void requestEvaluators() {
+    assert (this.state == State.INIT);
+    LOG.log(Level.INFO, "Schedule on {0} Evaluators.", this.numEvaluators);
+    this.evaluatorRequestor.submit(
+        EvaluatorRequest.newBuilder()
+            .setMemory(128)
+            .setNumberOfCores(1)
+            .setNumber(this.numEvaluators).build()
+    );
+    this.state = State.WAIT_EVALUATORS;
+    this.expectCount = this.numEvaluators;
+  }
+
+  /**
+   * Possible states of the job driver. Can be one of:
+   * <dl>
+   * <du><code>INIT</code></du><dd>initial state, ready to request the evaluators.</dd>
+   * <du><code>WAIT_EVALUATORS</code></du><dd>Wait for requested evaluators to initialize.</dd>
+   * <du><code>READY</code></du><dd>Ready to submitTask a new task.</dd>
+   * <du><code>WAIT_TASKS</code></du><dd>Wait for tasks to complete.</dd>
+   * </dl>
+   */
+  private enum State {
+    INIT, WAIT_EVALUATORS, READY, WAIT_TASKS
+  }
+
+  /**
+   * Receive notification that an Evaluator had been allocated,
+   * and submitTask a new Task in that Evaluator.
+   */
+  final class AllocatedEvaluatorHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator eval) {
+      synchronized (HttpShellJobDriver.this) {
+        LOG.log(Level.INFO, "Allocated Evaluator: {0} expect {1} running {2}",
+            new Object[]{eval.getId(), HttpShellJobDriver.this.expectCount, HttpShellJobDriver.this.contexts.size()});
+        assert (HttpShellJobDriver.this.state == State.WAIT_EVALUATORS);
+        try {
+          eval.submitContext(ContextConfiguration.CONF.set(
+              ContextConfiguration.IDENTIFIER, eval.getId() + "_context").build());
+        } catch (final BindException ex) {
+          LOG.log(Level.SEVERE, "Failed to submit a context to evaluator: " + eval.getId(), ex);
+          throw new RuntimeException(ex);
+        }
+      }
+    }
+  }
+
+  /**
+   * Receive notification that the entire Evaluator had failed.
+   * Stop other jobs and pass this error to the job observer on the client.
+   */
+  final class FailedEvaluatorHandler implements EventHandler<FailedEvaluator> {
+    @Override
+    public void onNext(final FailedEvaluator eval) {
+      synchronized (HttpShellJobDriver.this) {
+        LOG.log(Level.SEVERE, "FailedEvaluator", eval);
+        for (final FailedContext failedContext : eval.getFailedContextList()) {
+          HttpShellJobDriver.this.contexts.remove(failedContext.getId());
+        }
+        throw new RuntimeException("Failed Evaluator: ", eval.getEvaluatorException());
+      }
+    }
+  }
+
+  /**
+   * Receive notification that a new Context is available.
+   * Submit a new Distributed Shell Task to that Context.
+   */
+  final class ActiveContextHandler implements EventHandler<ActiveContext> {
+    @Override
+    public void onNext(final ActiveContext context) {
+      synchronized (HttpShellJobDriver.this) {
+        LOG.log(Level.INFO, "Context available: {0} expect {1} state {2}",
+            new Object[]{context.getId(), HttpShellJobDriver.this.expectCount, HttpShellJobDriver.this.state});
+        assert (HttpShellJobDriver.this.state == State.WAIT_EVALUATORS);
+        HttpShellJobDriver.this.contexts.put(context.getId(), context);
+        if (--HttpShellJobDriver.this.expectCount <= 0) {
+          HttpShellJobDriver.this.state = State.READY;
+          if (HttpShellJobDriver.this.cmd == null) {
+            LOG.log(Level.INFO, "All evaluators ready; waiting for command. State: {0}",
+                HttpShellJobDriver.this.state);
+          } else {
+            HttpShellJobDriver.this.submit(HttpShellJobDriver.this.cmd);
+          }
+        }
+      }
+    }
+  }
+
+  /**
+   * Receive notification that the Context had completed.
+   * Remove context from the list of active context.
+   */
+  final class ClosedContextHandler implements EventHandler<ClosedContext> {
+    @Override
+    public void onNext(final ClosedContext context) {
+      LOG.log(Level.INFO, "Completed Context: {0}", context.getId());
+      synchronized (HttpShellJobDriver.this) {
+        HttpShellJobDriver.this.contexts.remove(context.getId());
+      }
+    }
+  }
+
+  final class HttpClientCloseHandler implements EventHandler<Void> {
+    @Override
+    public void onNext(final Void aVoid) throws RuntimeException {
+      LOG.log(Level.INFO, "Received a close message from the client. You can put code here to properly close drivers and evaluators.");
+      for (final ActiveContext c : contexts.values()) {
+        c.close();
+      }
+    }
+  }
+
+  /**
+   * Receive notification that the Context had failed.
+   * Remove context from the list of active context and notify the client.
+   */
+  final class FailedContextHandler implements EventHandler<FailedContext> {
+    @Override
+    public void onNext(final FailedContext context) {
+      LOG.log(Level.SEVERE, "FailedContext", context);
+      synchronized (HttpShellJobDriver.this) {
+        HttpShellJobDriver.this.contexts.remove(context.getId());
+      }
+      throw new RuntimeException("Failed context: ", context.asError());
+    }
+  }
+
+  /**
+   * Receive notification that the Task has completed successfully.
+   */
+  final class CompletedTaskHandler implements EventHandler<CompletedTask> {
+    @Override
+    public void onNext(final CompletedTask task) {
+      LOG.log(Level.INFO, "Completed task: {0}", task.getId());
+      // Take the message returned by the task and add it to the running result.
+      final String result = CODEC.decode(task.get());
+      synchronized (HttpShellJobDriver.this) {
+        HttpShellJobDriver.this.results.add(task.getId() + " :: " + result);
+        LOG.log(Level.INFO, "Task {0} result {1}: {2} state: {3}", new Object[]{
+            task.getId(), HttpShellJobDriver.this.results.size(), result, HttpShellJobDriver.this.state});
+        if (--HttpShellJobDriver.this.expectCount <= 0) {
+          HttpShellJobDriver.this.returnResults();
+          HttpShellJobDriver.this.state = State.READY;
+          if (HttpShellJobDriver.this.cmd != null) {
+            HttpShellJobDriver.this.submit(HttpShellJobDriver.this.cmd);
+          }
+        }
+      }
+    }
+  }
+
+  /**
+   * Receive notification from the client.
+   */
+  final class ClientMessageHandler implements EventHandler<byte[]> {
+    @Override
+    public void onNext(final byte[] message) {
+      synchronized (HttpShellJobDriver.this) {
+        final String command = CODEC.decode(message);
+        LOG.log(Level.INFO, "Client message: {0} state: {1}",
+            new Object[]{command, HttpShellJobDriver.this.state});
+        assert (HttpShellJobDriver.this.cmd == null);
+        if (HttpShellJobDriver.this.state == State.READY) {
+          HttpShellJobDriver.this.submit(command);
+        } else {
+          // not ready yet - save the command for better times.
+          assert (HttpShellJobDriver.this.state == State.WAIT_EVALUATORS);
+          HttpShellJobDriver.this.cmd = command;
+        }
+      }
+    }
+  }
+
+  /**
+   * Job Driver is ready and the clock is set up: request the evaluators.
+   */
+  final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime startTime) {
+      LOG.log(Level.INFO, "{0} StartTime: {1}", new Object[]{state, startTime});
+      assert (state == State.INIT);
+      requestEvaluators();
+    }
+  }
+
+  /**
+   * Shutting down the job driver: close the evaluators.
+   */
+  final class StopHandler implements EventHandler<StopTime> {
+    @Override
+    public void onNext(final StopTime time) {
+      LOG.log(Level.INFO, "{0} StopTime: {1}", new Object[]{state, time});
+      for (final ActiveContext context : contexts.values()) {
+        context.close();
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/library/Command.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/library/Command.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/library/Command.java
new file mode 100644
index 0000000..85d811a
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/library/Command.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.examples.library;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * Command line parameter: a command to run. e.g. "echo Hello REEF"
+ */
+@NamedParameter(doc = "The shell command", short_name = "cmd", default_value = "*INTERACTIVE*")
+public final class Command implements Name<String> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/library/ShellTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/library/ShellTask.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/library/ShellTask.java
new file mode 100644
index 0000000..0ea7b99
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/library/ShellTask.java
@@ -0,0 +1,73 @@
+/**
+ * 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.reef.examples.library;
+
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.task.Task;
+import org.apache.reef.util.CommandUtils;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Execute command, capture its stdout, and return that string to the job driver.
+ */
+public class ShellTask implements Task {
+
+  /**
+   * Standard java logger.
+   */
+  private static final Logger LOG = Logger.getLogger(ShellTask.class.getName());
+
+  /**
+   * A command to execute.
+   */
+  private final String command;
+
+  /**
+   * Object Serializable Codec
+   */
+  private static final ObjectSerializableCodec<String> CODEC = new ObjectSerializableCodec<>();
+
+  /**
+   * Task constructor. Parameters are injected automatically by TANG.
+   *
+   * @param command a command to execute.
+   */
+  @Inject
+  private ShellTask(@Parameter(Command.class) final String command) {
+    this.command = command;
+  }
+
+  /**
+   * Execute the shell command and return the result, which is sent back to
+   * the JobDriver and surfaced in the CompletedTask object.
+   *
+   * @param memento ignored.
+   * @return byte string containing the stdout from executing the shell command.
+   */
+  @Override
+  public byte[] call(final byte[] memento) {
+    String result = CommandUtils.runCommand(this.command);
+    LOG.log(Level.INFO, result);
+    return CODEC.encode(result);
+  }
+}


[23/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/HDInsightDriverConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/HDInsightDriverConfiguration.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/HDInsightDriverConfiguration.java
new file mode 100644
index 0000000..f372fa1
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/HDInsightDriverConfiguration.java
@@ -0,0 +1,95 @@
+/**
+ * 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.reef.runtime.hdinsight.client;
+
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.io.TempFileCreator;
+import org.apache.reef.io.WorkingDirectoryTempFileCreator;
+import org.apache.reef.runtime.common.driver.api.AbstractDriverRuntimeConfiguration;
+import org.apache.reef.runtime.common.driver.api.ResourceLaunchHandler;
+import org.apache.reef.runtime.common.driver.api.ResourceReleaseHandler;
+import org.apache.reef.runtime.common.driver.api.ResourceRequestHandler;
+import org.apache.reef.runtime.common.files.RuntimeClasspathProvider;
+import org.apache.reef.runtime.common.parameters.JVMHeapSlack;
+import org.apache.reef.runtime.hdinsight.HDInsightClasspathProvider;
+import org.apache.reef.runtime.yarn.driver.*;
+import org.apache.reef.runtime.yarn.driver.parameters.JobSubmissionDirectory;
+import org.apache.reef.runtime.yarn.driver.parameters.YarnHeartbeatPeriod;
+import org.apache.reef.runtime.yarn.util.YarnConfigurationConstructor;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.OptionalParameter;
+import org.apache.reef.tang.formats.RequiredParameter;
+import org.apache.reef.wake.time.Clock;
+
+/**
+ * ConfigurationModule to create a Driver configuration.
+ */
+@Private
+@ClientSide
+public final class HDInsightDriverConfiguration extends ConfigurationModuleBuilder {
+
+  /**
+   * @see org.apache.reef.runtime.yarn.driver.parameters.JobSubmissionDirectory
+   */
+  public static final RequiredParameter<String> JOB_SUBMISSION_DIRECTORY = new RequiredParameter<>();
+  /**
+   * @see org.apache.reef.runtime.yarn.driver.parameters.YarnHeartbeatPeriod.class
+   */
+  public static final OptionalParameter<Integer> YARN_HEARTBEAT_INTERVAL = new OptionalParameter<>();
+
+  /**
+   * @see AbstractDriverRuntimeConfiguration.JobIdentifier.class
+   */
+  public static final RequiredParameter<String> JOB_IDENTIFIER = new RequiredParameter<>();
+
+  /**
+   * @see AbstractDriverRuntimeConfiguration.EvaluatorTimeout
+   */
+  public static final OptionalParameter<Long> EVALUATOR_TIMEOUT = new OptionalParameter<>();
+
+  /**
+   * The fraction of the container memory NOT to use for the Java Heap.
+   */
+  public static final OptionalParameter<Double> JVM_HEAP_SLACK = new OptionalParameter<>();
+
+  public static final ConfigurationModule CONF = new HDInsightDriverConfiguration()
+
+      // Bind the YARN runtime for the resource manager.
+      .bindImplementation(ResourceLaunchHandler.class, YARNResourceLaunchHandler.class)
+      .bindImplementation(ResourceReleaseHandler.class, YARNResourceReleaseHandler.class)
+      .bindImplementation(ResourceRequestHandler.class, YarnResourceRequestHandler.class)
+      .bindConstructor(YarnConfiguration.class, YarnConfigurationConstructor.class)
+      .bindSetEntry(Clock.RuntimeStartHandler.class, YARNRuntimeStartHandler.class)
+      .bindSetEntry(Clock.RuntimeStopHandler.class, YARNRuntimeStopHandler.class)
+      .bindImplementation(TempFileCreator.class, WorkingDirectoryTempFileCreator.class)
+
+          // Bind the YARN Configuration parameters
+      .bindNamedParameter(JobSubmissionDirectory.class, JOB_SUBMISSION_DIRECTORY)
+      .bindNamedParameter(YarnHeartbeatPeriod.class, YARN_HEARTBEAT_INTERVAL)
+
+          // Bind the fields bound in AbstractDriverRuntimeConfiguration
+      .bindNamedParameter(AbstractDriverRuntimeConfiguration.JobIdentifier.class, JOB_IDENTIFIER)
+      .bindNamedParameter(AbstractDriverRuntimeConfiguration.EvaluatorTimeout.class, EVALUATOR_TIMEOUT)
+      .bindNamedParameter(JVMHeapSlack.class, JVM_HEAP_SLACK)
+      .bindImplementation(RuntimeClasspathProvider.class, HDInsightClasspathProvider.class)
+      .build();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/HDInsightJobSubmissionHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/HDInsightJobSubmissionHandler.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/HDInsightJobSubmissionHandler.java
new file mode 100644
index 0000000..7ac314a
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/HDInsightJobSubmissionHandler.java
@@ -0,0 +1,180 @@
+/**
+ * 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.reef.runtime.hdinsight.client;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.yarn.api.ApplicationConstants;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.ClientRuntimeProtocol;
+import org.apache.reef.runtime.common.client.api.JobSubmissionHandler;
+import org.apache.reef.runtime.common.files.ClasspathProvider;
+import org.apache.reef.runtime.common.files.JobJarMaker;
+import org.apache.reef.runtime.common.files.REEFFileNames;
+import org.apache.reef.runtime.common.launch.JavaLaunchCommandBuilder;
+import org.apache.reef.runtime.common.parameters.JVMHeapSlack;
+import org.apache.reef.runtime.hdinsight.client.yarnrest.*;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Configurations;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.formats.ConfigurationSerializer;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Handles job submission to a HDInsight instance.
+ */
+@ClientSide
+@Private
+public final class HDInsightJobSubmissionHandler implements JobSubmissionHandler {
+
+  private static final Logger LOG = Logger.getLogger(HDInsightJobSubmissionHandler.class.getName());
+
+  private final AzureUploader uploader;
+  private final JobJarMaker jobJarMaker;
+  private final HDInsightInstance hdInsightInstance;
+  private final ConfigurationSerializer configurationSerializer;
+  private final REEFFileNames filenames;
+  private final ClasspathProvider classpath;
+  private final double jvmHeapSlack;
+
+  @Inject
+  HDInsightJobSubmissionHandler(final AzureUploader uploader,
+                                final JobJarMaker jobJarMaker,
+                                final HDInsightInstance hdInsightInstance,
+                                final ConfigurationSerializer configurationSerializer,
+                                final REEFFileNames filenames,
+                                final ClasspathProvider classpath,
+                                final @Parameter(JVMHeapSlack.class) double jvmHeapSlack) {
+    this.uploader = uploader;
+    this.jobJarMaker = jobJarMaker;
+    this.hdInsightInstance = hdInsightInstance;
+    this.configurationSerializer = configurationSerializer;
+    this.filenames = filenames;
+    this.classpath = classpath;
+    this.jvmHeapSlack = jvmHeapSlack;
+  }
+
+  @Override
+  public void close() {
+    LOG.log(Level.WARNING, ".close() is inconsequential with the HDInsight runtime");
+  }
+
+  @Override
+  public void onNext(final ClientRuntimeProtocol.JobSubmissionProto jobSubmissionProto) {
+
+    try {
+
+      LOG.log(Level.FINE, "Requesting Application ID from HDInsight.");
+      final ApplicationID applicationID = this.hdInsightInstance.getApplicationID();
+
+      LOG.log(Level.INFO, "Submitting application {0} to YARN.", applicationID.getId());
+
+      LOG.log(Level.FINE, "Creating a job folder on Azure.");
+      final String jobFolderURL = this.uploader.createJobFolder(applicationID.getId());
+
+      LOG.log(Level.FINE, "Assembling Configuration for the Driver.");
+      final Configuration driverConfiguration =
+          makeDriverConfiguration(jobSubmissionProto, applicationID.getId(), jobFolderURL);
+
+      LOG.log(Level.FINE, "Making Job JAR.");
+      final File jobSubmissionJarFile =
+          this.jobJarMaker.createJobSubmissionJAR(jobSubmissionProto, driverConfiguration);
+
+      LOG.log(Level.FINE, "Uploading Job JAR to Azure.");
+      final FileResource uploadedFile = this.uploader.uploadFile(jobSubmissionJarFile);
+
+      LOG.log(Level.FINE, "Assembling application submission.");
+      final String command = getCommandString(jobSubmissionProto);
+
+      final ApplicationSubmission applicationSubmission = new ApplicationSubmission()
+          .setApplicationId(applicationID.getId())
+          .setApplicationName(jobSubmissionProto.getIdentifier())
+          .setResource(getResource(jobSubmissionProto))
+          .setContainerInfo(new ContainerInfo()
+              .addFileResource(this.filenames.getREEFFolderName(), uploadedFile)
+              .addCommand(command));
+
+      this.hdInsightInstance.submitApplication(applicationSubmission);
+      LOG.log(Level.INFO, "Submitted application to HDInsight. The application id is: {0}", applicationID.getId());
+
+    } catch (final IOException ex) {
+      LOG.log(Level.SEVERE, "Error submitting HDInsight request", ex);
+      throw new RuntimeException(ex);
+    }
+  }
+
+  /**
+   * Extracts the resource demands from the jobSubmissionProto.
+   */
+  private final Resource getResource(
+      final ClientRuntimeProtocol.JobSubmissionProto jobSubmissionProto) {
+
+    return new Resource()
+        .setMemory(String.valueOf(jobSubmissionProto.getDriverMemory()))
+        .setvCores("1");
+  }
+
+  /**
+   * Assembles the command to execute the Driver.
+   */
+  private String getCommandString(
+      final ClientRuntimeProtocol.JobSubmissionProto jobSubmissionProto) {
+    return StringUtils.join(getCommandList(jobSubmissionProto), ' ');
+  }
+
+  /**
+   * Assembles the command to execute the Driver in list form.
+   */
+  private List<String> getCommandList(
+      final ClientRuntimeProtocol.JobSubmissionProto jobSubmissionProto) {
+
+    return new JavaLaunchCommandBuilder()
+        .setJavaPath("%JAVA_HOME%/bin/java")
+        .setErrorHandlerRID(jobSubmissionProto.getRemoteId())
+        .setLaunchID(jobSubmissionProto.getIdentifier())
+        .setConfigurationFileName(this.filenames.getDriverConfigurationPath())
+        .setClassPath(this.classpath.getDriverClasspath())
+        .setMemory(jobSubmissionProto.getDriverMemory())
+        .setStandardErr(ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/" + this.filenames.getDriverStderrFileName())
+        .setStandardOut(ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/" + this.filenames.getDriverStdoutFileName())
+        .build();
+  }
+
+  private Configuration makeDriverConfiguration(
+      final ClientRuntimeProtocol.JobSubmissionProto jobSubmissionProto,
+      final String applicationId,
+      final String jobFolderURL) throws IOException {
+
+    final Configuration hdinsightDriverConfiguration = HDInsightDriverConfiguration.CONF
+        .set(HDInsightDriverConfiguration.JOB_IDENTIFIER, applicationId)
+        .set(HDInsightDriverConfiguration.JOB_SUBMISSION_DIRECTORY, jobFolderURL)
+        .set(HDInsightDriverConfiguration.JVM_HEAP_SLACK, this.jvmHeapSlack)
+        .build();
+
+    return Configurations.merge(
+        this.configurationSerializer.fromString(jobSubmissionProto.getConfiguration()),
+        hdinsightDriverConfiguration);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/HDInsightRuntimeConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/HDInsightRuntimeConfiguration.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/HDInsightRuntimeConfiguration.java
new file mode 100644
index 0000000..22e3d1d
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/HDInsightRuntimeConfiguration.java
@@ -0,0 +1,123 @@
+/**
+ * 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.reef.runtime.hdinsight.client;
+
+import org.apache.reef.runtime.hdinsight.parameters.*;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Configurations;
+import org.apache.reef.tang.formats.AvroConfigurationSerializer;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.RequiredParameter;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Configuration module to setup REEF to submit jobs to HDInsight.
+ */
+public final class HDInsightRuntimeConfiguration extends ConfigurationModuleBuilder {
+
+  /**
+   * The URL of the hdinsight web service. E.g. http://services.mycompany.com:1234/templeton/v1/
+   */
+  public static final RequiredParameter<String> URL = new RequiredParameter<>();
+
+  /**
+   * The Storage account to be used by Azure.
+   */
+  public static final RequiredParameter<String> STORAGE_ACCOUNT_NAME = new RequiredParameter<>();
+
+  /**
+   * The Storage account key to be used by Azure.
+   */
+  public static final RequiredParameter<String> STORAGE_ACCOUNT_KEY = new RequiredParameter<>();
+
+  /**
+   * The Container name to be used by Azure.
+   */
+  public static final RequiredParameter<String> CONTAINER_NAME = new RequiredParameter<>();
+
+  /**
+   * The username to be used for connecting to hdinsight.
+   */
+  public static final RequiredParameter<String> USER_NAME = new RequiredParameter<>();
+
+  /**
+   * The password to be used for connecting to hdinsight.
+   */
+  public static final RequiredParameter<String> PASSWORD = new RequiredParameter<>();
+
+  /**
+   * The environment variable that holds the path to the default configuration file
+   */
+  public static final String HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE = "REEF_HDI_CONF";
+
+  public static final ConfigurationModule CONF = new HDInsightRuntimeConfiguration()
+      .merge(HDInsightRuntimeConfigurationStatic.CONF)
+      .bindNamedParameter(AzureStorageAccountName.class, STORAGE_ACCOUNT_NAME)
+      .bindNamedParameter(AzureStorageAccountKey.class, STORAGE_ACCOUNT_KEY)
+      .bindNamedParameter(AzureStorageAccountContainerName.class, CONTAINER_NAME)
+      .bindNamedParameter(HDInsightInstanceURL.class, URL)
+      .bindNamedParameter(HDInsightUsername.class, USER_NAME)
+      .bindNamedParameter(HDInsightPassword.class, PASSWORD)
+      .build();
+
+  /**
+   * Returns a HDInsight runtime configuration from the credentials stored in the given file.
+   *
+   * @param file
+   * @return a HDInsight runtime configuration from the credentials stored in the given file.
+   * @throws IOException if the file can't be read
+   */
+  public static Configuration fromTextFile(final File file) throws IOException {
+    final Configuration loaded = new AvroConfigurationSerializer().fromTextFile(file);
+    final Configuration staticConfiguration = HDInsightRuntimeConfigurationStatic.CONF.build();
+    return Configurations.merge(loaded, staticConfiguration);
+  }
+
+  /**
+   * @return the RuntimeConfiguration that is stored in a file refered to
+   * by the environment variable HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE.
+   * @throws IOException
+   * @see HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE
+   */
+  public static Configuration fromEnvironment() throws IOException {
+
+    final String configurationPath =
+        System.getenv(HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE);
+
+    if (null == configurationPath) {
+      throw new IOException("Environment Variable " +
+          HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE +
+          " not set.");
+    }
+
+    final File configurationFile = new File(configurationPath);
+    if (!configurationFile.canRead()) {
+      throw new IOException("Environment Variable " +
+          HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE +
+          " points to a file " + configurationFile.getAbsolutePath() +
+          " which can't be read."
+      );
+    }
+
+    return fromTextFile(configurationFile);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/HDInsightRuntimeConfigurationStatic.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/HDInsightRuntimeConfigurationStatic.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/HDInsightRuntimeConfigurationStatic.java
new file mode 100644
index 0000000..e84e77f
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/HDInsightRuntimeConfigurationStatic.java
@@ -0,0 +1,53 @@
+/**
+ * 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.reef.runtime.hdinsight.client;
+
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.reef.client.REEF;
+import org.apache.reef.client.RunningJob;
+import org.apache.reef.runtime.common.client.REEFImplementation;
+import org.apache.reef.runtime.common.client.RunningJobImpl;
+import org.apache.reef.runtime.common.client.api.JobSubmissionHandler;
+import org.apache.reef.runtime.common.files.RuntimeClasspathProvider;
+import org.apache.reef.runtime.common.launch.REEFMessageCodec;
+import org.apache.reef.runtime.hdinsight.HDInsightClasspathProvider;
+import org.apache.reef.runtime.hdinsight.client.sslhacks.DefaultClientConstructor;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.util.logging.LoggingSetup;
+import org.apache.reef.wake.remote.RemoteConfiguration;
+
+/**
+ * The static part of the HDInsightRuntimeConfiguration.
+ */
+public final class HDInsightRuntimeConfigurationStatic extends ConfigurationModuleBuilder {
+  static {
+    LoggingSetup.setupCommonsLogging();
+  }
+
+  public static final ConfigurationModule CONF = new HDInsightRuntimeConfigurationStatic()
+      .bindImplementation(REEF.class, REEFImplementation.class)
+      .bindImplementation(RunningJob.class, RunningJobImpl.class)
+      .bindNamedParameter(RemoteConfiguration.MessageCodec.class, REEFMessageCodec.class)
+      .bindImplementation(JobSubmissionHandler.class, HDInsightJobSubmissionHandler.class)
+      .bindConstructor(CloseableHttpClient.class, DefaultClientConstructor.class)
+      .bindImplementation(RuntimeClasspathProvider.class, HDInsightClasspathProvider.class)
+      .build();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/UnsafeHDInsightRuntimeConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/UnsafeHDInsightRuntimeConfiguration.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/UnsafeHDInsightRuntimeConfiguration.java
new file mode 100644
index 0000000..a96f5e5
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/UnsafeHDInsightRuntimeConfiguration.java
@@ -0,0 +1,118 @@
+/**
+ * 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.reef.runtime.hdinsight.client;
+
+import org.apache.reef.runtime.hdinsight.parameters.*;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Configurations;
+import org.apache.reef.tang.formats.AvroConfigurationSerializer;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.RequiredParameter;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Same as HDInsightRuntimeConfiguration, but ignores SSL errors on submission.
+ */
+public final class UnsafeHDInsightRuntimeConfiguration extends ConfigurationModuleBuilder {
+
+  /**
+   * The URL of the hdinsight web service. E.g. http://services.mycompany.com:1234/templeton/v1/
+   */
+  public static final RequiredParameter<String> URL = new RequiredParameter<>();
+
+  /**
+   * The Storage account to be used by Azure.
+   */
+  public static final RequiredParameter<String> STORAGE_ACCOUNT_NAME = new RequiredParameter<>();
+
+  /**
+   * The Storage account key to be used by Azure.
+   */
+  public static final RequiredParameter<String> STORAGE_ACCOUNT_KEY = new RequiredParameter<>();
+
+  /**
+   * The Container name to be used by Azure.
+   */
+  public static final RequiredParameter<String> CONTAINER_NAME = new RequiredParameter<>();
+
+  /**
+   * The username to be used for connecting to hdinsight.
+   */
+  public static final RequiredParameter<String> USER_NAME = new RequiredParameter<>();
+
+  /**
+   * The password to be used for connecting to hdinsight.
+   */
+  public static final RequiredParameter<String> PASSWORD = new RequiredParameter<>();
+
+  public static final ConfigurationModule CONF = new UnsafeHDInsightRuntimeConfiguration()
+      .merge(UnsafeHDInsightRuntimeConfigurationStatic.CONF)
+      .bindNamedParameter(AzureStorageAccountName.class, STORAGE_ACCOUNT_NAME)
+      .bindNamedParameter(AzureStorageAccountKey.class, STORAGE_ACCOUNT_KEY)
+      .bindNamedParameter(AzureStorageAccountContainerName.class, CONTAINER_NAME)
+      .bindNamedParameter(HDInsightInstanceURL.class, URL)
+      .bindNamedParameter(HDInsightUsername.class, USER_NAME)
+      .bindNamedParameter(HDInsightPassword.class, PASSWORD)
+      .build();
+
+  /**
+   * Returns an UNSAFE HDInsight runtime configuration from the credentials stored in the given file.
+   *
+   * @param file
+   * @return an UNSAFE HDInsight runtime configuration from the credentials stored in the given file.
+   * @throws java.io.IOException if the file can't be read
+   */
+  public static Configuration fromTextFile(final File file) throws IOException {
+    final Configuration loaded = new AvroConfigurationSerializer().fromTextFile(file);
+    final Configuration staticConfiguration = UnsafeHDInsightRuntimeConfigurationStatic.CONF.build();
+    return Configurations.merge(loaded, staticConfiguration);
+  }
+
+  /**
+   * @return the RuntimeConfiguration that is stored in a file refered to by the environment
+   * variable HDInsightRuntimeConfiguration.HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE.
+   * @throws IOException
+   * @see HDInsightRuntimeConfiguration.HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE
+   */
+  public static Configuration fromEnvironment() throws IOException {
+
+    final String configurationPath = System.getenv(
+        HDInsightRuntimeConfiguration.HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE);
+
+    if (null == configurationPath) {
+      throw new IOException("Environment Variable " +
+          HDInsightRuntimeConfiguration.HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE +
+          " not set.");
+    }
+
+    final File configurationFile = new File(configurationPath);
+    if (!configurationFile.canRead()) {
+      throw new IOException("Environment Variable " +
+          HDInsightRuntimeConfiguration.HDINSIGHT_CONFIGURATION_FILE_ENVIRONMENT_VARIABLE +
+          " points to a file " + configurationFile.getAbsolutePath() +
+          " which can't be read."
+      );
+    }
+
+    return fromTextFile(configurationFile);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/UnsafeHDInsightRuntimeConfigurationStatic.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/UnsafeHDInsightRuntimeConfigurationStatic.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/UnsafeHDInsightRuntimeConfigurationStatic.java
new file mode 100644
index 0000000..37a46bf
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/UnsafeHDInsightRuntimeConfigurationStatic.java
@@ -0,0 +1,50 @@
+/**
+ * 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.reef.runtime.hdinsight.client;
+
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.reef.client.REEF;
+import org.apache.reef.client.RunningJob;
+import org.apache.reef.runtime.common.client.REEFImplementation;
+import org.apache.reef.runtime.common.client.RunningJobImpl;
+import org.apache.reef.runtime.common.client.api.JobSubmissionHandler;
+import org.apache.reef.runtime.common.launch.REEFMessageCodec;
+import org.apache.reef.runtime.hdinsight.client.sslhacks.UnsafeClientConstructor;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.util.logging.LoggingSetup;
+import org.apache.reef.wake.remote.RemoteConfiguration;
+
+/**
+ * The static part of the UnsafeHDInsightRuntimeConfiguration
+ */
+public final class UnsafeHDInsightRuntimeConfigurationStatic extends ConfigurationModuleBuilder {
+  static {
+    LoggingSetup.setupCommonsLogging();
+  }
+
+  public static final ConfigurationModule CONF = new UnsafeHDInsightRuntimeConfigurationStatic()
+      .bindImplementation(REEF.class, REEFImplementation.class)
+      .bindImplementation(RunningJob.class, RunningJobImpl.class)
+      .bindNamedParameter(RemoteConfiguration.MessageCodec.class, REEFMessageCodec.class)
+      .bindImplementation(JobSubmissionHandler.class, HDInsightJobSubmissionHandler.class)
+      .bindConstructor(CloseableHttpClient.class, UnsafeClientConstructor.class)
+      .build();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/package-info.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/package-info.java
new file mode 100644
index 0000000..042207e
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * The client to submit jobs to HDInsight.
+ */
+package org.apache.reef.runtime.hdinsight.client;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/sslhacks/DefaultClientConstructor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/sslhacks/DefaultClientConstructor.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/sslhacks/DefaultClientConstructor.java
new file mode 100644
index 0000000..47ce1d5
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/sslhacks/DefaultClientConstructor.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.runtime.hdinsight.client.sslhacks;
+
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.reef.tang.ExternalConstructor;
+
+import javax.inject.Inject;
+
+/**
+ * Default Client constructor with default SSL checks.
+ */
+public final class DefaultClientConstructor implements ExternalConstructor<CloseableHttpClient> {
+  @Inject
+  DefaultClientConstructor() {
+  }
+
+  @Override
+  public CloseableHttpClient newInstance() {
+    return HttpClients.createDefault();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/sslhacks/UnsafeClientConstructor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/sslhacks/UnsafeClientConstructor.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/sslhacks/UnsafeClientConstructor.java
new file mode 100644
index 0000000..a696540
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/sslhacks/UnsafeClientConstructor.java
@@ -0,0 +1,72 @@
+/**
+ * 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.reef.runtime.hdinsight.client.sslhacks;
+
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.BasicClientConnectionManager;
+import org.apache.reef.tang.ExternalConstructor;
+
+import javax.inject.Inject;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A Client constructor that produces Clients that do not check SSL.
+ */
+public final class UnsafeClientConstructor implements ExternalConstructor<CloseableHttpClient> {
+
+  @Inject
+  UnsafeClientConstructor() {
+    Logger.getLogger(UnsafeClientConstructor.class.getName())
+        .log(Level.SEVERE, "DANGER: INSTANTIATING HTTP CLIENT WITH NO SSL CHECKS.");
+  }
+
+  @Override
+  public CloseableHttpClient newInstance() {
+    try {
+      final SSLSocketFactory socketFactory = new SSLSocketFactory(this.getSSLContext());
+      socketFactory.setHostnameVerifier(new UnsafeHostNameVerifier());
+      final SchemeRegistry schemeRegistry = new SchemeRegistry();
+      schemeRegistry.register(new Scheme("https", 443, socketFactory));
+      final ClientConnectionManager clientConnectionManager = new BasicClientConnectionManager(schemeRegistry);
+      return new DefaultHttpClient(clientConnectionManager);
+    } catch (final KeyManagementException | NoSuchAlgorithmException ex) {
+      throw new RuntimeException("Unable to instantiate HTTP Client", ex);
+    }
+  }
+
+  private SSLContext getSSLContext() throws KeyManagementException, NoSuchAlgorithmException {
+    final SSLContext sc = SSLContext.getInstance("TLS");
+    sc.init(new KeyManager[0], new TrustManager[]{new UnsafeTrustManager()}, new SecureRandom());
+    return sc;
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/sslhacks/UnsafeHostNameVerifier.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/sslhacks/UnsafeHostNameVerifier.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/sslhacks/UnsafeHostNameVerifier.java
new file mode 100644
index 0000000..1ff83f3
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/sslhacks/UnsafeHostNameVerifier.java
@@ -0,0 +1,50 @@
+/**
+ * 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.reef.runtime.hdinsight.client.sslhacks;
+
+import org.apache.http.conn.ssl.X509HostnameVerifier;
+
+import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.SSLSocket;
+import java.io.IOException;
+import java.security.cert.X509Certificate;
+
+final class UnsafeHostNameVerifier implements X509HostnameVerifier {
+
+  @Override
+  public void verify(String host, SSLSocket ssl) throws IOException {
+
+  }
+
+  @Override
+  public void verify(String host, X509Certificate cert) throws SSLException {
+
+  }
+
+  @Override
+  public void verify(String host, String[] cns, String[] subjectAlts) throws SSLException {
+
+  }
+
+  @Override
+  public boolean verify(String s, SSLSession sslSession) {
+    return true;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/sslhacks/UnsafeTrustManager.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/sslhacks/UnsafeTrustManager.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/sslhacks/UnsafeTrustManager.java
new file mode 100644
index 0000000..3e6e1e6
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/sslhacks/UnsafeTrustManager.java
@@ -0,0 +1,49 @@
+/**
+ * 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.reef.runtime.hdinsight.client.sslhacks;
+
+import javax.inject.Inject;
+import javax.net.ssl.X509TrustManager;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+/**
+ * A TrustManager that trusts all certificates. Basically the "GOTO FAIL" bug implemented in Java.
+ * <p/>
+ * Hence: DO NOT USE THIS CLASS UNLESS DEBUGGING.
+ */
+final class UnsafeTrustManager implements X509TrustManager {
+  @Inject
+  UnsafeTrustManager() {
+  }
+
+  @Override
+  public void checkClientTrusted(final X509Certificate[] x509Certificates, final String s) throws CertificateException {
+  }
+
+  @Override
+  public void checkServerTrusted(final X509Certificate[] x509Certificates, final String s) throws CertificateException {
+  }
+
+  @Override
+  public X509Certificate[] getAcceptedIssuers() {
+    return new X509Certificate[0];
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ApplicationID.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ApplicationID.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ApplicationID.java
new file mode 100644
index 0000000..d3ead6b
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ApplicationID.java
@@ -0,0 +1,52 @@
+/**
+ * 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.reef.runtime.hdinsight.client.yarnrest;
+
+/**
+ * Represents the response to an application ID request.
+ */
+public final class ApplicationID {
+
+  private String id;
+  private Resource resource;
+
+  public String getId() {
+    return id;
+  }
+
+  public void setId(final String id) {
+    this.id = id;
+  }
+
+  public Resource getResource() {
+    return resource;
+  }
+
+  public void setResource(final Resource resource) {
+    this.resource = resource;
+  }
+
+  @Override
+  public String toString() {
+    return "ApplicationID{" +
+        "id='" + id + '\'' +
+        ", resource=" + resource +
+        '}';
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ApplicationResponse.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ApplicationResponse.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ApplicationResponse.java
new file mode 100644
index 0000000..8586e5e
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ApplicationResponse.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.runtime.hdinsight.client.yarnrest;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by marku_000 on 2014-06-30.
+ */
+public class ApplicationResponse {
+
+  private Map<String, List<ApplicationState>> apps;
+
+  public Map<String, List<ApplicationState>> getApps() {
+    return apps;
+  }
+
+  public void setApps(Map<String, List<ApplicationState>> apps) {
+    this.apps = apps;
+  }
+
+  public List<ApplicationState> getApplicationStates() {
+    return apps.get("app");
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ApplicationState.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ApplicationState.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ApplicationState.java
new file mode 100644
index 0000000..6825dd9
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ApplicationState.java
@@ -0,0 +1,214 @@
+/**
+ * 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.reef.runtime.hdinsight.client.yarnrest;
+
+/**
+ * Created by marku_000 on 2014-06-30.
+ */
+public class ApplicationState {
+  private String progress;
+  private String queue;
+  private String trackingUI;
+  private String state;
+  private String amContainerLogs;
+  private String applicationType;
+  private int runningContainers;
+  private int allocatedMB;
+  private long elapsedTime;
+  private String amHostHttpAddress;
+  private String id;
+  private String finalStatus;
+  private String trackingUrl;
+  private int allocatedVCores;
+  private long finishedTime;
+  private String applicationTags;
+  private String name;
+  private long clusterId;
+  private String user;
+  private String diagnostics;
+  private long startedTime;
+
+  public String getProgress() {
+    return progress;
+  }
+
+  public void setProgress(String progress) {
+    this.progress = progress;
+  }
+
+  public String getQueue() {
+    return queue;
+  }
+
+  public void setQueue(String queue) {
+    this.queue = queue;
+  }
+
+  public String getTrackingUI() {
+    return trackingUI;
+  }
+
+  public void setTrackingUI(String trackingUI) {
+    this.trackingUI = trackingUI;
+  }
+
+  public String getState() {
+    return state;
+  }
+
+  public void setState(String state) {
+    this.state = state;
+  }
+
+  public String getAmContainerLogs() {
+    return amContainerLogs;
+  }
+
+  public void setAmContainerLogs(String amContainerLogs) {
+    this.amContainerLogs = amContainerLogs;
+  }
+
+  public String getApplicationType() {
+    return applicationType;
+  }
+
+  public void setApplicationType(String applicationType) {
+    this.applicationType = applicationType;
+  }
+
+  public int getRunningContainers() {
+    return runningContainers;
+  }
+
+  public void setRunningContainers(int runningContainers) {
+    this.runningContainers = runningContainers;
+  }
+
+  public int getAllocatedMB() {
+    return allocatedMB;
+  }
+
+  public void setAllocatedMB(int allocatedMB) {
+    this.allocatedMB = allocatedMB;
+  }
+
+  public long getElapsedTime() {
+    return elapsedTime;
+  }
+
+  public void setElapsedTime(long elapsedTime) {
+    this.elapsedTime = elapsedTime;
+  }
+
+  public String getAmHostHttpAddress() {
+    return amHostHttpAddress;
+  }
+
+  public void setAmHostHttpAddress(String amHostHttpAddress) {
+    this.amHostHttpAddress = amHostHttpAddress;
+  }
+
+  public String getId() {
+    return id;
+  }
+
+  public void setId(String id) {
+    this.id = id;
+  }
+
+  public String getFinalStatus() {
+    return finalStatus;
+  }
+
+  public void setFinalStatus(String finalStatus) {
+    this.finalStatus = finalStatus;
+  }
+
+  public String getTrackingUrl() {
+    return trackingUrl;
+  }
+
+  public void setTrackingUrl(String trackingUrl) {
+    this.trackingUrl = trackingUrl;
+  }
+
+  public int getAllocatedVCores() {
+    return allocatedVCores;
+  }
+
+  public void setAllocatedVCores(int allocatedVCores) {
+    this.allocatedVCores = allocatedVCores;
+  }
+
+  public long getFinishedTime() {
+    return finishedTime;
+  }
+
+  public void setFinishedTime(long finishedTime) {
+    this.finishedTime = finishedTime;
+  }
+
+  public String getApplicationTags() {
+    return applicationTags;
+  }
+
+  public void setApplicationTags(String applicationTags) {
+    this.applicationTags = applicationTags;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public long getClusterId() {
+    return clusterId;
+  }
+
+  public void setClusterId(long clusterId) {
+    this.clusterId = clusterId;
+  }
+
+  public String getUser() {
+    return user;
+  }
+
+  public void setUser(String user) {
+    this.user = user;
+  }
+
+  public String getDiagnostics() {
+    return diagnostics;
+  }
+
+  public void setDiagnostics(String diagnostics) {
+    this.diagnostics = diagnostics;
+  }
+
+  public long getStartedTime() {
+    return startedTime;
+  }
+
+  public void setStartedTime(long startedTime) {
+    this.startedTime = startedTime;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ApplicationSubmission.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ApplicationSubmission.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ApplicationSubmission.java
new file mode 100644
index 0000000..77455e4
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ApplicationSubmission.java
@@ -0,0 +1,167 @@
+/**
+ * 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.reef.runtime.hdinsight.client.yarnrest;
+
+/**
+ * Represents an ApplicationSubmission to the YARN REST API.
+ */
+public final class ApplicationSubmission {
+
+  public static final String DEFAULT_QUEUE = "default";
+  private String queue = DEFAULT_QUEUE;
+
+  public static final String DEFAULT_PRIORITY = "3";
+  private String priority = DEFAULT_PRIORITY;
+
+  public static final String DEFAULT_MAX_ATTEMPTS = "1";
+  private String maxAppAttempts = DEFAULT_MAX_ATTEMPTS;
+
+  public static final String DEFAULT_APPLICATION_TYPE = "YARN";
+  private String applicationType = DEFAULT_APPLICATION_TYPE;
+
+  public static final String DEFAULT_KEEP_CONTAINERS = "false";
+  private String keepContainers = DEFAULT_KEEP_CONTAINERS;
+
+  public static final String DEFAULT_IS_UNMANAGED_AM = "false";
+  private String isUnmanagedAM = DEFAULT_IS_UNMANAGED_AM;
+
+  public static final String DEFAULT_CANCEL_TOKENS_WHEN_COMPLETE = "true";
+  private String cancelTokensWhenComplete = DEFAULT_CANCEL_TOKENS_WHEN_COMPLETE;
+
+  private String applicationId;
+  private String applicationName;
+  private ContainerInfo containerInfo;
+  private Resource resource;
+
+  public String getApplicationId() {
+    return applicationId;
+  }
+
+  public ApplicationSubmission setApplicationId(String applicationId) {
+    this.applicationId = applicationId;
+    return this;
+  }
+
+  public String getApplicationName() {
+    return applicationName;
+  }
+
+  public ApplicationSubmission setApplicationName(String applicationName) {
+    this.applicationName = applicationName;
+    return this;
+  }
+
+  public String getApplicationType() {
+    return applicationType;
+  }
+
+  public ApplicationSubmission setApplicationType(String applicationType) {
+    this.applicationType = applicationType;
+    return this;
+  }
+
+  public String isCancelTokensWhenComplete() {
+    return cancelTokensWhenComplete;
+  }
+
+  public ApplicationSubmission setCancelTokensWhenComplete(String cancelTokensWhenComplete) {
+    this.cancelTokensWhenComplete = cancelTokensWhenComplete;
+    return this;
+  }
+
+  public ContainerInfo getContainerInfo() {
+    return containerInfo;
+  }
+
+  public ApplicationSubmission setContainerInfo(ContainerInfo containerInfo) {
+    this.containerInfo = containerInfo;
+    return this;
+  }
+
+  public String isUnmanagedAM() {
+    return isUnmanagedAM;
+  }
+
+  public ApplicationSubmission setUnmanagedAM(String isUnmanagedAM) {
+    this.isUnmanagedAM = isUnmanagedAM;
+    return this;
+  }
+
+  public String isKeepContainers() {
+    return keepContainers;
+  }
+
+  public ApplicationSubmission setKeepContainers(String keepContainers) {
+    this.keepContainers = keepContainers;
+    return this;
+  }
+
+  public String getMaxAppAttempts() {
+    return maxAppAttempts;
+  }
+
+  public ApplicationSubmission setMaxAppAttempts(String maxAppAttempts) {
+    this.maxAppAttempts = maxAppAttempts;
+    return this;
+  }
+
+  public String getPriority() {
+    return priority;
+  }
+
+  public ApplicationSubmission setPriority(String priority) {
+    this.priority = priority;
+    return this;
+  }
+
+  public String getQueue() {
+    return queue;
+  }
+
+  public ApplicationSubmission setQueue(String queue) {
+    this.queue = queue;
+    return this;
+  }
+
+  public Resource getResource() {
+    return resource;
+  }
+
+  public ApplicationSubmission setResource(Resource resource) {
+    this.resource = resource;
+    return this;
+  }
+
+  @Override
+  public String toString() {
+    return "ApplicationSubmission{" +
+        "queue='" + queue + '\'' +
+        ", priority=" + priority +
+        ", maxAppAttempts=" + maxAppAttempts +
+        ", applicationType='" + applicationType + '\'' +
+        ", keepContainers=" + keepContainers +
+        ", applicationId='" + applicationId + '\'' +
+        ", applicationName='" + applicationName + '\'' +
+        ", containerInfo=" + containerInfo +
+        ", isUnmanagedAM=" + isUnmanagedAM +
+        ", cancelTokensWhenComplete=" + cancelTokensWhenComplete +
+        ", resource=" + resource +
+        '}';
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ContainerInfo.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ContainerInfo.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ContainerInfo.java
new file mode 100644
index 0000000..3c779d5
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/ContainerInfo.java
@@ -0,0 +1,125 @@
+/**
+ * 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.reef.runtime.hdinsight.client.yarnrest;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Represents a ContainerInfo in the YARN REST APIs.
+ */
+public final class ContainerInfo {
+
+  public static final String DEFAULT_SERVICE_DATA = null;
+  private String serviceData = DEFAULT_SERVICE_DATA;
+
+  public static final String DEFAULT_TOKENS = "";
+  private String tokens = DEFAULT_TOKENS;
+
+  public static final String DEFAULT_ACLS = null;
+  private String acls = DEFAULT_ACLS;
+
+  private List<String> commands = new ArrayList<>();
+  private Map<String, EnvironmentEntry> environment = new HashMap<>();
+  private Map<String, LocalResourcesEntry> localResources = new HashMap<>();
+
+  /**
+   * Adds an environment variable.
+   *
+   * @param key   the name of the variable
+   * @param value the value it shall take
+   * @return this
+   */
+  public ContainerInfo addEnvironment(final String key, final String value) {
+    this.environment.put("entry", new EnvironmentEntry(key, value));
+    return this;
+  }
+
+  /**
+   * Adds a command to the command list to be executed
+   *
+   * @param command
+   * @return this
+   */
+  public ContainerInfo addCommand(final String command) {
+    this.commands.add(command);
+    return this;
+  }
+
+  public ContainerInfo addFileResource(final String key, final FileResource fileResource) {
+    this.localResources.put("entry", new LocalResourcesEntry(key, fileResource));
+    return this;
+  }
+
+  public String getServiceData() {
+    return this.serviceData;
+  }
+
+  public ContainerInfo setServiceData(final String serviceData) {
+    this.serviceData = serviceData;
+    return this;
+  }
+
+  public String getTokens() {
+    return this.tokens;
+  }
+
+  public ContainerInfo setTokens(final String tokens) {
+    this.tokens = tokens;
+    return this;
+  }
+
+  public String getAcls() {
+    return this.acls;
+  }
+
+  public ContainerInfo setAcls(final String acls) {
+    this.acls = acls;
+    return this;
+  }
+
+  public Map<String, EnvironmentEntry> getEnvironment() {
+    return this.environment;
+  }
+
+  public void setEnvironment(final Map<String, EnvironmentEntry> environment) {
+    this.environment = environment;
+  }
+
+  public List<String> getCommands() {
+    return this.commands;
+  }
+
+  public ContainerInfo setCommands(final List<String> commands) {
+    this.commands = commands;
+    return this;
+  }
+
+  public Map<String, LocalResourcesEntry> getLocalResources() {
+    return this.localResources;
+  }
+
+  public ContainerInfo setLocalResources(final Map<String, LocalResourcesEntry> localResources) {
+    this.localResources = localResources;
+    return this;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/EnvironmentEntry.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/EnvironmentEntry.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/EnvironmentEntry.java
new file mode 100644
index 0000000..8444d47
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/EnvironmentEntry.java
@@ -0,0 +1,76 @@
+/**
+ * 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.reef.runtime.hdinsight.client.yarnrest;
+
+/**
+ * An Entry in the Environment field of an ApplicationSubmission
+ */
+public final class EnvironmentEntry {
+
+  private String key;
+  private String value;
+
+  public EnvironmentEntry(final String key, final String value) {
+    this.key = key;
+    this.value = value;
+  }
+
+  public String getKey() {
+    return this.key;
+  }
+
+  public void setKey(final String key) {
+    this.key = key;
+  }
+
+  public String getValue() {
+    return this.value;
+  }
+
+  public void setValue(final String value) {
+    this.value = value;
+  }
+
+  @Override
+  public String toString() {
+    return "EnvironmentEntry{" +
+        "key='" + this.key + '\'' +
+        ", value='" + this.value + '\'' +
+        '}';
+  }
+
+  @Override
+  public boolean equals(final Object o) {
+
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    final EnvironmentEntry that = (EnvironmentEntry) o;
+
+    return (this.key == that.key || (this.key != null && this.key.equals(that.key)))
+        && (this.value == that.value || (this.value != null && this.value.equals(that.value)));
+  }
+
+  @Override
+  public int hashCode() {
+    int result = this.key != null ? this.key.hashCode() : 0;
+    result = 31 * result + (this.value != null ? this.value.hashCode() : 0);
+    return result;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/FileResource.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/FileResource.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/FileResource.java
new file mode 100644
index 0000000..519228c
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/FileResource.java
@@ -0,0 +1,89 @@
+/**
+ * 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.reef.runtime.hdinsight.client.yarnrest;
+
+public final class FileResource {
+
+  public static final String TYPE_FILE = "FILE";
+  public static final String TYPE_ARCHIVE = "ARCHIVE";
+
+  public static final String VISIBILITY_APPLICATION = "APPLICATION";
+
+  private String url;
+  private String type;
+  private String visibility;
+  private String size;
+  private String timestamp;
+
+  public String getUrl() {
+    return this.url;
+  }
+
+  public FileResource setUrl(final String url) {
+    this.url = url;
+    return this;
+  }
+
+  public String getType() {
+    return this.type;
+  }
+
+  public FileResource setType(final String type) {
+    this.type = type;
+    return this;
+  }
+
+  public String getVisibility() {
+    return this.visibility;
+  }
+
+  public FileResource setVisibility(final String visibility) {
+    this.visibility = visibility;
+    return this;
+  }
+
+  public String getSize() {
+    return this.size;
+  }
+
+  public FileResource setSize(final String size) {
+    this.size = size;
+    return this;
+  }
+
+  public String getTimestamp() {
+    return this.timestamp;
+  }
+
+  public FileResource setTimestamp(final String timestamp) {
+    this.timestamp = timestamp;
+    return this;
+  }
+
+  @Override
+  public String toString() {
+    return "FileResource{" +
+        "url='" + url + '\'' +
+        ", type='" + type + '\'' +
+        ", visibility='" + visibility + '\'' +
+        ", size=" + size +
+        ", timestamp=" + timestamp +
+        '}';
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/HDInsightInstance.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/HDInsightInstance.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/HDInsightInstance.java
new file mode 100644
index 0000000..2bbad8a
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/HDInsightInstance.java
@@ -0,0 +1,211 @@
+/**
+ * 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.reef.runtime.hdinsight.client.yarnrest;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.NotImplementedException;
+import org.apache.http.Header;
+import org.apache.http.HttpHost;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.AuthCache;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.auth.BasicScheme;
+import org.apache.http.impl.client.BasicAuthCache;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.message.BasicHeader;
+import org.apache.reef.runtime.hdinsight.parameters.HDInsightInstanceURL;
+import org.apache.reef.runtime.hdinsight.parameters.HDInsightPassword;
+import org.apache.reef.runtime.hdinsight.parameters.HDInsightUsername;
+import org.apache.reef.tang.annotations.Parameter;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Represents an HDInsight instance.
+ */
+public final class HDInsightInstance {
+
+  private static final Logger LOG = Logger.getLogger(HDInsightInstance.class.getName());
+  private static final String APPLICATION_KILL_MESSAGE = "{\"app:{\"state\":\"KILLED\"}}";
+
+  private final ObjectMapper objectMapper = new ObjectMapper();
+  private final Header[] headers;
+  private final HttpClientContext httpClientContext;
+
+  private final String instanceUrl;
+  private final String username;
+  private final CloseableHttpClient httpClient;
+
+  @Inject
+  HDInsightInstance(final @Parameter(HDInsightUsername.class) String username,
+                    final @Parameter(HDInsightPassword.class) String password,
+                    final @Parameter(HDInsightInstanceURL.class) String instanceUrl,
+                    final CloseableHttpClient client) throws URISyntaxException, IOException {
+    this.httpClient = client;
+    this.instanceUrl = instanceUrl.endsWith("/") ? instanceUrl : instanceUrl + "/";
+    this.username = username;
+    final String host = this.getHost();
+    this.headers = new Header[]{
+        new BasicHeader("Host", host)
+    };
+    this.httpClientContext = getClientContext(host, username, password);
+  }
+
+  /**
+   * Request an ApplicationId from the cluster.
+   *
+   * @return
+   * @throws IOException
+   */
+  public ApplicationID getApplicationID() throws IOException {
+    final String url = "ws/v1/cluster/appids?user.name=" + this.username;
+    final HttpPost post = preparePost(url);
+    try (final CloseableHttpResponse response = this.httpClient.execute(post, this.httpClientContext)) {
+      final String message = IOUtils.toString(response.getEntity().getContent());
+      final ApplicationID result = this.objectMapper.readValue(message, ApplicationID.class);
+      return result;
+    }
+  }
+
+  /**
+   * Submits an application for execution.
+   *
+   * @param applicationSubmission
+   * @throws IOException
+   */
+  public void submitApplication(final ApplicationSubmission applicationSubmission) throws IOException {
+
+    final String applicationId = applicationSubmission.getApplicationId();
+    final String url = "ws/v1/cluster/apps/" + applicationId + "?user.name=" + this.username;
+    final HttpPost post = preparePost(url);
+
+    final StringWriter writer = new StringWriter();
+    try {
+      this.objectMapper.writeValue(writer, applicationSubmission);
+    } catch (final IOException e) {
+      throw new RuntimeException(e);
+    }
+    final String message = writer.toString();
+    LOG.log(Level.FINE, "Sending:\n{0}", message.replace("\n", "\n\t"));
+    post.setEntity(new StringEntity(message, ContentType.APPLICATION_JSON));
+
+    try (final CloseableHttpResponse response = this.httpClient.execute(post, this.httpClientContext)) {
+      final String responseMessage = IOUtils.toString(response.getEntity().getContent());
+      LOG.log(Level.FINE, "Response: {0}", responseMessage.replace("\n", "\n\t"));
+    }
+  }
+
+  /**
+   * Issues a YARN kill command to the application.
+   *
+   * @param applicationId
+   */
+  public void killApplication(final String applicationId) {
+    throw new NotImplementedException();
+  }
+
+  public List<ApplicationState> listApplications() throws IOException {
+    final String url = "ws/v1/cluster/apps";
+    final HttpGet get = prepareGet(url);
+    try (final CloseableHttpResponse response = this.httpClient.execute(get, this.httpClientContext)) {
+      final String message = IOUtils.toString(response.getEntity().getContent());
+      final ApplicationResponse result = this.objectMapper.readValue(message, ApplicationResponse.class);
+      return result.getApplicationStates();
+    }
+  }
+
+  /**
+   * @param applicationId
+   * @return the URL that can be used to issue application level messages.
+   */
+  public String getApplicationURL(final String applicationId) {
+    return "ws/v1/cluster/apps/" + applicationId;
+  }
+
+  private final String getHost() throws URISyntaxException {
+    final URI uri = new URI(this.instanceUrl);
+    return uri.getHost();
+  }
+
+  /**
+   * Creates a HttpGet request with all the common headers.
+   *
+   * @param url
+   * @return
+   */
+  private HttpGet prepareGet(final String url) {
+    final HttpGet httpGet = new HttpGet(this.instanceUrl + url);
+    for (final Header header : this.headers) {
+      httpGet.addHeader(header);
+    }
+    return httpGet;
+  }
+
+  /**
+   * Creates a HttpPost request with all the common headers.
+   *
+   * @param url
+   * @return
+   */
+  private HttpPost preparePost(final String url) {
+    final HttpPost httpPost = new HttpPost(this.instanceUrl + url);
+    for (final Header header : this.headers) {
+      httpPost.addHeader(header);
+    }
+    return httpPost;
+  }
+
+
+  private HttpClientContext getClientContext(final String hostname, final String username, final String password) throws IOException {
+    final HttpHost targetHost = new HttpHost(hostname, 443, "https");
+    final HttpClientContext result = HttpClientContext.create();
+    // Setup credentials provider
+    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
+    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
+    result.setCredentialsProvider(credentialsProvider);
+
+    // Setup preemptive authentication
+    final AuthCache authCache = new BasicAuthCache();
+    final BasicScheme basicAuth = new BasicScheme();
+    authCache.put(targetHost, basicAuth);
+    result.setAuthCache(authCache);
+    final HttpGet httpget = new HttpGet("/");
+
+    // Prime the cache
+    try (final CloseableHttpResponse response = this.httpClient.execute(targetHost, httpget, result)) {
+    }
+    return result;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/LocalResourcesEntry.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/LocalResourcesEntry.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/LocalResourcesEntry.java
new file mode 100644
index 0000000..f73c31e
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/LocalResourcesEntry.java
@@ -0,0 +1,48 @@
+/**
+ * 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.reef.runtime.hdinsight.client.yarnrest;
+
+public final class LocalResourcesEntry {
+
+  private String key;
+  private FileResource value;
+
+  public LocalResourcesEntry(final String key, final FileResource value) {
+    this.key = key;
+    this.value = value;
+  }
+
+  public String getKey() {
+    return this.key;
+  }
+
+  public LocalResourcesEntry setKey(final String key) {
+    this.key = key;
+    return this;
+  }
+
+  public FileResource getValue() {
+    return this.value;
+  }
+
+  public LocalResourcesEntry setValue(final FileResource value) {
+    this.value = value;
+    return this;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/Resource.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/Resource.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/Resource.java
new file mode 100644
index 0000000..7e1b647
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/Resource.java
@@ -0,0 +1,54 @@
+/**
+ * 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.reef.runtime.hdinsight.client.yarnrest;
+
+/**
+ * Represents the resoure field in the YARN REST API
+ */
+public final class Resource {
+
+  private String memory;
+  private String vCores;
+
+  public String getMemory() {
+    return this.memory;
+  }
+
+  public Resource setMemory(final String memory) {
+    this.memory = memory;
+    return this;
+  }
+
+  public String getvCores() {
+    return this.vCores;
+  }
+
+  public Resource setvCores(final String vCores) {
+    this.vCores = vCores;
+    return this;
+  }
+
+  @Override
+  public String toString() {
+    return "Resource{" +
+        "memory=" + this.memory +
+        ", vCores=" + this.vCores +
+        '}';
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/package-info.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/package-info.java
new file mode 100644
index 0000000..0fa4a76
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/yarnrest/package-info.java
@@ -0,0 +1,24 @@
+/**
+ * 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.
+ */
+/**
+ * Some minimal abstraction over the YARN REST API.
+ *
+ * Note: This will likely get an overhaul as that API gets closer to finalization.
+ */
+package org.apache.reef.runtime.hdinsight.client.yarnrest;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/package-info.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/package-info.java
new file mode 100644
index 0000000..94acb4c
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * HDInsight support for REEF.
+ */
+package org.apache.reef.runtime.hdinsight;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/AzureStorageAccountContainerName.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/AzureStorageAccountContainerName.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/AzureStorageAccountContainerName.java
new file mode 100644
index 0000000..8f51421
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/parameters/AzureStorageAccountContainerName.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.runtime.hdinsight.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The Storage account container name to be used by Azure.
+ */
+@NamedParameter(doc = "The Storage account container name to be used by Azure")
+public final class AzureStorageAccountContainerName implements Name<String> {
+}


[14/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/package-info.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/package-info.java
new file mode 100644
index 0000000..0513a03
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/package-info.java
@@ -0,0 +1,29 @@
+/**
+ * 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.
+ */
+/**
+ * Tang format classes encode and decode information that Tang gathers at
+ * runtime.  Such information comes in three forms: ClassHierarchy data
+ * that is derived directly from compiled application code, Configuration
+ * data that has been typechecked, and is derived from various user inputs,
+ * such as configuration files and command line arguments, and finally,
+ * InjectionPlans which encode the constructor invocations that Tang would
+ * make when instantiating a particular class.
+ */
+package org.apache.reef.tang.formats;
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/ConfigurationBuilderImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/ConfigurationBuilderImpl.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/ConfigurationBuilderImpl.java
new file mode 100644
index 0000000..a9ead69
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/ConfigurationBuilderImpl.java
@@ -0,0 +1,378 @@
+/**
+ * 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.reef.tang.implementation;
+
+import org.apache.reef.tang.*;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.NameResolutionException;
+import org.apache.reef.tang.exceptions.ParseException;
+import org.apache.reef.tang.implementation.java.ClassHierarchyImpl;
+import org.apache.reef.tang.types.*;
+import org.apache.reef.tang.util.MonotonicMultiMap;
+import org.apache.reef.tang.util.TracingMonotonicMap;
+import org.apache.reef.tang.util.TracingMonotonicTreeMap;
+
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+public class ConfigurationBuilderImpl implements ConfigurationBuilder {
+  public final static String IMPORT = "import";
+  public final static String INIT = "<init>";
+  final TracingMonotonicMap<ClassNode<?>, ClassNode<?>> boundImpls = new TracingMonotonicTreeMap<>();
+  final TracingMonotonicMap<ClassNode<?>, ClassNode<? extends ExternalConstructor<?>>> boundConstructors = new TracingMonotonicTreeMap<>();
+  final Map<NamedParameterNode<?>, String> namedParameters = new TracingMonotonicTreeMap<>();
+  final Map<ClassNode<?>, ConstructorDef<?>> legacyConstructors = new TracingMonotonicTreeMap<>();
+  final MonotonicMultiMap<NamedParameterNode<Set<?>>, Object> boundSetEntries = new MonotonicMultiMap<>();
+  final TracingMonotonicMap<NamedParameterNode<List<?>>, List<Object>> boundLists = new TracingMonotonicTreeMap<>();
+  // TODO: None of these should be public! - Move to configurationBuilder. Have
+  // that wrap itself
+  // in a sane Configuration interface...
+  // TODO: Should be final again!
+  public ClassHierarchy namespace;
+
+  protected ConfigurationBuilderImpl() {
+    this.namespace = Tang.Factory.getTang().getDefaultClassHierarchy();
+  }
+
+  protected ConfigurationBuilderImpl(ClassHierarchy namespace) {
+    this.namespace = namespace;
+  }
+
+  protected ConfigurationBuilderImpl(URL[] jars, Configuration[] confs, Class<? extends ExternalConstructor<?>>[] parsers)
+      throws BindException {
+    this.namespace = Tang.Factory.getTang().getDefaultClassHierarchy(jars, parsers);
+    for (Configuration tc : confs) {
+      addConfiguration(((ConfigurationImpl) tc));
+    }
+  }
+
+  protected ConfigurationBuilderImpl(ConfigurationBuilderImpl t) {
+    this.namespace = t.getClassHierarchy();
+    try {
+      addConfiguration(t.getClassHierarchy(), t);
+    } catch (BindException e) {
+      throw new IllegalStateException("Could not copy builder", e);
+    }
+  }
+
+  @SuppressWarnings("unchecked")
+  protected ConfigurationBuilderImpl(URL... jars) throws BindException {
+    this(jars, new Configuration[0], new Class[0]);
+  }
+
+  @SuppressWarnings("unchecked")
+  protected ConfigurationBuilderImpl(Configuration... confs) throws BindException {
+    this(new URL[0], confs, new Class[0]);
+  }
+
+  @Override
+  public void addConfiguration(Configuration conf) throws BindException {
+    // XXX remove cast!
+    addConfiguration(conf.getClassHierarchy(), ((ConfigurationImpl) conf).builder);
+  }
+
+  @SuppressWarnings("unchecked")
+  private <T> void addConfiguration(ClassHierarchy ns, ConfigurationBuilderImpl builder)
+      throws BindException {
+    namespace = namespace.merge(ns);
+    if ((namespace instanceof ClassHierarchyImpl || builder.namespace instanceof ClassHierarchyImpl)) {
+      if ((namespace instanceof ClassHierarchyImpl && builder.namespace instanceof ClassHierarchyImpl)) {
+        ((ClassHierarchyImpl) namespace).parameterParser
+            .mergeIn(((ClassHierarchyImpl) builder.namespace).parameterParser);
+      } else {
+        throw new IllegalArgumentException("Attempt to merge Java and non-Java class hierarchy!  Not supported.");
+      }
+    }
+
+    for (ClassNode<?> cn : builder.boundImpls.keySet()) {
+      bind(cn.getFullName(), builder.boundImpls.get(cn).getFullName());
+    }
+    for (ClassNode<?> cn : builder.boundConstructors.keySet()) {
+      bind(cn.getFullName(), builder.boundConstructors.get(cn).getFullName());
+    }
+    // The namedParameters set contains the strings that can be used to
+    // instantiate new
+    // named parameter instances. Create new ones where we can.
+    for (NamedParameterNode<?> np : builder.namedParameters.keySet()) {
+      bind(np.getFullName(), builder.namedParameters.get(np));
+    }
+    for (ClassNode<?> cn : builder.legacyConstructors.keySet()) {
+      registerLegacyConstructor(cn, builder.legacyConstructors.get(cn)
+          .getArgs());
+    }
+    for (Entry<NamedParameterNode<Set<?>>, Object> e : builder.boundSetEntries) {
+      String name = ((NamedParameterNode<Set<T>>) (NamedParameterNode<?>) e.getKey()).getFullName();
+      if (e.getValue() instanceof Node) {
+        bindSetEntry(name, (Node) e.getValue());
+      } else if (e.getValue() instanceof String) {
+        bindSetEntry(name, (String) e.getValue());
+      } else {
+        throw new IllegalStateException();
+      }
+    }
+    // The boundLists set contains bound lists with their target NamedParameters
+    for (NamedParameterNode<List<?>> np : builder.boundLists.keySet()) {
+      bindList(np.getFullName(), builder.boundLists.get(np));
+    }
+  }
+
+  @Override
+  public ClassHierarchy getClassHierarchy() {
+    return namespace;
+  }
+
+  @Override
+  public void registerLegacyConstructor(ClassNode<?> c,
+                                        final ConstructorArg... args) throws BindException {
+    String cn[] = new String[args.length];
+    for (int i = 0; i < args.length; i++) {
+      cn[i] = args[i].getType();
+    }
+    registerLegacyConstructor(c.getFullName(), cn);
+  }
+
+  @Override
+  public void registerLegacyConstructor(String s, final String... args)
+      throws BindException {
+    ClassNode<?> cn = (ClassNode<?>) namespace.getNode(s);
+    ClassNode<?>[] cnArgs = new ClassNode[args.length];
+    for (int i = 0; i < args.length; i++) {
+      cnArgs[i] = (ClassNode<?>) namespace.getNode(args[i]);
+    }
+    registerLegacyConstructor(cn, cnArgs);
+  }
+
+  @Override
+  public void registerLegacyConstructor(ClassNode<?> cn,
+                                        final ClassNode<?>... args) throws BindException {
+    legacyConstructors.put(cn, cn.getConstructorDef(args));
+  }
+
+  @Override
+  public <T> void bind(String key, String value) throws BindException {
+    Node n = namespace.getNode(key);
+    if (n instanceof NamedParameterNode) {
+      bindParameter((NamedParameterNode<?>) n, value);
+    } else if (n instanceof ClassNode) {
+      Node m = namespace.getNode(value);
+      bind((ClassNode<?>) n, (ClassNode<?>) m);
+    } else {
+      throw new IllegalStateException("getNode() returned " + n + " which is neither a ClassNode nor a NamedParameterNode");
+    }
+  }
+
+  @SuppressWarnings({"unchecked", "rawtypes"})
+  public void bind(Node key, Node value) throws BindException {
+    if (key instanceof NamedParameterNode) {
+      bindParameter((NamedParameterNode<?>) key, value.getFullName());
+    } else if (key instanceof ClassNode) {
+      ClassNode<?> k = (ClassNode<?>) key;
+      if (value instanceof ClassNode) {
+        ClassNode<?> val = (ClassNode<?>) value;
+        if (val.isExternalConstructor() && !k.isExternalConstructor()) {
+          bindConstructor(k, (ClassNode) val);
+        } else {
+          bindImplementation(k, (ClassNode) val);
+        }
+      }
+    }
+  }
+
+  public <T> void bindImplementation(ClassNode<T> n, ClassNode<? extends T> m)
+      throws BindException {
+    if (namespace.isImplementation(n, m)) {
+      boundImpls.put(n, m);
+    } else {
+      throw new IllegalArgumentException("Class" + m + " does not extend " + n);
+    }
+  }
+
+  @SuppressWarnings({"unchecked", "rawtypes"})
+  public <T> void bindParameter(NamedParameterNode<T> name, String value)
+      throws BindException {
+    /* Parse and discard value; this is just for type checking */
+    if (namespace instanceof JavaClassHierarchy) {
+      ((JavaClassHierarchy) namespace).parse(name, value);
+    }
+    if (name.isSet()) {
+      bindSetEntry((NamedParameterNode) name, value);
+    } else {
+      namedParameters.put(name, value);
+    }
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public void bindSetEntry(String iface, String impl)
+      throws BindException {
+    boundSetEntries.put((NamedParameterNode<Set<?>>) namespace.getNode(iface), impl);
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public void bindSetEntry(String iface, Node impl)
+      throws BindException {
+    boundSetEntries.put((NamedParameterNode<Set<?>>) namespace.getNode(iface), impl);
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public <T> void bindSetEntry(NamedParameterNode<Set<T>> iface, String impl)
+      throws BindException {
+    if (namespace instanceof ClassHierarchyImpl) {
+      JavaClassHierarchy javanamespace = (ClassHierarchyImpl) namespace;
+      try {
+        javanamespace.parse(iface, impl);
+      } catch (ParseException e) {
+        throw new IllegalStateException("Could not parse " + impl + " which was passed to " + iface);
+      }
+    }
+    boundSetEntries.put((NamedParameterNode<Set<?>>) (NamedParameterNode<?>) iface, impl);
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public <T> void bindSetEntry(NamedParameterNode<Set<T>> iface, Node impl)
+      throws BindException {
+    boundSetEntries.put((NamedParameterNode<Set<?>>) (NamedParameterNode<?>) iface, impl);
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public <T> void bindList(NamedParameterNode<List<T>> iface, List implList) {
+    // Check parsability of list items
+    for (Object item : implList) {
+      if (item instanceof String) {
+        JavaClassHierarchy javanamespace = (ClassHierarchyImpl) namespace;
+        try {
+          // Just for parsability checking.
+          javanamespace.parse(iface, (String) item);
+        } catch (ParseException e) {
+          throw new IllegalStateException("Could not parse " + item + " which was passed to " + iface);
+        }
+      }
+    }
+    boundLists.put((NamedParameterNode<List<?>>) (NamedParameterNode<?>) iface, implList);
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public void bindList(String iface, List implList) {
+    NamedParameterNode<List<?>> ifaceNode = (NamedParameterNode<List<?>>) namespace.getNode(iface);
+    // Check parsability of list items
+    for (Object item : implList) {
+      if (item instanceof String) {
+        JavaClassHierarchy javanamespace = (ClassHierarchyImpl) namespace;
+        try {
+          // Just for parsability checking.
+          javanamespace.parse(ifaceNode, (String) item);
+        } catch (ParseException e) {
+          throw new IllegalStateException("Could not parse " + item + " which was passed to " + iface);
+        }
+      }
+    }
+    boundLists.put(ifaceNode, implList);
+  }
+
+  @Override
+  public <T> void bindConstructor(ClassNode<T> k,
+                                  ClassNode<? extends ExternalConstructor<? extends T>> v) {
+    boundConstructors.put(k, v);
+  }
+
+  @Override
+  public ConfigurationImpl build() {
+    return new ConfigurationImpl(new ConfigurationBuilderImpl(this));
+  }
+
+  @Override
+  public String classPrettyDefaultString(String longName) throws NameResolutionException {
+    final NamedParameterNode<?> param = (NamedParameterNode<?>) namespace
+        .getNode(longName);
+    return param.getSimpleArgName() + "=" + join(",", param.getDefaultInstanceAsStrings());
+  }
+
+  private String join(String sep, String[] s) {
+    if (s.length == 0) {
+      return null;
+    } else {
+      StringBuilder sb = new StringBuilder(s[0]);
+      for (int i = 1; i < s.length; i++) {
+        sb.append(sep);
+        sb.append(s[i]);
+      }
+      return sb.toString();
+    }
+  }
+
+  @Override
+  public String classPrettyDescriptionString(String fullName)
+      throws NameResolutionException {
+    final NamedParameterNode<?> param = (NamedParameterNode<?>) namespace
+        .getNode(fullName);
+    return param.getDocumentation() + "\n" + param.getFullName();
+  }
+
+  @Override
+  public boolean equals(final Object o) {
+    if (this == o) {
+      return true;
+    }
+    if (o == null || getClass() != o.getClass()) {
+      return false;
+    }
+
+    ConfigurationBuilderImpl that = (ConfigurationBuilderImpl) o;
+
+    if (boundConstructors != null ? !boundConstructors.equals(that.boundConstructors) : that.boundConstructors != null) {
+      return false;
+    }
+    if (boundImpls != null ? !boundImpls.equals(that.boundImpls) : that.boundImpls != null) {
+      return false;
+    }
+    if (boundSetEntries != null ? !boundSetEntries.equals(that.boundSetEntries) : that.boundSetEntries != null) {
+      return false;
+    }
+    if (boundLists != null ? !boundLists.equals(that.boundLists) : that.boundLists != null) {
+      return false;
+    }
+    if (legacyConstructors != null ? !legacyConstructors.equals(that.legacyConstructors) : that.legacyConstructors != null) {
+      return false;
+    }
+    if (namedParameters != null ? !namedParameters.equals(that.namedParameters) : that.namedParameters != null) {
+      return false;
+    }
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = boundImpls != null ? boundImpls.hashCode() : 0;
+    result = 31 * result + (boundConstructors != null ? boundConstructors.hashCode() : 0);
+    result = 31 * result + (namedParameters != null ? namedParameters.hashCode() : 0);
+    result = 31 * result + (legacyConstructors != null ? legacyConstructors.hashCode() : 0);
+    result = 31 * result + (boundSetEntries != null ? boundSetEntries.hashCode() : 0);
+    result = 31 * result + (boundLists != null ? boundLists.hashCode() : 0);
+    return result;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/ConfigurationImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/ConfigurationImpl.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/ConfigurationImpl.java
new file mode 100644
index 0000000..076435f
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/ConfigurationImpl.java
@@ -0,0 +1,143 @@
+/**
+ * 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.reef.tang.implementation;
+
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.ConfigurationBuilder;
+import org.apache.reef.tang.ExternalConstructor;
+import org.apache.reef.tang.types.ClassNode;
+import org.apache.reef.tang.types.ConstructorDef;
+import org.apache.reef.tang.types.NamedParameterNode;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Set;
+
+public class ConfigurationImpl implements Configuration {
+  final ConfigurationBuilderImpl builder;
+
+  protected ConfigurationImpl(final ConfigurationBuilderImpl builder) {
+    this.builder = builder;
+  }
+
+  @Override
+  public String getNamedParameter(final NamedParameterNode<?> np) {
+    return builder.namedParameters.get(np);
+  }
+
+  @Override
+  @SuppressWarnings("unchecked")
+  public <T> ClassNode<ExternalConstructor<T>> getBoundConstructor(
+      final ClassNode<T> cn) {
+    return (ClassNode<ExternalConstructor<T>>) builder.boundConstructors.get(cn);
+  }
+
+  @Override
+  public Set<ClassNode<?>> getBoundImplementations() {
+    return builder.boundImpls.keySet();
+  }
+
+  @Override
+  public Set<ClassNode<?>> getBoundConstructors() {
+    return builder.boundConstructors.keySet();
+  }
+
+  @Override
+  public Set<NamedParameterNode<?>> getNamedParameters() {
+    return builder.namedParameters.keySet();
+  }
+
+  @Override
+  public Set<ClassNode<?>> getLegacyConstructors() {
+    return builder.legacyConstructors.keySet();
+  }
+
+  @Override
+  @SuppressWarnings("unchecked")
+  public <T> ClassNode<T> getBoundImplementation(final ClassNode<T> cn) {
+    return (ClassNode<T>) builder.boundImpls.get(cn);
+  }
+
+  @Override
+  @SuppressWarnings("unchecked")
+  public <T> ConstructorDef<T> getLegacyConstructor(final ClassNode<T> cn) {
+    return (ConstructorDef<T>) builder.legacyConstructors.get(cn);
+  }
+
+  @Override
+  public ConfigurationBuilder newBuilder() {
+    return builder.build().builder;
+  }
+
+  @Override
+  public ClassHierarchy getClassHierarchy() {
+    return builder.namespace;
+  }
+
+  @Override
+  public Set<Object> getBoundSet(NamedParameterNode<Set<?>> np) {
+    return this.builder.boundSetEntries.getValuesForKey(np);
+  }
+
+  @Override
+  public List<Object> getBoundList(NamedParameterNode<List<?>> np) {
+    return this.builder.boundLists.get(np);
+  }
+
+  @Override
+  public Iterable<Entry<NamedParameterNode<Set<?>>, Object>> getBoundSets() {
+    return new Iterable<Entry<NamedParameterNode<Set<?>>, Object>>() {
+
+      @Override
+      public Iterator<Entry<NamedParameterNode<Set<?>>, Object>> iterator() {
+        return builder.boundSetEntries.iterator();
+      }
+    };
+  }
+
+  @Override
+  public Set<NamedParameterNode<List<?>>> getBoundLists() {
+    return builder.boundLists.keySet();
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) {
+      return true;
+    }
+    if (o == null || getClass() != o.getClass()) {
+      return false;
+    }
+
+    final ConfigurationImpl that = (ConfigurationImpl) o;
+
+    if (builder != null ? !builder.equals(that.builder) : that.builder != null) {
+      return false;
+    }
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return builder != null ? builder.hashCode() : 0;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/Constructor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/Constructor.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/Constructor.java
new file mode 100644
index 0000000..b41682d
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/Constructor.java
@@ -0,0 +1,186 @@
+/**
+ * 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.reef.tang.implementation;
+
+import org.apache.reef.tang.types.ClassNode;
+import org.apache.reef.tang.types.ConstructorDef;
+
+import java.util.*;
+
+final public class Constructor<T> extends InjectionPlan<T> {
+
+  final ConstructorDef<T> constructor;
+  final InjectionPlan<?>[] args;
+  final int numAlternatives;
+  final boolean isAmbiguous;
+  final boolean isInjectable;
+
+  public Constructor(final ClassNode<T> classNode,
+                     final ConstructorDef<T> constructor, final InjectionPlan<?>[] args) {
+    super(classNode);
+    this.constructor = constructor;
+    this.args = args;
+    int curAlternatives = 1;
+    boolean curAmbiguous = false;
+    boolean curInjectable = true;
+    for (final InjectionPlan<?> plan : args) {
+      curAlternatives *= plan.getNumAlternatives();
+      curAmbiguous |= plan.isAmbiguous();
+      curInjectable &= plan.isInjectable();
+    }
+    this.numAlternatives = curAlternatives;
+    this.isAmbiguous = curAmbiguous;
+    this.isInjectable = curInjectable;
+  }
+
+  public InjectionPlan<?>[] getArgs() {
+    return args;
+  }
+
+  /**
+   * Get child elements of the injection plan tree.
+   * This method is inherited from the Traversable interface.
+   * TODO: use ArrayList internally (and maybe for input, too).
+   *
+   * @return A list of injection plans for the constructor's arguments.
+   */
+  @Override
+  public Collection<InjectionPlan<?>> getChildren() {
+    return Collections.unmodifiableList(Arrays.asList(this.args));
+  }
+
+  public ConstructorDef<T> getConstructorDef() {
+    return constructor;
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public ClassNode<T> getNode() {
+    return (ClassNode<T>) node;
+  }
+
+  @Override
+  public int getNumAlternatives() {
+    return numAlternatives;
+  }
+
+  @Override
+  public boolean isAmbiguous() {
+    return isAmbiguous;
+  }
+
+  @Override
+  public boolean isInjectable() {
+    return isInjectable;
+  }
+
+  @Override
+  public String toString() {
+    final StringBuilder sb = new StringBuilder("new " + getNode().getName() + '(');
+    if (args.length > 0) {
+      sb.append(args[0]);
+      for (int i = 1; i < args.length; i++) {
+        sb.append(", " + args[i]);
+      }
+    }
+    sb.append(')');
+    return sb.toString();
+  }
+
+  private String shallowArgString(final InjectionPlan<?> arg) {
+    if (arg instanceof Constructor || arg instanceof Subplan) {
+      return arg.getClass().getName() + ": " + arg.getNode().getName();
+    } else {
+      return arg.toShallowString();
+    }
+  }
+
+  @Override
+  public String toShallowString() {
+    final StringBuilder sb = new StringBuilder("new " + getNode().getName() + '(');
+    if (args.length > 0) {
+      sb.append(shallowArgString(args[0]));
+      for (int i = 1; i < args.length; i++) {
+        sb.append(", " + shallowArgString(args[i]));
+      }
+    }
+    sb.append(')');
+    return sb.toString();
+  }
+
+  /**
+   * @return A string describing ambiguous constructor arguments.
+   * @throws IllegalArgumentException if constructor is not ambiguous.
+   */
+  @Override
+  protected String toAmbiguousInjectString() {
+
+    if (!isAmbiguous) {
+      throw new IllegalArgumentException(getNode().getFullName() + " is NOT ambiguous.");
+    }
+
+    final StringBuilder sb = new StringBuilder(
+        getNode().getFullName() + " has ambiguous arguments: [ ");
+
+    for (final InjectionPlan<?> plan : args) {
+      if (plan.isAmbiguous()) {
+        sb.append(plan.toAmbiguousInjectString());
+      }
+    }
+
+    sb.append(']');
+    return sb.toString();
+  }
+
+  @Override
+  protected String toInfeasibleInjectString() {
+
+    final List<InjectionPlan<?>> leaves = new ArrayList<>();
+
+    for (final InjectionPlan<?> ip : args) {
+      if (!ip.isFeasible()) {
+        if (ip.isInfeasibleLeaf()) {
+          leaves.add(ip);
+        } else {
+          return ip.toInfeasibleInjectString();
+        }
+      }
+    }
+
+    if (leaves.isEmpty()) {
+      throw new IllegalArgumentException(getNode().getFullName() + " has NO infeasible leaves.");
+    }
+
+    if (leaves.size() == 1) {
+      return getNode().getFullName() + " missing argument " + leaves.get(0).getNode().getFullName();
+    } else {
+      final StringBuffer sb = new StringBuffer(getNode().getFullName() + " missing arguments: [\n\t");
+      for (final InjectionPlan<?> leaf : leaves) {
+        sb.append(leaf.getNode().getFullName() + "\n\t");
+      }
+      sb.append(']');
+      return sb.toString();
+    }
+  }
+
+  @Override
+  protected boolean isInfeasibleLeaf() {
+    return false;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/InjectionFuturePlan.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/InjectionFuturePlan.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/InjectionFuturePlan.java
new file mode 100644
index 0000000..b57eeec
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/InjectionFuturePlan.java
@@ -0,0 +1,64 @@
+/**
+ * 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.reef.tang.implementation;
+
+import org.apache.reef.tang.types.Node;
+
+public class InjectionFuturePlan<T> extends InjectionPlan<T> {
+
+  public InjectionFuturePlan(Node name) {
+    super(name);
+  }
+
+  @Override
+  public int getNumAlternatives() {
+    return 1;
+  }
+
+  @Override
+  public boolean isAmbiguous() {
+    return false;
+  }
+
+  @Override
+  public boolean isInjectable() {
+    return true;
+  }
+
+  @Override
+  protected String toAmbiguousInjectString() {
+    throw new UnsupportedOperationException("InjectionFuturePlan cannot be ambiguous!");
+  }
+
+  @Override
+  protected String toInfeasibleInjectString() {
+    throw new UnsupportedOperationException("InjectionFuturePlan is always feasible!");
+  }
+
+  @Override
+  protected boolean isInfeasibleLeaf() {
+    return false;
+  }
+
+  @Override
+  public String toShallowString() {
+    return "InjectionFuture<" + getNode().getFullName() + ">";
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/InjectionPlan.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/InjectionPlan.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/InjectionPlan.java
new file mode 100644
index 0000000..ee113b1
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/InjectionPlan.java
@@ -0,0 +1,161 @@
+/**
+ * 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.reef.tang.implementation;
+
+import org.apache.reef.tang.types.Node;
+import org.apache.reef.tang.types.Traversable;
+
+import java.util.Collection;
+import java.util.Collections;
+
+public abstract class InjectionPlan<T> implements Traversable<InjectionPlan<?>> {
+
+  protected final Node node;
+
+  public InjectionPlan(final Node node) {
+    this.node = node;
+  }
+
+  private static void newline(StringBuffer pretty, int indent) {
+    pretty.append('\n');
+    for (int j = 0; j < indent * 2; j++) {
+      pretty.append(' ');
+    }
+  }
+
+  public Node getNode() {
+    return node;
+  }
+
+  /**
+   * Get child elements of the injection plan tree.
+   * By default, returns an empty list.
+   *
+   * @return An empty list.
+   */
+  @SuppressWarnings("unchecked")
+  @Override
+  public Collection<InjectionPlan<?>> getChildren() {
+    return Collections.EMPTY_LIST;
+  }
+
+  public abstract int getNumAlternatives();
+
+  public boolean isFeasible() {
+    return getNumAlternatives() > 0;
+  }
+
+  abstract public boolean isAmbiguous();
+
+  abstract public boolean isInjectable();
+
+  protected void pad(StringBuffer sb, int n) {
+    for (int i = 0; i < n; i++) {
+      sb.append("  ");
+    }
+  }
+
+  public String toPrettyString() {
+    String ugly = node.getFullName() + ":\n" + toString();
+    StringBuffer pretty = new StringBuffer();
+    int currentIndent = 1;
+    for (int i = 0; i < ugly.length(); i++) {
+      char c = ugly.charAt(i);
+      if (c == '(') {
+        if (ugly.charAt(i + 1) == ')') {
+          pretty.append("()");
+          i++;
+        } else {
+          newline(pretty, currentIndent);
+          currentIndent++;
+          pretty.append(c);
+          pretty.append(' ');
+        }
+      } else if (c == '[') {
+        if (ugly.charAt(i + 1) == ']') {
+          pretty.append("[]");
+          i++;
+        } else {
+          newline(pretty, currentIndent);
+          currentIndent++;
+          pretty.append(c);
+          pretty.append(' ');
+        }
+      } else if (c == ')' || c == ']') {
+        currentIndent--;
+        newline(pretty, currentIndent);
+        pretty.append(c);
+      } else if (c == '|') {
+        newline(pretty, currentIndent);
+        pretty.append(c);
+      } else if (c == ',') {
+        currentIndent--;
+        newline(pretty, currentIndent);
+        pretty.append(c);
+        currentIndent++;
+      } else {
+        pretty.append(c);
+      }
+    }
+    return pretty.toString();
+  }
+
+  /**
+   * Algorithm for generating cant inject string:
+   * <p/>
+   * For infeasible plans:
+   * <p/>
+   * Some node types are "leaves":
+   * <ul>
+   * <li>NamedParameterNode</li>
+   * <li>ClassNode with no @Inject constructors</li>
+   * </ul>
+   * We do a depth first search of the injection plan, starting with the left
+   * most constructor arguments. When we encounter a constructor whose arguments
+   * are all either injectable or non-injectable leaf nodes, we return the name
+   * of its parent, and the name of the non-injectable leaves.
+   * <p/>
+   * For ambiguous plans:
+   * <p/>
+   * We perform a depth first search of the ambiguous constructors, as above. We
+   * return the name of the first class that has multiple constructors that are
+   * feasible or ambiguous (as opposed to having a single constructor with an
+   * ambiguous argument, or a constructor with an infeasible argument and an
+   * ambiguous argument).
+   */
+  public final String toCantInjectString() {
+    if (!isFeasible()) {
+      return toInfeasibleInjectString();
+    } else if (isAmbiguous()) {
+      return toAmbiguousInjectString();
+    } else {
+      throw new IllegalArgumentException(
+          "toCantInjectString() called on injectable constructor:"
+              + this.toPrettyString());
+    }
+  }
+
+  protected abstract String toAmbiguousInjectString();
+
+  protected abstract String toInfeasibleInjectString();
+
+  protected abstract boolean isInfeasibleLeaf();
+
+  public abstract String toShallowString();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/ListInjectionPlan.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/ListInjectionPlan.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/ListInjectionPlan.java
new file mode 100644
index 0000000..236820c
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/ListInjectionPlan.java
@@ -0,0 +1,106 @@
+/**
+ * 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.reef.tang.implementation;
+
+import org.apache.reef.tang.types.Node;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ListInjectionPlan<T> extends InjectionPlan<T> {
+  private final List<InjectionPlan<T>> entries = new ArrayList<>();
+  private final int numAlternatives;
+  private final boolean isAmbiguous;
+  private final boolean isInjectable;
+
+  public ListInjectionPlan(Node name, List<InjectionPlan<T>> entries) {
+    super(name);
+    this.entries.addAll(entries);
+    int numAlternatives = 1;
+    boolean isAmbiguous = false;
+    boolean isInjectable = true;
+    for (InjectionPlan<T> ip : entries) {
+      numAlternatives *= ip.getNumAlternatives();
+      isAmbiguous |= ip.isAmbiguous();
+      isInjectable &= ip.isInjectable();
+    }
+    this.numAlternatives = numAlternatives;
+    this.isAmbiguous = isAmbiguous;
+    this.isInjectable = isInjectable;
+  }
+
+  @Override
+  public int getNumAlternatives() {
+    return numAlternatives;
+  }
+
+  @Override
+  public boolean isAmbiguous() {
+    return isAmbiguous;
+  }
+
+  @Override
+  public boolean isInjectable() {
+    return isInjectable;
+  }
+
+  public List<InjectionPlan<T>> getEntryPlans() {
+    return new ArrayList<>(this.entries);
+  }
+
+  @Override
+  protected String toAmbiguousInjectString() {
+    StringBuilder sb = new StringBuilder(getNode().getFullName() + "(list) includes ambiguous plans [");
+    for (InjectionPlan<T> ip : entries) {
+      if (ip.isAmbiguous()) {
+        sb.append("\n" + ip.toAmbiguousInjectString());
+      }
+    }
+    sb.append("]");
+    return sb.toString();
+  }
+
+  @Override
+  protected String toInfeasibleInjectString() {
+    StringBuilder sb = new StringBuilder(getNode().getFullName() + "(list) includes infeasible plans [");
+    for (InjectionPlan<T> ip : entries) {
+      if (!ip.isFeasible()) {
+        sb.append("\n" + ip.toInfeasibleInjectString());
+      }
+    }
+    sb.append("\n]");
+    return sb.toString();
+  }
+
+  @Override
+  protected boolean isInfeasibleLeaf() {
+    return false;
+  }
+
+  @Override
+  public String toShallowString() {
+    StringBuilder sb = new StringBuilder("list { ");
+    for (InjectionPlan<T> ip : entries) {
+      sb.append("\n" + ip.toShallowString());
+    }
+    sb.append("\n } ");
+    return null;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/SetInjectionPlan.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/SetInjectionPlan.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/SetInjectionPlan.java
new file mode 100644
index 0000000..e39a17f
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/SetInjectionPlan.java
@@ -0,0 +1,106 @@
+/**
+ * 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.reef.tang.implementation;
+
+import org.apache.reef.tang.types.Node;
+import org.apache.reef.tang.util.MonotonicHashSet;
+
+import java.util.Set;
+
+public class SetInjectionPlan<T> extends InjectionPlan<T> {
+  private final Set<InjectionPlan<T>> entries = new MonotonicHashSet<>();
+  private final int numAlternatives;
+  private final boolean isAmbiguous;
+  private final boolean isInjectable;
+
+  public SetInjectionPlan(Node name, Set<InjectionPlan<T>> entries) {
+    super(name);
+    this.entries.addAll(entries);
+    int numAlternatives = 1;
+    boolean isAmbiguous = false;
+    boolean isInjectable = true;
+    for (InjectionPlan<T> ip : entries) {
+      numAlternatives *= ip.getNumAlternatives();
+      isAmbiguous |= ip.isAmbiguous();
+      isInjectable &= ip.isInjectable();
+    }
+    this.numAlternatives = numAlternatives;
+    this.isAmbiguous = isAmbiguous;
+    this.isInjectable = isInjectable;
+  }
+
+  @Override
+  public int getNumAlternatives() {
+    return numAlternatives;
+  }
+
+  @Override
+  public boolean isAmbiguous() {
+    return isAmbiguous;
+  }
+
+  @Override
+  public boolean isInjectable() {
+    return isInjectable;
+  }
+
+  public Set<InjectionPlan<T>> getEntryPlans() {
+    return new MonotonicHashSet<>(this.entries);
+  }
+
+  @Override
+  protected String toAmbiguousInjectString() {
+    StringBuilder sb = new StringBuilder(getNode().getFullName() + "(set) includes ambiguous plans [");
+    for (InjectionPlan<T> ip : entries) {
+      if (ip.isAmbiguous()) {
+        sb.append("\n" + ip.toAmbiguousInjectString());
+      }
+    }
+    sb.append("]");
+    return sb.toString();
+  }
+
+  @Override
+  protected String toInfeasibleInjectString() {
+    StringBuilder sb = new StringBuilder(getNode().getFullName() + "(set) includes infeasible plans [");
+    for (InjectionPlan<T> ip : entries) {
+      if (!ip.isFeasible()) {
+        sb.append("\n" + ip.toInfeasibleInjectString());
+      }
+    }
+    sb.append("\n]");
+    return sb.toString();
+  }
+
+  @Override
+  protected boolean isInfeasibleLeaf() {
+    return false;
+  }
+
+  @Override
+  public String toShallowString() {
+    StringBuilder sb = new StringBuilder("set { ");
+    for (InjectionPlan<T> ip : entries) {
+      sb.append("\n" + ip.toShallowString());
+    }
+    sb.append("\n } ");
+    return null;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/StackBindLocation.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/StackBindLocation.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/StackBindLocation.java
new file mode 100644
index 0000000..1349001
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/StackBindLocation.java
@@ -0,0 +1,46 @@
+/**
+ * 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.reef.tang.implementation;
+
+import org.apache.reef.tang.BindLocation;
+
+import java.util.Arrays;
+
+public class StackBindLocation implements BindLocation {
+  final StackTraceElement[] stack;
+
+  public StackBindLocation() {
+    StackTraceElement[] stack = new Throwable().getStackTrace();
+    if (stack.length != 0) {
+      this.stack = Arrays.copyOfRange(stack, 1, stack.length);
+    } else {
+      this.stack = new StackTraceElement[0];
+    }
+  }
+
+  @Override
+  public String toString() {
+    StringBuffer sb = new StringBuffer("[\n");
+    for (StackTraceElement e : stack) {
+      sb.append(e.toString() + "\n");
+    }
+    sb.append("]\n");
+    return sb.toString();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/Subplan.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/Subplan.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/Subplan.java
new file mode 100644
index 0000000..5866703
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/Subplan.java
@@ -0,0 +1,188 @@
+/**
+ * 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.reef.tang.implementation;
+
+import org.apache.reef.tang.types.Node;
+
+import java.util.*;
+
+final public class Subplan<T> extends InjectionPlan<T> {
+  final InjectionPlan<? extends T>[] alternatives;
+  final int numAlternatives;
+  final int selectedIndex;
+
+  @SafeVarargs
+  public Subplan(Node node, int selectedIndex, InjectionPlan<T>... alternatives) {
+    super(node);
+    this.alternatives = alternatives;
+    if (selectedIndex < -1 || selectedIndex >= alternatives.length) {
+      throw new ArrayIndexOutOfBoundsException();
+    }
+    this.selectedIndex = selectedIndex;
+    if (selectedIndex != -1) {
+      this.numAlternatives = alternatives[selectedIndex].getNumAlternatives();
+    } else {
+      int numAlternatives = 0;
+      for (InjectionPlan<? extends T> a : alternatives) {
+        numAlternatives += a.getNumAlternatives();
+      }
+      this.numAlternatives = numAlternatives;
+    }
+  }
+
+  @SafeVarargs
+  public Subplan(Node node, InjectionPlan<T>... alternatives) {
+    this(node, -1, alternatives);
+  }
+
+  /**
+   * Get child elements of the injection plan tree.
+   * TODO: use ArrayList internally (and maybe for input, too).
+   *
+   * @return A list of injection sub-plans.
+   */
+  @SuppressWarnings({"unchecked", "rawtypes"})
+  @Override
+  public Collection<InjectionPlan<?>> getChildren() {
+    return (Collection) Collections.unmodifiableCollection(Arrays.asList(this.alternatives));
+  }
+
+  @Override
+  public int getNumAlternatives() {
+    return this.numAlternatives;
+  }
+
+  /**
+   * Even if there is only one sub-plan, it was registered as a default plan,
+   * and is therefore ambiguous.
+   */
+  @Override
+  public boolean isAmbiguous() {
+    if (selectedIndex == -1) {
+      return true;
+    }
+    return alternatives[selectedIndex].isAmbiguous();
+  }
+
+  @Override
+  public boolean isInjectable() {
+    if (selectedIndex == -1) {
+      return false;
+    } else {
+      return alternatives[selectedIndex].isInjectable();
+    }
+  }
+
+  @Override
+  public String toString() {
+    if (alternatives.length == 1) {
+      return getNode().getName() + " = " + alternatives[0];
+    } else if (alternatives.length == 0) {
+      return getNode().getName() + ": no injectable constructors";
+    }
+    StringBuilder sb = new StringBuilder("[");
+    sb.append(getNode().getName() + " = " + alternatives[0]);
+    for (int i = 1; i < alternatives.length; i++) {
+      sb.append(" | " + alternatives[i]);
+    }
+    sb.append("]");
+    return sb.toString();
+  }
+
+  @Override
+  public String toShallowString() {
+    if (alternatives.length == 1) {
+      return getNode().getName() + " = " + alternatives[0].toShallowString();
+    } else if (alternatives.length == 0) {
+      return getNode().getName() + ": no injectable constructors";
+    }
+    StringBuilder sb = new StringBuilder("[");
+    sb.append(getNode().getName() + " = " + alternatives[0].toShallowString());
+    for (int i = 1; i < alternatives.length; i++) {
+      sb.append(" | " + alternatives[i].toShallowString());
+    }
+    sb.append("]");
+    return sb.toString();
+  }
+
+  public int getSelectedIndex() {
+    return selectedIndex;
+  }
+
+  public InjectionPlan<? extends T> getDelegatedPlan() {
+    if (selectedIndex == -1) {
+      throw new IllegalStateException();
+    } else {
+      return alternatives[selectedIndex];
+    }
+  }
+
+  @Override
+  protected String toAmbiguousInjectString() {
+    if (alternatives.length == 1) {
+      return alternatives[0].toAmbiguousInjectString();
+    } else if (selectedIndex != -1) {
+      return alternatives[selectedIndex].toAmbiguousInjectString();
+    } else {
+      List<InjectionPlan<?>> alts = new ArrayList<>();
+      List<InjectionPlan<?>> ambig = new ArrayList<>();
+      for (InjectionPlan<?> alt : alternatives) {
+        if (alt.isFeasible()) {
+          alts.add(alt);
+        }
+        if (alt.isAmbiguous()) {
+          ambig.add(alt);
+        }
+      }
+      StringBuffer sb = new StringBuffer("Ambigous subplan " + getNode().getFullName());
+      for (InjectionPlan<?> alt : alts) {
+        sb.append("\n  " + alt.toShallowString() + " ");
+      }
+      for (InjectionPlan<?> alt : ambig) {
+        sb.append("\n  " + alt.toShallowString() + " ");
+      }
+      sb.append("\n]");
+      return sb.toString();
+    }
+  }
+
+  @Override
+  protected String toInfeasibleInjectString() {
+    if (alternatives.length == 1) {
+      return alternatives[0].toInfeasibleInjectString();
+    } else if (alternatives.length == 0) {
+      return "No known implementations / injectable constructors for "
+          + this.getNode().getFullName();
+    } else if (selectedIndex != -1) {
+      return alternatives[selectedIndex].toInfeasibleInjectString();
+    } else {
+      return "Multiple infeasible plans: " + toPrettyString();
+    }
+  }
+
+  @Override
+  protected boolean isInfeasibleLeaf() {
+    return false;
+  }
+
+  public InjectionPlan<?>[] getPlans() {
+    return Arrays.copyOf(alternatives, alternatives.length);
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/TangImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/TangImpl.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/TangImpl.java
new file mode 100644
index 0000000..52e0569
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/TangImpl.java
@@ -0,0 +1,161 @@
+/**
+ * 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.reef.tang.implementation;
+
+import org.apache.reef.tang.*;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.implementation.java.ClassHierarchyImpl;
+import org.apache.reef.tang.implementation.java.InjectorImpl;
+import org.apache.reef.tang.implementation.java.JavaConfigurationBuilderImpl;
+
+import java.net.URL;
+import java.util.*;
+
+public class TangImpl implements Tang {
+
+  private static Map<SetValuedKey, JavaClassHierarchy> defaultClassHierarchy = new HashMap<>();
+
+  /**
+   * Only for testing. Deletes Tang's current database of known classes, forcing
+   * it to rebuild them over time.
+   */
+  public static void reset() {
+    defaultClassHierarchy = new HashMap<>(); //new ClassHierarchyImpl();
+  }
+
+  @Override
+  public Injector newInjector(Configuration... confs) throws BindException {
+    return new InjectorImpl(new JavaConfigurationBuilderImpl(confs).build());
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public JavaConfigurationBuilder newConfigurationBuilder() {
+    try {
+      return newConfigurationBuilder(new URL[0], new Configuration[0], new Class[0]);
+    } catch (BindException e) {
+      throw new IllegalStateException(
+          "Caught unexpeceted bind exception!  Implementation bug.", e);
+    }
+  }
+
+  @Override
+  public ConfigurationBuilder newConfigurationBuilder(ClassHierarchy ch) {
+    return new ConfigurationBuilderImpl(ch);
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public JavaConfigurationBuilder newConfigurationBuilder(URL... jars) {
+    try {
+      return newConfigurationBuilder(jars, new Configuration[0], new Class[0]);
+    } catch (BindException e) {
+      throw new IllegalStateException(
+          "Caught unexpeceted bind exception!  Implementation bug.", e);
+    }
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public JavaConfigurationBuilder newConfigurationBuilder(
+      Configuration... confs) throws BindException {
+    return newConfigurationBuilder(new URL[0], confs, new Class[0]);
+  }
+
+  @Override
+  public final JavaConfigurationBuilder newConfigurationBuilder(
+      @SuppressWarnings("unchecked") Class<? extends ExternalConstructor<?>>... parsers) throws BindException {
+    return newConfigurationBuilder(new URL[0], new Configuration[0], parsers);
+  }
+
+  @Override
+  public JavaConfigurationBuilder newConfigurationBuilder(URL[] jars,
+                                                          Configuration[] confs, Class<? extends ExternalConstructor<?>>[] parameterParsers) throws BindException {
+    JavaConfigurationBuilder cb = new JavaConfigurationBuilderImpl(jars, confs, parameterParsers);
+//    for (Configuration c : confs) {
+//      cb.addConfiguration(c);
+//    }
+    return cb;
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public JavaClassHierarchy getDefaultClassHierarchy() {
+    return getDefaultClassHierarchy(new URL[0], new Class[0]);
+  }
+
+  @Override
+  public JavaClassHierarchy getDefaultClassHierarchy(URL[] jars, Class<? extends ExternalConstructor<?>>[] parameterParsers) {
+    SetValuedKey key = new SetValuedKey(jars, parameterParsers);
+
+    JavaClassHierarchy ret = defaultClassHierarchy.get(key);
+    if (ret == null) {
+      ret = new ClassHierarchyImpl(jars, parameterParsers);
+      defaultClassHierarchy.put(key, ret);
+    }
+    return ret;
+  }
+
+  @Override
+  public Injector newInjector(Configuration confs) {
+    try {
+      return newInjector(new Configuration[]{confs});
+    } catch (BindException e) {
+      throw new IllegalStateException("Unexpected error cloning configuration", e);
+    }
+  }
+
+  @Override
+  public Injector newInjector() {
+    try {
+      return newInjector(new Configuration[]{});
+    } catch (BindException e) {
+      throw new IllegalStateException("Unexpected error from empty configuration", e);
+    }
+  }
+
+  private class SetValuedKey {
+    public final Set<Object> key;
+
+    public SetValuedKey(Object[] ts, Object[] us) {
+      key = new HashSet<Object>(Arrays.asList(ts));
+      key.addAll(Arrays.asList(us));
+    }
+
+    @Override
+    public int hashCode() {
+      int i = 0;
+      for (Object t : key) {
+        i += t.hashCode();
+      }
+      return i;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+      SetValuedKey other = (SetValuedKey) o;
+      if (other.key.size() != this.key.size()) {
+        return false;
+      }
+      return key.containsAll(other.key);
+    }
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/ClassHierarchyImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/ClassHierarchyImpl.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/ClassHierarchyImpl.java
new file mode 100644
index 0000000..4368aa8
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/ClassHierarchyImpl.java
@@ -0,0 +1,448 @@
+/**
+ * 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.reef.tang.implementation.java;
+
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.ExternalConstructor;
+import org.apache.reef.tang.JavaClassHierarchy;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.ClassHierarchyException;
+import org.apache.reef.tang.exceptions.NameResolutionException;
+import org.apache.reef.tang.exceptions.ParseException;
+import org.apache.reef.tang.formats.ParameterParser;
+import org.apache.reef.tang.types.*;
+import org.apache.reef.tang.util.MonotonicTreeMap;
+import org.apache.reef.tang.util.ReflectionUtilities;
+
+import java.lang.reflect.Type;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.*;
+
+public class ClassHierarchyImpl implements JavaClassHierarchy {
+  // TODO Want to add a "register namespace" method, but Java is not designed
+  // to support such things.
+  // There are third party libraries that would help, but they can fail if the
+  // relevant jar has not yet been loaded.  Tint works around this using such
+  // a library.
+
+  /**
+   * The ParameterParser that this ClassHierarchy uses to parse default values.
+   * Custom parameter parsers allow applications to extend the set of classes
+   * that Tang can parse.
+   */
+  public final ParameterParser parameterParser = new ParameterParser();
+  /**
+   * The classloader that was used to populate this class hierarchy.
+   */
+  private final URLClassLoader loader;
+  /**
+   * The jars that are reflected by that loader.  These are in addition to
+   * whatever jars are available by the default classloader (i.e., the one
+   * that loaded Tang.  We need this list so that we can merge class hierarchies
+   * that are backed by different classpaths.
+   */
+  private final List<URL> jars;
+  /**
+   * A reference to the root package which is a root of a tree of nodes.
+   * The children of each node in the tree are accessible by name, and the
+   * structure of the tree mirrors Java's package namespace.
+   */
+  private final PackageNode namespace;
+  /**
+   * A map from short name to named parameter node.  This is only used to
+   * sanity check short names so that name clashes get resolved.
+   */
+  private final Map<String, NamedParameterNode<?>> shortNames = new MonotonicTreeMap<>();
+
+  @SuppressWarnings("unchecked")
+  public ClassHierarchyImpl() {
+    this(new URL[0], new Class[0]);
+  }
+
+  @SuppressWarnings("unchecked")
+  public ClassHierarchyImpl(URL... jars) {
+    this(jars, new Class[0]);
+  }
+
+  public ClassHierarchyImpl(URL[] jars, Class<? extends ExternalConstructor<?>>[] parameterParsers) {
+    this.namespace = JavaNodeFactory.createRootPackageNode();
+    this.jars = new ArrayList<>(Arrays.asList(jars));
+    this.loader = new URLClassLoader(jars, this.getClass().getClassLoader());
+    for (Class<? extends ExternalConstructor<?>> p : parameterParsers) {
+      try {
+        parameterParser.addParser(p);
+      } catch (BindException e) {
+        throw new IllegalArgumentException("Could not register parameter parsers", e);
+      }
+    }
+  }
+
+  /**
+   * A helper method that returns the parsed default value of a given
+   * NamedParameter.
+   *
+   * @return null or an empty set if there is no default value, the default value (or set of values) otherwise.
+   * @throws ClassHierarchyException if a default value was specified, but could not be parsed, or if a set of
+   *                                 values were specified for a non-set parameter.
+   */
+  @SuppressWarnings("unchecked")
+  @Override
+  public <T> T parseDefaultValue(NamedParameterNode<T> name) {
+    String[] vals = name.getDefaultInstanceAsStrings();
+    T[] ret = (T[]) new Object[vals.length];
+    for (int i = 0; i < vals.length; i++) {
+      String val = vals[i];
+      try {
+        ret[i] = parse(name, val);
+      } catch (ParseException e) {
+        throw new ClassHierarchyException("Could not parse default value", e);
+      }
+    }
+    if (name.isSet()) {
+      return (T) new HashSet<T>(Arrays.asList(ret));
+    } else if (name.isList()) {
+      return (T) new ArrayList<T>(Arrays.asList(ret));
+    } else {
+      if (ret.length == 0) {
+        return null;
+      } else if (ret.length == 1) {
+        return ret[0];
+      } else {
+        throw new IllegalStateException("Multiple defaults for non-set named parameter! " + name.getFullName());
+      }
+    }
+  }
+
+  /**
+   * Parse a string, assuming that it is of the type expected by a given NamedParameter.
+   * <p/>
+   * This method does not deal with sets; if the NamedParameter is set valued, then the provided
+   * string should correspond to a single member of the set.  It is up to the caller to call parse
+   * once for each value that should be parsed as a member of the set.
+   *
+   * @return a non-null reference to the parsed value.
+   */
+  @Override
+  @SuppressWarnings("unchecked")
+  public <T> T parse(NamedParameterNode<T> np, String value) throws ParseException {
+    final ClassNode<T> iface;
+    try {
+      iface = (ClassNode<T>) getNode(np.getFullArgName());
+    } catch (NameResolutionException e) {
+      throw new IllegalStateException("Could not parse validated named parameter argument type.  NamedParameter is " + np.getFullName() + " argument type is " + np.getFullArgName());
+    }
+    Class<?> clazz;
+    String fullName;
+    try {
+      clazz = (Class<?>) classForName(iface.getFullName());
+      fullName = null;
+    } catch (ClassNotFoundException e) {
+      clazz = null;
+      fullName = iface.getFullName();
+    }
+    try {
+      if (clazz != null) {
+        return (T) parameterParser.parse(clazz, value);
+      } else {
+        return parameterParser.parse(fullName, value);
+      }
+    } catch (UnsupportedOperationException e) {
+      try {
+        final Node impl = getNode(value);
+        if (impl instanceof ClassNode) {
+          if (isImplementation(iface, (ClassNode<?>) impl)) {
+            return (T) impl;
+          }
+        }
+        throw new ParseException("Name<" + iface.getFullName() + "> " + np.getFullName() + " cannot take non-subclass " + impl.getFullName(), e);
+      } catch (NameResolutionException e2) {
+        throw new ParseException("Name<" + iface.getFullName() + "> " + np.getFullName() + " cannot take non-class " + value, e);
+      }
+    }
+  }
+
+  /**
+   * Helper method that converts a String to a Class using this
+   * ClassHierarchy's classloader.
+   */
+  @Override
+  public Class<?> classForName(String name) throws ClassNotFoundException {
+    return ReflectionUtilities.classForName(name, loader);
+  }
+
+  private <T, U> Node buildPathToNode(Class<U> clazz)
+      throws ClassHierarchyException {
+    String[] path = clazz.getName().split("\\$");
+
+    Node root = namespace;
+    for (int i = 0; i < path.length - 1; i++) {
+      root = root.get(path[i]);
+    }
+
+    if (root == null) {
+      throw new NullPointerException();
+    }
+    Node parent = root;
+
+    Type argType = ReflectionUtilities.getNamedParameterTargetOrNull(clazz);
+
+    if (argType == null) {
+      return JavaNodeFactory.createClassNode(parent, clazz);
+    } else {
+
+      @SuppressWarnings("unchecked")
+      // checked inside of NamedParameterNode, using reflection.
+          NamedParameterNode<T> np = JavaNodeFactory.createNamedParameterNode(
+          parent, (Class<? extends Name<T>>) clazz, argType);
+
+      if (parameterParser.canParse(ReflectionUtilities.getFullName(argType))) {
+        if (clazz.getAnnotation(NamedParameter.class).default_class() != Void.class) {
+          throw new ClassHierarchyException("Named parameter " + ReflectionUtilities.getFullName(clazz) + " defines default implementation for parsable type " + ReflectionUtilities.getFullName(argType));
+        }
+      }
+
+      String shortName = np.getShortName();
+      if (shortName != null) {
+        NamedParameterNode<?> oldNode = shortNames.get(shortName);
+        if (oldNode != null) {
+          if (oldNode.getFullName().equals(np.getFullName())) {
+            throw new IllegalStateException("Tried to double bind "
+                + oldNode.getFullName() + " to short name " + shortName);
+          }
+          throw new ClassHierarchyException("Named parameters " + oldNode.getFullName()
+              + " and " + np.getFullName() + " have the same short name: "
+              + shortName);
+        }
+        shortNames.put(shortName, np);
+      }
+      return np;
+    }
+  }
+
+  private Node getAlreadyBoundNode(Class<?> clazz) throws NameResolutionException {
+    return getAlreadyBoundNode(ReflectionUtilities.getFullName(clazz));
+  }
+
+  @Override
+  public Node getNode(Class<?> clazz) {
+    try {
+      return getNode(ReflectionUtilities.getFullName(clazz));
+    } catch (NameResolutionException e) {
+      throw new ClassHierarchyException("JavaClassHierarchy could not resolve " + clazz
+          + " which is definitely avalable at runtime", e);
+    }
+  }
+
+  @Override
+  public synchronized Node getNode(String name) throws NameResolutionException {
+    Node n = register(name);
+    if (n == null) {
+      // This will never succeed; it just generates a nice exception.
+      getAlreadyBoundNode(name);
+      throw new IllegalStateException("IMPLEMENTATION BUG: Register failed, "
+          + "but getAlreadyBoundNode succeeded!");
+    }
+    return n;
+  }
+
+  private Node getAlreadyBoundNode(String name) throws NameResolutionException {
+    Node root = namespace;
+    String[] toks = name.split("\\$");
+    String outerClassName = toks[0];
+    root = root.get(outerClassName);
+    if (root == null) {
+      throw new NameResolutionException(name, outerClassName);
+    }
+    for (int i = 1; i < toks.length; i++) {
+      root = root.get(toks[i]);
+      if (root == null) {
+        StringBuilder sb = new StringBuilder(outerClassName);
+        for (int j = 0; j < i; j++) {
+          sb.append(toks[j]);
+          if (j != i - 1) {
+            sb.append(".");
+          }
+        }
+        throw new NameResolutionException(name, sb.toString());
+      }
+    }
+    return root;
+  }
+
+  private Node register(String s) {
+    final Class<?> c;
+    try {
+      c = classForName(s);
+    } catch (ClassNotFoundException e1) {
+      return null;
+    }
+    try {
+      Node n = getAlreadyBoundNode(c);
+      return n;
+    } catch (NameResolutionException e) {
+    }
+    // First, walk up the class hierarchy, registering all out parents. This
+    // can't be loopy.
+    if (c.getSuperclass() != null) {
+      register(ReflectionUtilities.getFullName(c.getSuperclass()));
+    }
+    for (Class<?> i : c.getInterfaces()) {
+      register(ReflectionUtilities.getFullName(i));
+    }
+    // Now, we'd like to register our enclosing classes. This turns out to be
+    // safe.
+    // Thankfully, Java doesn't allow:
+    // class A implements A.B { class B { } }
+
+    // It also doesn't allow cycles such as:
+    // class A implements B.BB { interface AA { } }
+    // class B implements A.AA { interface BB { } }
+
+    // So, even though grafting arbitrary DAGs together can give us cycles, Java
+    // seems
+    // to have our back on this one.
+    Class<?> enclosing = c.getEnclosingClass();
+    if (enclosing != null) {
+      register(ReflectionUtilities.getFullName(enclosing));
+    }
+
+    // Now register the class. This has to be after the above so we know our
+    // parents (superclasses and enclosing packages) are already registered.
+    Node n = registerClass(c);
+
+    // Finally, do things that might introduce cycles that invlove c.
+    // This has to be below registerClass, which ensures that any cycles
+    // this stuff introduces are broken.
+    for (Class<?> inner_class : c.getDeclaredClasses()) {
+      register(ReflectionUtilities.getFullName(inner_class));
+    }
+    if (n instanceof ClassNode) {
+      ClassNode<?> cls = (ClassNode<?>) n;
+      for (ConstructorDef<?> def : cls.getInjectableConstructors()) {
+        for (ConstructorArg arg : def.getArgs()) {
+          register(arg.getType());
+          if (arg.getNamedParameterName() != null) {
+            NamedParameterNode<?> np = (NamedParameterNode<?>) register(arg
+                .getNamedParameterName());
+            try {
+              if (np.isSet()) {
+                /// XXX When handling sets, need to track target of generic parameter, and check the type here!
+              } else if (np.isList()) {
+
+              } else {
+                if (!ReflectionUtilities.isCoercable(classForName(arg.getType()),
+                    classForName(np.getFullArgName()))) {
+                  throw new ClassHierarchyException(
+                      "Named parameter type mismatch in " + cls.getFullName() + ".  Constructor expects a "
+                          + arg.getType() + " but " + np.getName() + " is a "
+                          + np.getFullArgName());
+                }
+              }
+            } catch (ClassNotFoundException e) {
+              throw new ClassHierarchyException("Constructor refers to unknown class "
+                  + arg.getType(), e);
+            }
+          }
+        }
+      }
+    } else if (n instanceof NamedParameterNode) {
+      NamedParameterNode<?> np = (NamedParameterNode<?>) n;
+      register(np.getFullArgName());
+    }
+    return n;
+  }
+
+  /**
+   * Assumes that all of the parents of c have been registered already.
+   *
+   * @param c
+   */
+  @SuppressWarnings("unchecked")
+  private <T> Node registerClass(final Class<T> c)
+      throws ClassHierarchyException {
+    if (c.isArray()) {
+      throw new UnsupportedOperationException("Can't register array types");
+    }
+    try {
+      return getAlreadyBoundNode(c);
+    } catch (NameResolutionException e) {
+    }
+
+    final Node n = buildPathToNode(c);
+
+    if (n instanceof ClassNode) {
+      ClassNode<T> cn = (ClassNode<T>) n;
+      Class<T> superclass = (Class<T>) c.getSuperclass();
+      if (superclass != null) {
+        try {
+          ((ClassNode<T>) getAlreadyBoundNode(superclass)).putImpl(cn);
+        } catch (NameResolutionException e) {
+          throw new IllegalStateException(e);
+        }
+      }
+      for (Class<?> interf : c.getInterfaces()) {
+        try {
+          ((ClassNode<T>) getAlreadyBoundNode(interf)).putImpl(cn);
+        } catch (NameResolutionException e) {
+          throw new IllegalStateException(e);
+        }
+      }
+    }
+    return n;
+  }
+
+  @Override
+  public PackageNode getNamespace() {
+    return namespace;
+  }
+
+  @Override
+  public synchronized boolean isImplementation(ClassNode<?> inter, ClassNode<?> impl) {
+    return impl.isImplementationOf(inter);
+  }
+
+  @Override
+  public synchronized ClassHierarchy merge(ClassHierarchy ch) {
+    if (this == ch) {
+      return this;
+    }
+    if (!(ch instanceof ClassHierarchyImpl)) {
+      throw new UnsupportedOperationException("Can't merge java and non-java class hierarchies yet!");
+    }
+    if (this.jars.size() == 0) {
+      return ch;
+    }
+    ClassHierarchyImpl chi = (ClassHierarchyImpl) ch;
+    HashSet<URL> otherJars = new HashSet<>();
+    otherJars.addAll(chi.jars);
+    HashSet<URL> myJars = new HashSet<>();
+    myJars.addAll(this.jars);
+    if (myJars.containsAll(otherJars)) {
+      return this;
+    } else if (otherJars.containsAll(myJars)) {
+      return ch;
+    } else {
+      myJars.addAll(otherJars);
+      return new ClassHierarchyImpl(myJars.toArray(new URL[0]));
+    }
+  }
+}


[07/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterface.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterface.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterface.java
new file mode 100644
index 0000000..7205d4a
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterface.java
@@ -0,0 +1,27 @@
+/**
+ * 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.reef.tang.test;
+
+/**
+ * Interface used for the set injecttion test.
+ */
+interface SetInterface {
+
+  void aMethod();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterfaceImplOne.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterfaceImplOne.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterfaceImplOne.java
new file mode 100644
index 0000000..3d9f0c7
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterfaceImplOne.java
@@ -0,0 +1,56 @@
+/**
+ * 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.reef.tang.test;
+
+import javax.inject.Inject;
+
+/**
+ * Created by mweimer on 3/18/14.
+ */
+final class SetInterfaceImplOne implements SetInterface {
+
+  private final int magicNumber;
+
+  @Inject
+  public SetInterfaceImplOne() {
+    this.magicNumber = 42;
+  }
+
+  @Override
+  public void aMethod() {
+
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    SetInterfaceImplOne that = (SetInterfaceImplOne) o;
+
+    if (magicNumber != that.magicNumber) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return magicNumber;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterfaceImplTwo.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterfaceImplTwo.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterfaceImplTwo.java
new file mode 100644
index 0000000..4e8bb3a
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetInterfaceImplTwo.java
@@ -0,0 +1,54 @@
+/**
+ * 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.reef.tang.test;
+
+import javax.inject.Inject;
+
+final class SetInterfaceImplTwo implements SetInterface {
+
+  private final double magicNumber;
+
+  @Inject
+  SetInterfaceImplTwo() {
+    this.magicNumber = 42.0;
+  }
+
+  @Override
+  public void aMethod() {
+
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    SetInterfaceImplTwo that = (SetInterfaceImplTwo) o;
+
+    if (Double.compare(that.magicNumber, magicNumber) != 0) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    long temp = Double.doubleToLongBits(magicNumber);
+    return (int) (temp ^ (temp >>> 32));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetOfBaseTypes.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetOfBaseTypes.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetOfBaseTypes.java
new file mode 100644
index 0000000..fda1504
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetOfBaseTypes.java
@@ -0,0 +1,85 @@
+/**
+ * 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.reef.tang.test;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+import java.util.Set;
+
+/**
+ * A class that depends on sets of base types.
+ */
+final class SetOfBaseTypes {
+  private final Set<Integer> integers;
+  private final Set<Double> doubles;
+  private final Set<String> strings;
+  private final Set<Integer> moreIntegers;
+
+  @Inject
+  SetOfBaseTypes(@Parameter(Integers.class) final Set<Integer> integers,
+                 @Parameter(Doubles.class) final Set<Double> doubles,
+                 @Parameter(Strings.class) final Set<String> strings,
+                 @Parameter(MoreIntegers.class) final Set<Integer> moreIntegers) {
+    this.integers = integers;
+    this.doubles = doubles;
+    this.strings = strings;
+    this.moreIntegers = moreIntegers;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    SetOfBaseTypes that = (SetOfBaseTypes) o;
+
+    if (!doubles.equals(that.doubles)) return false;
+    if (!integers.equals(that.integers)) return false;
+    if (!strings.equals(that.strings)) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = integers.hashCode();
+    result = 31 * result + doubles.hashCode();
+    result = 31 * result + strings.hashCode();
+    return result;
+  }
+
+  @NamedParameter
+  public static class Integers implements Name<Set<Integer>> {
+  }
+
+  @NamedParameter(default_values = {"1", "2", "3"})
+  public static class MoreIntegers implements Name<Set<Integer>> {
+  }
+
+  @NamedParameter
+  public static class Doubles implements Name<Set<Double>> {
+  }
+
+  @NamedParameter
+  public static class Strings implements Name<Set<String>> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetOfImplementations.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetOfImplementations.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetOfImplementations.java
new file mode 100644
index 0000000..5372af2
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/SetOfImplementations.java
@@ -0,0 +1,55 @@
+/**
+ * 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.reef.tang.test;
+
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+import java.util.Set;
+
+final class SetOfImplementations {
+
+  private final Set<SetInterface> theInstances;
+
+  @Inject
+  SetOfImplementations(@Parameter(TestConfiguration.SetOfInstances.class) final Set<SetInterface> theInstances) {
+    this.theInstances = theInstances;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    SetOfImplementations that = (SetOfImplementations) o;
+
+    if (!theInstances.equals(that.theInstances)) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return theInstances.hashCode();
+  }
+
+  public boolean isValid() {
+    return this.theInstances.size() == 2;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/TestConfiguration.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/TestConfiguration.java
new file mode 100644
index 0000000..98f1329
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/TestConfiguration.java
@@ -0,0 +1,110 @@
+/**
+ * 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.reef.tang.test;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.OptionalParameter;
+import org.apache.reef.tang.formats.RequiredParameter;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * All the configuration parameters and options for the test.
+ */
+public class TestConfiguration extends ConfigurationModuleBuilder {
+  public static final String REQUIRED_STRING_VALUE = "Required String Value";
+  public static final String OPTIONAL_STRING_VALUE = "Optional String Value";
+  public static final RequiredParameter<String> REQUIRED_STRING = new RequiredParameter<>();
+  public static final OptionalParameter<String> OPTIONAL_STRING = new OptionalParameter<>();
+  public static final int NAMED_PARAMETER_INTEGER_VALUE = 42;
+  public static final double NAMED_PARAMETER_DOUBLE_VALUE = 42.0;
+  // Pre-defined lists used in injection
+  private static final List<Class<? extends ListInterface>> injectedImplList = Arrays.asList(ListInterfaceImplOne.class,
+      ListInterfaceImplTwo.class);
+  private static final List<String> injectedIntegerList = Arrays.asList("1", "2", "3");
+  private static final List<String> injectedDoubleList = Arrays.asList("1", "2", "3");
+  private static final List<String> injectedStringList = Arrays.asList("1", "2", "3");
+
+  public static final ConfigurationModule CONF = new TestConfiguration()
+      .bindImplementation(RootInterface.class, RootImplementation.class)
+      .bindNamedParameter(IntegerHandler.class, UnitClass.IntegerHandler.class)
+      .bindNamedParameter(StringHandler.class, UnitClass.StringHandler.class)
+      .bindNamedParameter(NamedParameterInteger.class, String.valueOf(NAMED_PARAMETER_INTEGER_VALUE))
+      .bindNamedParameter(NamedParameterDouble.class, String.valueOf(NAMED_PARAMETER_DOUBLE_VALUE))
+      .bindSetEntry(SetOfInstances.class, SetInterfaceImplOne.class)
+      .bindSetEntry(SetOfInstances.class, SetInterfaceImplTwo.class)
+          // Adds list implementations
+      .bindList(ListOfInstances.class, injectedImplList)
+      .bindNamedParameter(RequiredString.class, REQUIRED_STRING)
+      .bindNamedParameter(OptionalString.class, OPTIONAL_STRING)
+          // Sets of base types
+      .bindSetEntry(SetOfBaseTypes.Integers.class, "1")
+      .bindSetEntry(SetOfBaseTypes.Integers.class, "2")
+      .bindSetEntry(SetOfBaseTypes.Integers.class, "3")
+      .bindSetEntry(SetOfBaseTypes.Doubles.class, "1")
+      .bindSetEntry(SetOfBaseTypes.Doubles.class, "2")
+      .bindSetEntry(SetOfBaseTypes.Doubles.class, "3")
+      .bindSetEntry(SetOfBaseTypes.Strings.class, "1")
+      .bindSetEntry(SetOfBaseTypes.Strings.class, "2")
+      .bindSetEntry(SetOfBaseTypes.Strings.class, "3")
+          // Lists of base types
+      .bindList(ListOfBaseTypes.Integers.class, injectedIntegerList)
+      .bindList(ListOfBaseTypes.Doubles.class, injectedDoubleList)
+      .bindList(ListOfBaseTypes.Strings.class, injectedStringList)
+      .build();
+
+  @NamedParameter()
+  public static final class RequiredString implements Name<String> {
+  }
+
+  @NamedParameter(default_value = "default_string_default_value")
+  public static final class OptionalString implements Name<String> {
+  }
+
+  @NamedParameter()
+  public static final class IntegerHandler implements Name<Handler<Integer>> {
+  }
+
+  @NamedParameter()
+  public static final class StringHandler implements Name<Handler<String>> {
+  }
+
+  @NamedParameter()
+  public static final class NamedParameterInteger implements Name<Integer> {
+  }
+
+  @NamedParameter()
+  public static final class NamedParameterDouble implements Name<Double> {
+  }
+
+  @NamedParameter
+  public static final class SetOfInstances implements Name<Set<SetInterface>> {
+  }
+
+  @NamedParameter
+  public static final class ListOfInstances implements Name<List<ListInterface>> {
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/TestConfigurationWithoutList.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/TestConfigurationWithoutList.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/TestConfigurationWithoutList.java
new file mode 100644
index 0000000..36b9704
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/TestConfigurationWithoutList.java
@@ -0,0 +1,92 @@
+/**
+ * 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.reef.tang.test;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.OptionalParameter;
+import org.apache.reef.tang.formats.RequiredParameter;
+
+import java.util.Set;
+
+/**
+ * All the configuration parameters and options for the test without list
+ */
+public class TestConfigurationWithoutList extends ConfigurationModuleBuilder {
+  public static final String REQUIRED_STRING_VALUE = "Required String Value";
+  public static final String OPTIONAL_STRING_VALUE = "Optional String Value";
+  public static final RequiredParameter<String> REQUIRED_STRING = new RequiredParameter<>();
+  public static final OptionalParameter<String> OPTIONAL_STRING = new OptionalParameter<>();
+  public static final int NAMED_PARAMETER_INTEGER_VALUE = 42;
+  public static final double NAMED_PARAMETER_DOUBLE_VALUE = 42.0;
+  public static final ConfigurationModule CONF = new TestConfigurationWithoutList()
+      .bindImplementation(RootInterface.class, RootImplementationWithoutList.class)
+      .bindNamedParameter(IntegerHandler.class, UnitClass.IntegerHandler.class)
+      .bindNamedParameter(StringHandler.class, UnitClass.StringHandler.class)
+      .bindNamedParameter(NamedParameterInteger.class, String.valueOf(NAMED_PARAMETER_INTEGER_VALUE))
+      .bindNamedParameter(NamedParameterDouble.class, String.valueOf(NAMED_PARAMETER_DOUBLE_VALUE))
+      .bindSetEntry(SetOfInstances.class, SetInterfaceImplOne.class)
+      .bindSetEntry(SetOfInstances.class, SetInterfaceImplTwo.class)
+          // Adds list implementations
+      .bindNamedParameter(RequiredString.class, REQUIRED_STRING)
+      .bindNamedParameter(OptionalString.class, OPTIONAL_STRING)
+          // Sets of base types
+      .bindSetEntry(SetOfBaseTypes.Integers.class, "1")
+      .bindSetEntry(SetOfBaseTypes.Integers.class, "2")
+      .bindSetEntry(SetOfBaseTypes.Integers.class, "3")
+      .bindSetEntry(SetOfBaseTypes.Doubles.class, "1")
+      .bindSetEntry(SetOfBaseTypes.Doubles.class, "2")
+      .bindSetEntry(SetOfBaseTypes.Doubles.class, "3")
+      .bindSetEntry(SetOfBaseTypes.Strings.class, "1")
+      .bindSetEntry(SetOfBaseTypes.Strings.class, "2")
+      .bindSetEntry(SetOfBaseTypes.Strings.class, "3")
+          // Lists of base types
+      .build();
+
+  // TODO: Remove this method after #192 is fixed
+  @NamedParameter()
+  public static final class RequiredString implements Name<String> {
+  }
+
+  @NamedParameter(default_value = "default_string_default_value")
+  public static final class OptionalString implements Name<String> {
+  }
+
+  @NamedParameter()
+  public static final class IntegerHandler implements Name<Handler<Integer>> {
+  }
+
+  @NamedParameter()
+  public static final class StringHandler implements Name<Handler<String>> {
+  }
+
+  @NamedParameter()
+  public static final class NamedParameterInteger implements Name<Integer> {
+  }
+
+  @NamedParameter()
+  public static final class NamedParameterDouble implements Name<Double> {
+  }
+
+  @NamedParameter
+  public static final class SetOfInstances implements Name<Set<SetInterface>> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/UnitClass.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/UnitClass.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/UnitClass.java
new file mode 100644
index 0000000..684a09f
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/UnitClass.java
@@ -0,0 +1,119 @@
+/**
+ * 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.reef.tang.test;
+
+import org.apache.reef.tang.annotations.Unit;
+
+import javax.inject.Inject;
+
+/**
+ * A test user for the @Unit annotation
+ */
+@Unit
+final class UnitClass {
+  private String stringValue;
+  private int intValue;
+
+  @Inject
+  UnitClass() {
+
+  }
+
+  public String getStringValue() {
+    return stringValue;
+  }
+
+  public int getIntValue() {
+    return intValue;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    UnitClass unitClass = (UnitClass) o;
+
+    if (intValue != unitClass.intValue) return false;
+    if (stringValue != null ? !stringValue.equals(unitClass.stringValue) : unitClass.stringValue != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = stringValue != null ? stringValue.hashCode() : 0;
+    result = 31 * result + intValue;
+    return result;
+  }
+
+  final class IntegerHandler implements Handler<Integer> {
+    final int foo = 42;
+
+    @Override
+    public void process(final Integer value) {
+      UnitClass.this.intValue = value;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+      if (this == o) return true;
+      if (o == null || getClass() != o.getClass()) return false;
+
+      IntegerHandler that = (IntegerHandler) o;
+
+      if (foo != that.foo) return false;
+
+      return true;
+    }
+
+    @Override
+    public int hashCode() {
+      return foo;
+    }
+  }
+
+  final class StringHandler implements Handler<String> {
+    final int bar = -42;
+
+    @Override
+    public void process(final String value) {
+      UnitClass.this.stringValue = value;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+      if (this == o) return true;
+      if (o == null || getClass() != o.getClass()) return false;
+
+      StringHandler that = (StringHandler) o;
+
+      if (bar != that.bar) return false;
+
+      return true;
+    }
+
+    @Override
+    public int hashCode() {
+      return bar;
+    }
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/package-info.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/package-info.java
new file mode 100644
index 0000000..5fb2159
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/test/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * This holds an integration test of most if not all of Tang's functionality.
+ */
+package org.apache.reef.tang.test;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/resources/Event.bin
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/resources/Event.bin b/lang/java/reef-tang/tang/src/test/resources/Event.bin
new file mode 100644
index 0000000..7f21ea6
Binary files /dev/null and b/lang/java/reef-tang/tang/src/test/resources/Event.bin differ

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/resources/Task.bin
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/resources/Task.bin b/lang/java/reef-tang/tang/src/test/resources/Task.bin
new file mode 100644
index 0000000..a71273e
Binary files /dev/null and b/lang/java/reef-tang/tang/src/test/resources/Task.bin differ

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/pom.xml b/lang/java/reef-tests/pom.xml
new file mode 100644
index 0000000..ee21633
--- /dev/null
+++ b/lang/java/reef-tests/pom.xml
@@ -0,0 +1,161 @@
+<?xml version="1.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.
+-->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+         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>
+    <artifactId>reef-tests</artifactId>
+    <name>REEF Tests</name>
+    <description>Integration tests for REEF</description>
+
+
+    <parent>
+        <groupId>org.apache.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-local</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-yarn</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-mesos</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-poison</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-examples</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-jdk14</artifactId>
+            <optional>true</optional>
+        </dependency>
+    </dependencies>
+
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <configuration>
+                    <descriptors>
+                        <descriptor>src/main/assembly/test-jar-with-dependencies.xml</descriptor>
+                    </descriptors>
+                </configuration>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>single</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+
+    <profiles>
+        <profile>
+            <id>test</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <configuration>
+                            <forkMode>pertest</forkMode>
+                            <!-- <useManifestOnlyJar>false</useManifestOnlyJar>
+                            <useSystemClassLoader>false</useSystemClassLoader> -->
+                            <systemPropertyVariables>
+                                <propertyName>java.util.logging.config.class</propertyName>
+                                <propertyValue>org.apache.reef.util.logging.Config</propertyValue>
+                            </systemPropertyVariables>
+                            <additionalClasspathElements>
+                                <additionalClasspathElement>${env.YARN_CONF_DIR}</additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/share/hadoop/common/lib/*
+                                </additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/share/hadoop/common/*
+                                </additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/contrib/capacity-scheduler/*.jar
+                                </additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/share/hadoop/hdfs
+                                </additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/share/hadoop/hdfs/lib/*
+                                </additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/share/hadoop/hdfs/*
+                                </additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/share/hadoop/yarn/lib/*
+                                </additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/share/hadoop/yarn/*
+                                </additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/share/hadoop/mapreduce/lib/*
+                                </additionalClasspathElement>
+                                <additionalClasspathElement>${env.YARN_HOME}/share/hadoop/mapreduce/*
+                                </additionalClasspathElement>
+                            </additionalClasspathElements>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/assembly/test-jar-with-dependencies.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/assembly/test-jar-with-dependencies.xml b/lang/java/reef-tests/src/main/assembly/test-jar-with-dependencies.xml
new file mode 100644
index 0000000..b0fb0a1
--- /dev/null
+++ b/lang/java/reef-tests/src/main/assembly/test-jar-with-dependencies.xml
@@ -0,0 +1,38 @@
+<!--
+
+    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.
+
+-->
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+    <id>test-jar-with-dependencies</id>
+    <formats>
+        <format>jar</format>
+    </formats>
+    <includeBaseDirectory>false</includeBaseDirectory>
+    <dependencySets>
+        <dependencySet>
+            <outputDirectory>/</outputDirectory>
+            <useProjectArtifact>true</useProjectArtifact>
+            <useProjectAttachments>true</useProjectAttachments>
+            <unpack>true</unpack>
+            <scope>test</scope>
+        </dependencySet>
+    </dependencySets>
+</assembly>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/TestDriverLauncher.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/TestDriverLauncher.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/TestDriverLauncher.java
new file mode 100644
index 0000000..96f3172
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/TestDriverLauncher.java
@@ -0,0 +1,132 @@
+/**
+ * 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.reef.tests;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.client.*;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A launcher for REEF Drivers. It behaves exactly like the original DriverLauncher,
+ * but does not dump the exception stack trace to the log. (it writes only a short INFO message).
+ * It is used in TestFailDriver etc. unit tests.
+ */
+@Public
+@Provided
+@ClientSide
+@Unit
+public final class TestDriverLauncher {
+
+  private static final Logger LOG = Logger.getLogger(TestDriverLauncher.class.getName());
+
+  private final DriverLauncher launcher;
+
+  @Inject
+  private TestDriverLauncher(final DriverLauncher launcher) {
+    this.launcher = launcher;
+  }
+
+  /**
+   * Instantiate a launcher for the given Configuration.
+   *
+   * @param runtimeConfiguration the resourcemanager configuration to be used
+   * @return a DriverLauncher based on the given resourcemanager configuration
+   * @throws org.apache.reef.tang.exceptions.BindException      on configuration errors
+   * @throws org.apache.reef.tang.exceptions.InjectionException on configuration errors
+   */
+  public static TestDriverLauncher getLauncher(
+      final Configuration runtimeConfiguration) throws BindException, InjectionException {
+
+    final Configuration clientConfiguration = ClientConfiguration.CONF
+        .set(ClientConfiguration.ON_JOB_RUNNING, DriverLauncher.RunningJobHandler.class)
+        .set(ClientConfiguration.ON_JOB_COMPLETED, DriverLauncher.CompletedJobHandler.class)
+        .set(ClientConfiguration.ON_RUNTIME_ERROR, SilentRuntimeErrorHandler.class)
+        .set(ClientConfiguration.ON_JOB_FAILED, SilentFailedTestJobHandler.class)
+        .build();
+
+    return Tang.Factory.getTang()
+        .newInjector(runtimeConfiguration, clientConfiguration)
+        .getInstance(TestDriverLauncher.class);
+  }
+
+  public void close() {
+    this.launcher.close();
+  }
+
+  /**
+   * Run a job. Waits indefinitely for the job to complete.
+   *
+   * @param driverConfig the configuration for the driver. See DriverConfiguration for details.
+   * @return the state of the job after execution.
+   */
+  public LauncherStatus run(final Configuration driverConfig) {
+    return this.launcher.run(driverConfig);
+  }
+
+  /**
+   * Run a job with a waiting timeout after which it will be killed, if it did not complete yet.
+   *
+   * @param driverConfig the configuration for the driver. See DriverConfiguration for details.
+   * @param timeOut      timeout on the job.
+   * @return the state of the job after execution.
+   */
+  public LauncherStatus run(final Configuration driverConfig, final long timeOut) {
+    return this.launcher.run(driverConfig, timeOut);
+  }
+
+  @Override
+  public String toString() {
+    return this.launcher.toString();
+  }
+
+  /**
+   * Handler an error in the job driver.
+   */
+  protected final class SilentRuntimeErrorHandler implements EventHandler<FailedRuntime> {
+    @Override
+    public void onNext(final FailedRuntime error) {
+      LOG.log(Level.INFO, "Received a runtime error: {0}", error);
+      launcher.setStatusAndNotify(LauncherStatus.FAILED(error.getReason()));
+    }
+  }
+
+  /**
+   * Job driver notifies us that the job had failed.
+   */
+  protected final class SilentFailedTestJobHandler implements EventHandler<FailedJob> {
+    @Override
+    public void onNext(final FailedJob job) {
+      final Optional<Throwable> ex = job.getReason();
+      LOG.log(Level.INFO, "Received an error for job {0}: {1}", new Object[]{job.getId(), ex});
+      launcher.setStatusAndNotify(LauncherStatus.FAILED(ex));
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/driver/DriverTestStartHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/driver/DriverTestStartHandler.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/driver/DriverTestStartHandler.java
new file mode 100644
index 0000000..1431fe2
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/driver/DriverTestStartHandler.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.tests.driver;
+
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A StartHandler that does nothing.
+ */
+final class DriverTestStartHandler implements EventHandler<StartTime> {
+  private static final Logger LOG = Logger.getLogger(DriverTestStartHandler.class.getName());
+
+
+  @Inject
+  DriverTestStartHandler() {
+  }
+
+  @Override
+  public void onNext(final StartTime startTime) {
+    LOG.log(Level.FINE, "StartTime: {0}", startTime);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/driver/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/driver/package-info.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/driver/package-info.java
new file mode 100644
index 0000000..37544a1
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/driver/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Tests whether a Driver can successfully be launched and shut down.
+ */
+package org.apache.reef.tests.driver;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/evaluatorreuse/EvaluatorReuseTestDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/evaluatorreuse/EvaluatorReuseTestDriver.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/evaluatorreuse/EvaluatorReuseTestDriver.java
new file mode 100644
index 0000000..b1be469
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/evaluatorreuse/EvaluatorReuseTestDriver.java
@@ -0,0 +1,118 @@
+/**
+ * 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.reef.tests.evaluatorreuse;
+
+import org.apache.reef.driver.client.JobMessageObserver;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.task.CompletedTask;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tests.library.exceptions.UnexpectedTaskReturnValue;
+import org.apache.reef.tests.library.tasks.EchoTask;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import javax.xml.bind.DatatypeConverter;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+final class EvaluatorReuseTestDriver {
+
+  private static final Logger LOG = Logger.getLogger(EvaluatorReuseTestDriver.class.getName());
+
+  private final int numberOfIterations;
+  private final JobMessageObserver client;
+
+  private int counter = 0;
+  private String lastMessage = null;
+
+  @Inject
+  EvaluatorReuseTestDriver(final @Parameter(NumberOfIterations.class) int n,
+                           final JobMessageObserver client) {
+    this.numberOfIterations = n;
+    this.client = client;
+  }
+
+  private void startTask(final ActiveContext context) {
+    if (counter < numberOfIterations) {
+      try {
+        this.lastMessage = "ECHO-" + counter;
+        client.sendMessageToClient(("Submitting iteration " + counter).getBytes());
+        final String memento = DatatypeConverter.printBase64Binary(this.lastMessage.getBytes());
+        context.submitTask(TaskConfiguration.CONF
+            .set(TaskConfiguration.IDENTIFIER, this.lastMessage)
+            .set(TaskConfiguration.TASK, EchoTask.class)
+            .set(TaskConfiguration.MEMENTO, memento)
+            .build());
+        counter += 1;
+      } catch (final BindException e) {
+        context.close();
+        throw new RuntimeException(e);
+      }
+    } else {
+      client.sendMessageToClient("Done. Closing the Context".getBytes());
+      context.close();
+    }
+  }
+
+  @NamedParameter(default_value = "3", short_name = "i")
+  class NumberOfIterations implements Name<Integer> {
+  }
+
+  final class TaskCompletedHandler implements EventHandler<CompletedTask> {
+    @Override
+    public void onNext(final CompletedTask completed) {
+      final String returned = new String(completed.get());
+      final String msg = "CompletedTask returned: \"" + returned + "\"";
+      client.sendMessageToClient(msg.getBytes());
+      if (!returned.equals(lastMessage)) {
+        throw new UnexpectedTaskReturnValue(lastMessage, returned);
+      } else {
+        startTask(completed.getActiveContext());
+      }
+    }
+  }
+
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator eb) {
+      LOG.log(Level.FINE, "AllocatedEvaluator: " + eb);
+      try {
+        eb.submitContext(ContextConfiguration.CONF
+            .set(ContextConfiguration.IDENTIFIER, "EvaluatorReuse").build());
+      } catch (BindException e) {
+        throw new RuntimeException(e);
+      }
+    }
+  }
+
+  final class ContextActiveHandler implements EventHandler<ActiveContext> {
+    @Override
+    public void onNext(final ActiveContext context) {
+      startTask(context);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/evaluatorreuse/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/evaluatorreuse/package-info.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/evaluatorreuse/package-info.java
new file mode 100644
index 0000000..fe021c1
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/evaluatorreuse/package-info.java
@@ -0,0 +1,23 @@
+/**
+ * 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.
+ */
+/**
+ * This package contains a test of the Evaluator reuse. It submits the EchoTask several times to the same Evaluator.
+ * This test also incidentially tests whether the memento is transferred correctly from and to the Task.
+ */
+package org.apache.reef.tests.evaluatorreuse;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/DriverFailOnFail.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/DriverFailOnFail.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/DriverFailOnFail.java
new file mode 100644
index 0000000..51883e1
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/DriverFailOnFail.java
@@ -0,0 +1,98 @@
+/**
+ * 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.reef.tests.fail.driver;
+
+import org.apache.reef.driver.client.JobMessageObserver;
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.driver.task.FailedTask;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tests.fail.task.FailTaskCall;
+import org.apache.reef.tests.library.exceptions.SimulatedDriverFailure;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+public final class DriverFailOnFail {
+
+  private static final Logger LOG = Logger.getLogger(DriverFailOnFail.class.getName());
+
+  private final transient JobMessageObserver client;
+  private final transient EvaluatorRequestor requestor;
+
+  @Inject
+  public DriverFailOnFail(final JobMessageObserver client, final EvaluatorRequestor requestor) {
+    this.client = client;
+    this.requestor = requestor;
+  }
+
+  public final class AllocatedEvaluatorHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator eval) {
+
+      try {
+
+        LOG.log(Level.INFO, "Submit task: Fail2");
+
+        final Configuration contextConfig = ContextConfiguration.CONF
+            .set(ContextConfiguration.IDENTIFIER, "Fail2")
+            .build();
+
+        final Configuration taskConfig = TaskConfiguration.CONF
+            .set(TaskConfiguration.IDENTIFIER, "Fail2")
+            .set(TaskConfiguration.TASK, FailTaskCall.class)
+            .build();
+
+        eval.submitContextAndTask(contextConfig, taskConfig);
+
+      } catch (final BindException ex) {
+        LOG.log(Level.WARNING, "Configuration error", ex);
+        throw new RuntimeException(ex);
+      }
+    }
+  }
+
+  public final class FailedTaskHandler implements EventHandler<FailedTask> {
+    @Override
+    public void onNext(final FailedTask task) throws SimulatedDriverFailure {
+      final SimulatedDriverFailure error = new SimulatedDriverFailure(
+          "Simulated Failure at DriverFailOnFail :: " + task.getClass().getName(), task.asError());
+      LOG.log(Level.INFO, "Simulated Failure: {0}", error);
+      throw error;
+    }
+  }
+
+  public final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime time) {
+      LOG.log(Level.INFO, "StartTime: {0}", time);
+      DriverFailOnFail.this.requestor.submit(EvaluatorRequest.newBuilder()
+          .setNumber(1).setMemory(128).setNumberOfCores(1).build());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailClient.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailClient.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailClient.java
new file mode 100644
index 0000000..1769e53
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailClient.java
@@ -0,0 +1,65 @@
+/**
+ * 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.reef.tests.fail.driver;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestDriverLauncher;
+import org.apache.reef.util.EnvironmentUtils;
+
+/**
+ * Client for the test REEF job that fails on different stages of execution.
+ */
+public final class FailClient {
+
+  public static LauncherStatus run(final Class<?> failMsgClass,
+                                   final Configuration runtimeConfig,
+                                   final int timeOut) throws BindException, InjectionException {
+
+    final Configuration driverConfig = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(FailDriver.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "Fail_" + failMsgClass.getSimpleName())
+        .set(DriverConfiguration.ON_DRIVER_STARTED, FailDriver.StartHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_STOP, FailDriver.StopHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, FailDriver.AllocatedEvaluatorHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_COMPLETED, FailDriver.CompletedEvaluatorHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_FAILED, FailDriver.FailedEvaluatorHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_ACTIVE, FailDriver.ActiveContextHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_MESSAGE, FailDriver.ContextMessageHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_CLOSED, FailDriver.ClosedContextHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_FAILED, FailDriver.FailedContextHandler.class)
+        .set(DriverConfiguration.ON_TASK_RUNNING, FailDriver.RunningTaskHandler.class)
+        .set(DriverConfiguration.ON_TASK_SUSPENDED, FailDriver.SuspendedTaskHandler.class)
+        .set(DriverConfiguration.ON_TASK_MESSAGE, FailDriver.TaskMessageHandler.class)
+        .set(DriverConfiguration.ON_TASK_FAILED, FailDriver.FailedTaskHandler.class)
+        .set(DriverConfiguration.ON_TASK_COMPLETED, FailDriver.CompletedTaskHandler.class)
+        .build();
+
+    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.addConfiguration(driverConfig);
+    cb.bindNamedParameter(FailDriver.FailMsgClassName.class, failMsgClass.getName());
+
+    return TestDriverLauncher.getLauncher(runtimeConfig).run(cb.build(), timeOut);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailDriver.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailDriver.java
new file mode 100644
index 0000000..15f70c7
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailDriver.java
@@ -0,0 +1,371 @@
+/**
+ * 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.reef.tests.fail.driver;
+
+import org.apache.reef.driver.context.*;
+import org.apache.reef.driver.evaluator.*;
+import org.apache.reef.driver.task.*;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.tests.library.exceptions.SimulatedDriverFailure;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.event.Alarm;
+import org.apache.reef.wake.time.event.StartTime;
+import org.apache.reef.wake.time.event.StopTime;
+
+import javax.inject.Inject;
+import javax.xml.bind.DatatypeConverter;
+import java.util.Arrays;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import static org.apache.reef.tests.fail.driver.FailDriver.ExpectedMessage.RequiredFlag.OPTIONAL;
+import static org.apache.reef.tests.fail.driver.FailDriver.ExpectedMessage.RequiredFlag.REQUIRED;
+
+@Unit
+public final class FailDriver {
+
+  private static final Logger LOG = Logger.getLogger(FailDriver.class.getName());
+  private static final ObjectSerializableCodec<String> CODEC = new ObjectSerializableCodec<>();
+  private static final byte[] HELLO_STR = CODEC.encode("MESSAGE::HELLO");
+  /**
+   * Send message to the Task MSG_DELAY milliseconds after start.
+   */
+  private static final int MSG_DELAY = 1000;
+  private static final ExpectedMessage[] EVENT_SEQUENCE = {
+      new ExpectedMessage(FailDriver.class, REQUIRED),
+      new ExpectedMessage(StartTime.class, REQUIRED),
+      new ExpectedMessage(AllocatedEvaluator.class, REQUIRED),
+      new ExpectedMessage(FailedEvaluator.class, OPTIONAL),
+      new ExpectedMessage(ActiveContext.class, REQUIRED),
+      new ExpectedMessage(ContextMessage.class, OPTIONAL),
+      new ExpectedMessage(FailedContext.class, OPTIONAL),
+      new ExpectedMessage(RunningTask.class, REQUIRED),
+      new ExpectedMessage(Alarm.class, REQUIRED),
+      new ExpectedMessage(TaskMessage.class, REQUIRED),
+      new ExpectedMessage(Alarm.class, REQUIRED),
+      new ExpectedMessage(SuspendedTask.class, REQUIRED),
+      new ExpectedMessage(RunningTask.class, REQUIRED),
+      new ExpectedMessage(Alarm.class, REQUIRED),
+      new ExpectedMessage(FailedTask.class, OPTIONAL),
+      new ExpectedMessage(CompletedTask.class, REQUIRED),
+      new ExpectedMessage(ClosedContext.class, OPTIONAL),
+      new ExpectedMessage(CompletedEvaluator.class, REQUIRED),
+      new ExpectedMessage(StopTime.class, REQUIRED)
+  };
+  private final transient Class<?> failMsgClass;
+  private final transient EvaluatorRequestor requestor;
+  private final transient Clock clock;
+  private transient RunningTask task = null;
+  private transient int expectIdx = 0;
+  private transient DriverState state = DriverState.INIT;
+
+  @Inject
+  public FailDriver(final @Parameter(FailMsgClassName.class) String failMsgClassName,
+                    final EvaluatorRequestor requestor, final Clock clock)
+      throws ClassNotFoundException {
+    this.failMsgClass = ClassLoader.getSystemClassLoader().loadClass(failMsgClassName);
+    this.requestor = requestor;
+    this.clock = clock;
+    this.checkMsgOrder(this);
+  }
+
+  /**
+   * Check if observer methods are called in the right order
+   * and generate an exception at the given point in the message sequence.
+   *
+   * @param msg a message from one of the observers.
+   * @throws SimulatedDriverFailure if failMsgClass matches the message class.
+   * @throws DriverSideFailure      if messages are out of order.
+   */
+  private void checkMsgOrder(final Object msg) throws SimulatedDriverFailure, DriverSideFailure {
+
+    final String msgClassName = msg.getClass().getName();
+    LOG.log(Level.FINE, "At {0} {1}:{2}", new Object[]{
+        this.state, this.expectIdx, msgClassName});
+
+    if (this.state == DriverState.FAILED) {
+      // If already failed, do not do anything
+      return;
+    }
+
+    // Simulate failure at this step?
+    if (this.failMsgClass.isInstance(msg)) {
+      this.state = DriverState.FAILED;
+    }
+
+    // Make sure events arrive in the right order (specified in EVENT_SEQUENCE):
+    boolean notFound = true;
+    for (; this.expectIdx < EVENT_SEQUENCE.length; ++this.expectIdx) {
+      if (EVENT_SEQUENCE[expectIdx].msgClass.isInstance(msg)) {
+        notFound = false;
+        break;
+      } else if (EVENT_SEQUENCE[expectIdx].requiredFlag == REQUIRED) {
+        break;
+      }
+    }
+
+    if (notFound) {
+      LOG.log(Level.SEVERE, "Event out of sequence: {0} {1}:{2}",
+          new Object[]{this.state, this.expectIdx, msgClassName});
+      throw new DriverSideFailure("Event out of sequence: " + msgClassName);
+    }
+
+    LOG.log(Level.INFO, "{0}: send: {1} got: {2}", new Object[]{
+        this.state, EVENT_SEQUENCE[this.expectIdx], msgClassName});
+
+    ++this.expectIdx;
+
+    if (this.state == DriverState.FAILED) {
+      final SimulatedDriverFailure ex = new SimulatedDriverFailure(
+          "Simulated Failure at FailDriver :: " + msgClassName);
+      LOG.log(Level.INFO, "Simulated Failure: {0}", ex);
+      throw ex;
+    }
+  }
+
+  private enum DriverState {INIT, SEND_MSG, SUSPEND, RESUME, CLOSE, FAILED}
+
+  /**
+   * Name of the message class to specify the failing message handler.
+   */
+  @NamedParameter(doc = "Full name of the message class to fail on", short_name = "fail")
+  public static final class FailMsgClassName implements Name<String> {
+  }
+
+  public static final class ExpectedMessage {
+
+    public final transient Class<?> msgClass;
+    public final transient RequiredFlag requiredFlag;
+    private final transient String repr;
+
+    public ExpectedMessage(final Class<?> clazz, final RequiredFlag requiredFlag) {
+      this.msgClass = clazz;
+      this.requiredFlag = requiredFlag;
+      this.repr = this.msgClass.getSimpleName() + ":" + this.requiredFlag;
+    }
+
+    @Override
+    public String toString() {
+      return this.repr;
+    }
+
+    public enum RequiredFlag {OPTIONAL, REQUIRED}
+  }
+
+  final class AllocatedEvaluatorHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator eval) {
+      checkMsgOrder(eval);
+      try {
+        eval.submitContext(ContextConfiguration.CONF
+            .set(ContextConfiguration.IDENTIFIER, "FailContext_" + eval.getId())
+            .build());
+      } catch (final BindException ex) {
+        LOG.log(Level.WARNING, "Context configuration error", ex);
+        throw new RuntimeException(ex);
+      }
+    }
+  }
+
+  final class CompletedEvaluatorHandler implements EventHandler<CompletedEvaluator> {
+    @Override
+    public void onNext(final CompletedEvaluator eval) {
+      checkMsgOrder(eval);
+      // noop
+    }
+  }
+
+  final class FailedEvaluatorHandler implements EventHandler<FailedEvaluator> {
+    @Override
+    public void onNext(final FailedEvaluator eval) {
+      LOG.log(Level.WARNING, "Evaluator failed: " + eval.getId(), eval.getEvaluatorException());
+      checkMsgOrder(eval);
+      throw new RuntimeException(eval.getEvaluatorException());
+    }
+  }
+
+  final class ActiveContextHandler implements EventHandler<ActiveContext> {
+    @Override
+    public void onNext(final ActiveContext context) {
+      checkMsgOrder(context);
+      try {
+        context.submitTask(TaskConfiguration.CONF
+            .set(TaskConfiguration.IDENTIFIER, "FailTask_" + context.getId())
+            .set(TaskConfiguration.TASK, NoopTask.class)
+            .set(TaskConfiguration.ON_MESSAGE, NoopTask.DriverMessageHandler.class)
+            .set(TaskConfiguration.ON_SUSPEND, NoopTask.TaskSuspendHandler.class)
+            .set(TaskConfiguration.ON_CLOSE, NoopTask.TaskCloseHandler.class)
+            .set(TaskConfiguration.ON_TASK_STOP, NoopTask.TaskStopHandler.class)
+            .set(TaskConfiguration.ON_SEND_MESSAGE, NoopTask.class)
+            .build());
+      } catch (final BindException ex) {
+        LOG.log(Level.WARNING, "Task configuration error", ex);
+        throw new RuntimeException(ex);
+      }
+    }
+  }
+
+  final class ContextMessageHandler implements EventHandler<ContextMessage> {
+    @Override
+    public void onNext(final ContextMessage message) {
+      checkMsgOrder(message);
+      // noop
+    }
+  }
+
+  final class ClosedContextHandler implements EventHandler<ClosedContext> {
+    @Override
+    public void onNext(final ClosedContext context) {
+      checkMsgOrder(context);
+      // noop
+    }
+  }
+
+  final class FailedContextHandler implements EventHandler<FailedContext> {
+    @Override
+    public void onNext(final FailedContext context) {
+      LOG.log(Level.WARNING, "Context failed: " + context.getId(), context.getReason().orElse(null));
+      checkMsgOrder(context);
+      // TODO: notify client?
+
+      // if (context.getParentContext().isPresent()) {
+      //   context.getParentContext().get().close();
+      // }
+    }
+  }
+
+  final class RunningTaskHandler implements EventHandler<RunningTask> {
+    @Override
+    public void onNext(final RunningTask task) {
+      checkMsgOrder(task);
+      FailDriver.this.task = task;
+      switch (state) {
+        case INIT:
+          state = DriverState.SEND_MSG;
+          break;
+        case RESUME:
+          state = DriverState.CLOSE;
+          break;
+        default:
+          LOG.log(Level.WARNING, "Unexpected state at TaskRuntime: {0}", state);
+          throw new DriverSideFailure("Unexpected state: " + state);
+      }
+      // After a delay, send message or suspend the task:
+      clock.scheduleAlarm(MSG_DELAY, new AlarmHandler());
+    }
+  }
+
+  final class SuspendedTaskHandler implements EventHandler<SuspendedTask> {
+    @Override
+    public void onNext(final SuspendedTask task) {
+      checkMsgOrder(task);
+      state = DriverState.RESUME;
+      try {
+        task.getActiveContext().submitTask(TaskConfiguration.CONF
+            .set(TaskConfiguration.IDENTIFIER, task.getId() + "_RESUMED")
+            .set(TaskConfiguration.TASK, NoopTask.class)
+            .set(TaskConfiguration.ON_MESSAGE, NoopTask.DriverMessageHandler.class)
+            .set(TaskConfiguration.ON_SUSPEND, NoopTask.TaskSuspendHandler.class)
+            .set(TaskConfiguration.ON_CLOSE, NoopTask.TaskCloseHandler.class)
+            .set(TaskConfiguration.ON_TASK_STOP, NoopTask.TaskStopHandler.class)
+            .set(TaskConfiguration.ON_SEND_MESSAGE, NoopTask.class)
+            .set(TaskConfiguration.MEMENTO, DatatypeConverter.printBase64Binary(HELLO_STR))
+            .build());
+      } catch (final BindException ex) {
+        LOG.log(Level.SEVERE, "Task configuration error", ex);
+        throw new DriverSideFailure("Task configuration error", ex);
+      }
+    }
+  }
+
+  final class TaskMessageHandler implements EventHandler<TaskMessage> {
+    @Override
+    public void onNext(final TaskMessage msg) {
+      checkMsgOrder(msg);
+      assert (Arrays.equals(HELLO_STR, msg.get()));
+      assert (state == DriverState.SEND_MSG);
+      state = DriverState.SUSPEND;
+      clock.scheduleAlarm(MSG_DELAY, new AlarmHandler());
+    }
+  }
+
+  final class FailedTaskHandler implements EventHandler<FailedTask> {
+    @Override
+    public void onNext(final FailedTask task) {
+      LOG.log(Level.WARNING, "Task failed: " + task.getId(), task.getReason().orElse(null));
+      checkMsgOrder(task);
+      if (task.getActiveContext().isPresent()) {
+        task.getActiveContext().get().close();
+      }
+    }
+  }
+
+  final class CompletedTaskHandler implements EventHandler<CompletedTask> {
+    @Override
+    public void onNext(final CompletedTask task) {
+      checkMsgOrder(task);
+      task.getActiveContext().close();
+    }
+  }
+
+  final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime time) {
+      FailDriver.this.checkMsgOrder(time);
+      FailDriver.this.requestor.submit(EvaluatorRequest.newBuilder()
+          .setNumber(1).setMemory(128).setNumberOfCores(1).build());
+    }
+  }
+
+  final class AlarmHandler implements EventHandler<Alarm> {
+    @Override
+    public void onNext(final Alarm time) {
+      FailDriver.this.checkMsgOrder(time);
+      switch (FailDriver.this.state) {
+        case SEND_MSG:
+          FailDriver.this.task.send(HELLO_STR);
+          break;
+        case SUSPEND:
+          FailDriver.this.task.suspend();
+          break;
+        case CLOSE:
+          FailDriver.this.task.close();
+          break;
+        default:
+          LOG.log(Level.WARNING, "Unexpected state at AlarmHandler: {0}", FailDriver.this.state);
+          throw new DriverSideFailure("Unexpected state: " + FailDriver.this.state);
+      }
+    }
+  }
+
+  final class StopHandler implements EventHandler<StopTime> {
+    @Override
+    public void onNext(final StopTime time) {
+      FailDriver.this.checkMsgOrder(time);
+      // noop
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailDriverDelayedMsg.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailDriverDelayedMsg.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailDriverDelayedMsg.java
new file mode 100644
index 0000000..332a4c9
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/FailDriverDelayedMsg.java
@@ -0,0 +1,128 @@
+/**
+ * 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.reef.tests.fail.driver;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.driver.task.RunningTask;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.driver.task.TaskMessage;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.event.Alarm;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.util.Arrays;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+public final class FailDriverDelayedMsg {
+
+  private static final Logger LOG = Logger.getLogger(FailDriverDelayedMsg.class.getName());
+  private static final ObjectSerializableCodec<String> CODEC = new ObjectSerializableCodec<>();
+  private static final byte[] HELLO_STR = CODEC.encode("MESSAGE::HELLO");
+
+  private final transient EvaluatorRequestor requestor;
+  private final transient Clock clock;
+  private transient RunningTask task = null;
+
+  @Inject
+  public FailDriverDelayedMsg(final EvaluatorRequestor requestor, final Clock clock) {
+    LOG.log(Level.INFO, "ENTER: FailDriverDelayedMsg.<init>");
+    this.requestor = requestor;
+    this.clock = clock;
+  }
+
+  public final class AllocatedEvaluatorHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator eval) {
+      LOG.log(Level.INFO, "ENTER: FailDriverDelayedMsg.send(AllocatedEvaluator): {0}", eval);
+      try {
+        eval.submitContext(ContextConfiguration.CONF
+            .set(ContextConfiguration.IDENTIFIER, "Context_" + eval.getId())
+            .build());
+      } catch (final BindException ex) {
+        LOG.log(Level.WARNING, "Context configuration error", ex);
+        throw new RuntimeException(ex);
+      }
+    }
+  }
+
+  public final class ActiveContextHandler implements EventHandler<ActiveContext> {
+    @Override
+    public void onNext(final ActiveContext context) {
+      LOG.log(Level.INFO, "ENTER: FailDriverDelayedMsg.send(ActiveContext): {0}", context);
+      try {
+        context.submitTask(TaskConfiguration.CONF
+            .set(TaskConfiguration.IDENTIFIER, "Task_" + context.getId())
+            .set(TaskConfiguration.TASK, NoopTask.class)
+            .set(TaskConfiguration.ON_MESSAGE, NoopTask.DriverMessageHandler.class)
+            .set(TaskConfiguration.ON_SUSPEND, NoopTask.TaskSuspendHandler.class)
+            .set(TaskConfiguration.ON_TASK_STOP, NoopTask.TaskStopHandler.class)
+            .set(TaskConfiguration.ON_CLOSE, NoopTask.TaskCloseHandler.class)
+            .set(TaskConfiguration.ON_SEND_MESSAGE, NoopTask.class)
+            .build());
+      } catch (final BindException ex) {
+        LOG.log(Level.WARNING, "Task configuration error", ex);
+        throw new RuntimeException(ex);
+      }
+    }
+  }
+
+  public final class RunningTaskHandler implements EventHandler<RunningTask> {
+    @Override
+    public void onNext(final RunningTask task) {
+      FailDriverDelayedMsg.this.task = task;
+      LOG.log(Level.INFO, "ENTER: FailDriverDelayedMsg.send(TaskRuntime): {0}", task);
+      FailDriverDelayedMsg.this.clock.scheduleAlarm(2000, new EventHandler<Alarm>() {
+        @Override
+        public void onNext(final Alarm time) {
+          LOG.log(Level.INFO, "ENTER: FailDriverDelayedMsg.send(Alarm): {0}", time);
+          task.send(HELLO_STR);
+        }
+      });
+    }
+  }
+
+  public final class TaskMessageHandler implements EventHandler<TaskMessage> {
+    @Override
+    public void onNext(final TaskMessage msg) {
+      LOG.log(Level.INFO, "ENTER: FailDriverDelayedMsg.send(TaskMessage): {0}", msg);
+      assert (Arrays.equals(HELLO_STR, msg.get()));
+      FailDriverDelayedMsg.this.task.close();
+    }
+  }
+
+  public final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime time) {
+      LOG.log(Level.INFO, "ENTER: FailDriverDelayedMsg.send(StartTime): {0}", time);
+      FailDriverDelayedMsg.this.requestor.submit(EvaluatorRequest.newBuilder()
+          .setNumber(1).setMemory(128).setNumberOfCores(1).build());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/NoopTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/NoopTask.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/NoopTask.java
new file mode 100644
index 0000000..7250004
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/fail/driver/NoopTask.java
@@ -0,0 +1,117 @@
+/**
+ * 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.reef.tests.fail.driver;
+
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.task.Task;
+import org.apache.reef.task.TaskMessage;
+import org.apache.reef.task.TaskMessageSource;
+import org.apache.reef.task.events.CloseEvent;
+import org.apache.reef.task.events.DriverMessage;
+import org.apache.reef.task.events.SuspendEvent;
+import org.apache.reef.task.events.TaskStop;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A basic task that quite successfully does nothing.
+ */
+@Unit
+public final class NoopTask implements Task, TaskMessageSource {
+
+  private static final Logger LOG = Logger.getLogger(NoopTask.class.getName());
+  private static final ObjectSerializableCodec<String> CODEC = new ObjectSerializableCodec<>();
+  private static final TaskMessage INIT_MESSAGE = TaskMessage.from("", CODEC.encode("MESSAGE::INIT"));
+  private transient boolean isRunning = true;
+  private transient Optional<TaskMessage> message = Optional.empty();
+
+  @Inject
+  public NoopTask() {
+    LOG.info("NoopTask created.");
+  }
+
+  @Override
+  public synchronized byte[] call(final byte[] memento) {
+    this.isRunning = true;
+    while (this.isRunning) {
+      try {
+        LOG.info("NoopTask.call(): Waiting for the message.");
+        this.wait();
+      } catch (final InterruptedException ex) {
+        LOG.log(Level.WARNING, "NoopTask.wait() interrupted.", ex);
+      }
+    }
+    LOG.log(Level.INFO, "NoopTask.call(): Exiting with message {0}",
+        CODEC.decode(this.message.orElse(INIT_MESSAGE).get()));
+    return this.message.orElse(INIT_MESSAGE).get();
+  }
+
+  @Override
+  public synchronized Optional<TaskMessage> getMessage() {
+    LOG.log(Level.INFO, "NoopTask.getMessage() invoked: {0}",
+        CODEC.decode(this.message.orElse(INIT_MESSAGE).get()));
+    return this.message;
+  }
+
+  private synchronized void stopTask() {
+    LOG.info("NoopTask.stopTask() invoked.");
+    this.isRunning = false;
+    this.notify();
+  }
+
+  public class TaskSuspendHandler implements EventHandler<SuspendEvent> {
+    @Override
+    public void onNext(final SuspendEvent suspendEvent) {
+      LOG.info("NoopTask.TaskSuspendHandler.send() invoked.");
+      NoopTask.this.stopTask();
+    }
+  }
+
+  public class TaskStopHandler implements EventHandler<TaskStop> {
+    @Override
+    public void onNext(final TaskStop event) {
+      LOG.info("NoopTask.TaskStopHandler.send() invoked.");
+      NoopTask.this.stopTask();
+    }
+  }
+
+  public class TaskCloseHandler implements EventHandler<CloseEvent> {
+    @Override
+    public void onNext(final CloseEvent closeEvent) {
+      LOG.info("NoopTask.TaskCloseHandler.send() invoked.");
+      NoopTask.this.stopTask();
+    }
+  }
+
+  public class DriverMessageHandler implements EventHandler<DriverMessage> {
+    @Override
+    public void onNext(DriverMessage driverMessage) {
+      final byte[] msg = driverMessage.get().get();
+      LOG.log(Level.INFO, "NoopTask.DriverMessageHandler.send() invoked: {0}", CODEC.decode(msg));
+      synchronized (NoopTask.this) {
+        NoopTask.this.message = Optional.of(TaskMessage.from(NoopTask.this.toString(), msg));
+      }
+    }
+  }
+}


[49/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/AssemblyInfo.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/AssemblyInfo.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/AssemblyInfo.cpp
new file mode 100644
index 0000000..f6c3178
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/AssemblyInfo.cpp
@@ -0,0 +1,50 @@
+/**
+ * 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 namespace System;
+using namespace System::Reflection;
+using namespace System::Runtime::CompilerServices;
+using namespace System::Runtime::InteropServices;
+using namespace System::Security::Permissions;
+
+//
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+//
+[assembly:AssemblyTitleAttribute("JavaClrBridge")];
+[assembly:AssemblyProductAttribute("JavaClrBridge")];
+[assembly:AssemblyCopyrightAttribute("Copyright (c)  2014")];
+//
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version
+//      Build Number
+//      Revision
+//
+// You can specify all the value or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+
+[assembly:AssemblyVersionAttribute("1.0.*")];
+
+[assembly:ComVisible(false)];
+
+[assembly:CLSCompliantAttribute(true)];
+
+[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/AssemblyUtil.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/AssemblyUtil.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/AssemblyUtil.cpp
new file mode 100644
index 0000000..ce9239c
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/AssemblyUtil.cpp
@@ -0,0 +1,53 @@
+/**
+ * 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.
+ */
+#include "InteropAssemblies.h"
+
+
+void AssemblyUtil::Add(Assembly^  myasm) {
+  if (0 == _asmCount) {
+    //asm1 = myasm;
+    AppDomain^ currentDomain = AppDomain::CurrentDomain;
+    currentDomain->AssemblyResolve += gcnew ResolveEventHandler(&MyResolveEventHandler);
+  }
+  String^ asmName = myasm->FullName->ToLower();
+  Assembly^ existingAsm = nullptr;
+  if (!asms2->TryGetValue(asmName, existingAsm)) {
+    Console::WriteLine ("AssemblyUtil:: Adding " + asmName);
+    asms2->Add(asmName , myasm);
+    ++_asmCount;
+  }
+}
+
+Assembly^ AssemblyUtil::FindAsm (String^ myasm) {
+  Assembly^ returnAsm = nullptr;
+  if (!asms2->TryGetValue(myasm->ToLower(), returnAsm)) {
+    Console::WriteLine ("AssemblyUtil:: FindAsm_Not_Found " + myasm->ToString());
+  }
+  return returnAsm;
+}
+
+Assembly^ AssemblyUtil::MyResolveEventHandler(Object^ sender, ResolveEventArgs^ args) {
+  Console::WriteLine ("AssemblyUtil:: Resolving " + args->Name);
+  Assembly^ myAsm = AssemblyUtil::FindAsm(args->Name);
+  if (nullptr != myAsm) {
+    Console::WriteLine ("AssemblyUtil:: Found " + args->Name);
+  }
+  return myAsm ;
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/BinaryUtil.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/BinaryUtil.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/BinaryUtil.cpp
new file mode 100644
index 0000000..b7c3a2e
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/BinaryUtil.cpp
@@ -0,0 +1,102 @@
+/**
+ * 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.
+ */
+#include "InteropUtil.h"
+#include "BinaryUtil.h"
+
+DWORD GetActualAddressFromRVA(IMAGE_SECTION_HEADER* pSectionHeader, IMAGE_NT_HEADERS* pNTHeaders, DWORD dwRVA) {
+  DWORD dwRet = 0;
+
+  for (int j = 0; j < pNTHeaders->FileHeader.NumberOfSections; j++, pSectionHeader++) {
+    DWORD cbMaxOnDisk = min( pSectionHeader->Misc.VirtualSize, pSectionHeader->SizeOfRawData );
+
+    DWORD startSectRVA, endSectRVA;
+
+    startSectRVA = pSectionHeader->VirtualAddress;
+    endSectRVA = startSectRVA + cbMaxOnDisk;
+
+    if ( (dwRVA >= startSectRVA) && (dwRVA < endSectRVA)) {
+      dwRet =  (pSectionHeader->PointerToRawData ) + (dwRVA - startSectRVA);
+      break;
+    }
+
+  }
+
+  return dwRet;
+}
+
+
+BINARY_TYPE IsManagedBinary(const wchar_t*  lpszImageName) {
+  BINARY_TYPE binaryType = BINARY_TYPE_NONE;
+  HANDLE hFile = CreateFile(lpszImageName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+
+  if (INVALID_HANDLE_VALUE != hFile) {
+    //succeeded
+    HANDLE hOpenFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
+    if (hOpenFileMapping) {
+      BYTE* lpBaseAddress = NULL;
+
+      lpBaseAddress = (BYTE*)MapViewOfFile(hOpenFileMapping, FILE_MAP_READ, 0, 0, 0);
+
+      if (lpBaseAddress) {
+        //having mapped the executable to our process space, now start navigating through the sections
+
+        //DOS header is straightforward. It is the topmost structure in the PE file
+        //i.e. the one at the lowest offset into the file
+        IMAGE_DOS_HEADER* pDOSHeader = (IMAGE_DOS_HEADER*)lpBaseAddress;
+
+        //the only important data in the DOS header is the e_lfanew
+        //the e_lfanew points to the offset of the beginning of NT Headers data
+        IMAGE_NT_HEADERS* pNTHeaders = (IMAGE_NT_HEADERS*)((BYTE*)pDOSHeader + pDOSHeader->e_lfanew);
+
+        IMAGE_SECTION_HEADER* pSectionHeader = (IMAGE_SECTION_HEADER*)((BYTE*)pNTHeaders + sizeof(IMAGE_NT_HEADERS));
+
+        //Now, start parsing
+        //check if it is a PE file
+
+        if (pNTHeaders->Signature == IMAGE_NT_SIGNATURE) {
+          //start parsing COM table
+
+          DWORD dwNETHeaderTableLocation = pNTHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR].VirtualAddress;
+
+          if (dwNETHeaderTableLocation) {
+            //import data does exist for this module
+            IMAGE_COR20_HEADER* pNETHeader = (IMAGE_COR20_HEADER*)((BYTE*)pDOSHeader + GetActualAddressFromRVA(pSectionHeader, pNTHeaders, dwNETHeaderTableLocation));
+
+            if (pNETHeader) {
+              binaryType = BINARY_TYPE_CLR;
+            }
+            else {
+              binaryType = BINARY_TYPE_NATIVE;
+            }
+          }
+          else {
+            binaryType = BINARY_TYPE_NATIVE;
+          }
+        }
+        else {
+          binaryType = BINARY_TYPE_NONE;
+        }
+        UnmapViewOfFile(lpBaseAddress);
+      }
+      CloseHandle(hOpenFileMapping);
+    }
+    CloseHandle(hFile);
+  }
+  return binaryType;
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/BinaryUtil.h
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/BinaryUtil.h b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/BinaryUtil.h
new file mode 100644
index 0000000..dc946a6
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/BinaryUtil.h
@@ -0,0 +1,26 @@
+/**
+ * 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.
+ */
+typedef enum BINARY_TYPE {
+  BINARY_TYPE_NONE = 0,
+  BINARY_TYPE_NATIVE = 1,
+  BINARY_TYPE_CLR = 2,
+} BINARY_TYPE ;
+
+
+BINARY_TYPE IsManagedBinary(const wchar_t* lpszImageName);

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ClosedContextClr2Java.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ClosedContextClr2Java.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ClosedContextClr2Java.cpp
new file mode 100644
index 0000000..d87d17a
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ClosedContextClr2Java.cpp
@@ -0,0 +1,86 @@
+/**
+ * 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.
+ */
+#include "Clr2JavaImpl.h"
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Driver {
+      namespace Bridge {
+        ref class ManagedLog {
+          internal:
+            static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>");
+        };
+        ClosedContextClr2Java::ClosedContextClr2Java(JNIEnv *env, jobject jobjectClosedContext) {
+          ManagedLog::LOGGER->LogStart("ClosedContextClr2Java::ClosedContextClr2Java");
+
+          pin_ptr<JavaVM*> pJavaVm = &_jvm;
+          if (env->GetJavaVM(pJavaVm) != 0) {
+            ManagedLog::LOGGER->LogError("Failed to get JavaVM", nullptr);
+          }
+          _jobjectClosedContext = reinterpret_cast<jobject>(env->NewGlobalRef(jobjectClosedContext));
+          jclass jclassClosedContext = env->GetObjectClass (_jobjectClosedContext);
+
+          jfieldID jidContextId = env->GetFieldID(jclassClosedContext, "contextId", "Ljava/lang/String;");
+          jfieldID jidEvaluatorId = env->GetFieldID(jclassClosedContext, "evaluatorId", "Ljava/lang/String;");
+
+          _jstringContextId = reinterpret_cast<jstring>(env->NewGlobalRef(env->GetObjectField(_jobjectClosedContext, jidContextId)));
+          _jstringEvaluatorId = reinterpret_cast<jstring>(env->NewGlobalRef(env->GetObjectField(_jobjectClosedContext, jidEvaluatorId)));
+
+          ManagedLog::LOGGER->LogStop("ClosedContextClr2Java::ClosedContextClr2Java");
+        }
+
+        IActiveContextClr2Java^ ClosedContextClr2Java::GetParentContext() {
+          ManagedLog::LOGGER->LogStart("ClosedContextClr2Java::GetParentContext");
+
+          JNIEnv *env = RetrieveEnv(_jvm);
+
+          jclass jclassClosedContext = env->GetObjectClass(_jobjectClosedContext);
+          jfieldID jidParentContext = env->GetFieldID(jclassClosedContext, "parentContext", "Lorg/apache/reef/javabridge/ActiveContextBridge;");
+          jobject jobjectParentContext = env->GetObjectField(_jobjectClosedContext, jidParentContext);
+          ManagedLog::LOGGER->LogStop("ClosedContextClr2Java::GetParentContext");
+
+          return gcnew ActiveContextClr2Java(env, jobjectParentContext);
+        }
+
+        String^ ClosedContextClr2Java::GetId() {
+          ManagedLog::LOGGER->Log("ClosedContextClr2Java::GetId");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          return ManagedStringFromJavaString(env, _jstringContextId);
+        }
+
+        String^ ClosedContextClr2Java::GetEvaluatorId() {
+          ManagedLog::LOGGER->Log("ClosedContextClr2Java::GetEvaluatorId");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          return ManagedStringFromJavaString(env, _jstringEvaluatorId);
+        }
+
+        IEvaluatorDescriptor^ ClosedContextClr2Java::GetEvaluatorDescriptor() {
+          ManagedLog::LOGGER->LogStart("ClosedContextClr2Java::GetEvaluatorDescriptor");
+          return CommonUtilities::RetrieveEvaluatorDescriptor(_jobjectClosedContext, _jvm);
+        }
+
+        void ClosedContextClr2Java::OnError(String^ message) {
+          ManagedLog::LOGGER->Log("ClosedContextClr2Java::OnError");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          HandleClr2JavaError(env, message, _jobjectClosedContext);
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/Clr2JavaImpl.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/Clr2JavaImpl.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/Clr2JavaImpl.cpp
new file mode 100644
index 0000000..ebd1aa4
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/Clr2JavaImpl.cpp
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+#include "Clr2JavaImpl.h"
+
+namespace Microsoft
+{
+	namespace Reef
+	{
+		namespace Interop
+		{
+			Clr2JavaImpl::Clr2JavaImpl (JNIEnv* env, jobject  jobjectEManager, jobject  jobjectDriverManager)
+			{
+				_env = env;
+				_jobjectEManager = jobjectEManager;
+				_jclassEManager =  env->GetObjectClass (_jobjectEManager);
+				_jmidSubmit = env->GetMethodID(_jclassEManager, "submit", "([B)V");	
+				_jobjectDriverManager = jobjectDriverManager;
+				_jclassDriverManager = env->GetObjectClass (_jobjectDriverManager);
+
+			}
+
+			void Clr2JavaImpl::AllocatedEvaluatorSubmitContextAndTask(String^ contextConfigStr, String^ taskConfigStr)
+			{
+				Console::WriteLine("AllocatedEvaluatorSubmitContextAndTask not implemented for Clr2JavaImpl");
+			}
+		}
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/Clr2JavaImpl.h
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/Clr2JavaImpl.h b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/Clr2JavaImpl.h
new file mode 100644
index 0000000..b907c2a
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/Clr2JavaImpl.h
@@ -0,0 +1,220 @@
+/**
+ * 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.
+ */
+#include "InteropUtil.h"
+#include "org_apache_reef_javabridge_NativeInterop.h"
+#include "JavaClrBridge.h"
+#include "InteropAssemblies.h"
+#using "clrhandler.dll"
+#using "Microsoft.Reef.Driver.dll"
+
+using namespace System;
+using namespace System::IO;
+using namespace System::Collections::Generic;
+using namespace System::Runtime::InteropServices;
+using namespace System::Reflection;
+using namespace Microsoft::Reef::Driver::Bridge;
+using namespace Microsoft::Reef::Driver::Evaluator;
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Driver {
+      namespace Bridge {
+        public ref class CommonUtilities {
+          public:
+            static IEvaluatorDescriptor^ RetrieveEvaluatorDescriptor(jobject object, JavaVM* jvm);
+        };
+
+        public ref class AllocatedEvaluatorClr2Java : public IAllocatedEvaluaotrClr2Java {
+            jobject  _jobjectAllocatedEvaluator;
+            JavaVM* _jvm;
+            jstring _jstringId;
+            jstring _jstringNameServerInfo;
+          public:
+            AllocatedEvaluatorClr2Java(JNIEnv *env, jobject jallocatedEvaluator);
+            virtual void SubmitContextAndTask(String^ contextConfigStr, String^ taskConfigStr);
+            virtual void SubmitContext(String^ contextConfigStr);
+            virtual void SubmitContextAndService(String^ contextConfigStr, String^ serviceConfigStr);
+            virtual void SubmitContextAndServiceAndTask(String^ contextConfigStr, String^ serviceConfigStr, String^ taskConfigStr);
+            virtual void OnError(String^ message);
+            virtual void Close();
+            virtual String^ GetId();
+            virtual String^ GetNameServerInfo();
+            virtual IEvaluatorDescriptor^ GetEvaluatorDescriptor();
+        };
+
+        public ref class ActiveContextClr2Java : public IActiveContextClr2Java {
+            jobject _jobjectActiveContext;
+            jstring _jstringId;
+            jstring _jstringEvaluatorId;
+            JavaVM* _jvm;
+          public:
+            ActiveContextClr2Java(JNIEnv *env, jobject jallocatedEvaluator);
+            virtual void SubmitTask(String^ taskConfigStr);
+            virtual void Close();
+            virtual void OnError(String^ message);
+            virtual String^ GetId();
+            virtual String^ GetEvaluatorId();
+            virtual IEvaluatorDescriptor^ GetEvaluatorDescriptor();
+        };
+
+        public ref class EvaluatorRequestorClr2Java : public IEvaluatorRequestorClr2Java {
+            jobject  _jobjectEvaluatorRequestor;
+            JavaVM* _jvm;
+          public:
+            EvaluatorRequestorClr2Java(JNIEnv *env, jobject jevaluatorRequestor);
+            virtual void OnError(String^ message);
+            virtual void Submit(IEvaluatorRequest^ request);
+        };
+
+        public ref class TaskMessageClr2Java : public ITaskMessageClr2Java {
+            jobject  _jobjectTaskMessage;
+            JavaVM* _jvm;
+            jstring _jstringId;
+          public:
+            TaskMessageClr2Java(JNIEnv *env, jobject jtaskMessage);
+            virtual void OnError(String^ message);
+            virtual String^ GetId();
+        };
+
+        public ref class FailedTaskClr2Java : public IFailedTaskClr2Java {
+            jobject  _jobjectFailedTask;
+            JavaVM* _jvm;
+          public:
+            FailedTaskClr2Java(JNIEnv *env, jobject jfailedTask);
+            virtual void OnError(String^ message);
+            virtual IActiveContextClr2Java^ GetActiveContext();
+            virtual String^ GetString();
+        };
+
+        public ref class RunningTaskClr2Java : public IRunningTaskClr2Java {
+            jobject  _jobjectRunningTask;
+            JavaVM* _jvm;
+            jstring _jstringId;
+          public:
+            RunningTaskClr2Java(JNIEnv *env, jobject jrunningTask);
+            virtual void OnError(String^ message);
+            virtual IActiveContextClr2Java^ GetActiveContext();
+            virtual String^ GetId();
+            virtual void Send(array<byte>^ message);
+        };
+
+        public ref class FailedEvaluatorClr2Java : public IFailedEvaluatorClr2Java {
+            jobject  _jobjectFailedEvaluator;
+            JavaVM* _jvm;
+            jstring _jstringId;
+          public:
+            FailedEvaluatorClr2Java(JNIEnv *env, jobject jfailedEvaluator);
+            virtual void OnError(String^ message);
+            virtual IEvaluatorRequestorClr2Java^ GetEvaluatorRequestor();
+            virtual String^ GetId();
+        };
+
+        public ref class HttpServerClr2Java : public IHttpServerBridgeClr2Java {
+            jobject _jhttpServerEventBridge;
+            JavaVM* _jvm;
+          public:
+            HttpServerClr2Java(JNIEnv *env, jobject jhttpServerEventBridge);
+            virtual void OnError(String^ message);
+            virtual String^ GetQueryString();
+            virtual void SetUriSpecification(String^ uriSpecification);
+            virtual void SetQueryResult(String^ queryResult);
+            virtual array<byte>^ GetQueryRequestData();
+            virtual void SetQueryResponseData(array<byte>^ responseData);
+        };
+
+        public ref class CompletedTaskClr2Java : public ICompletedTaskClr2Java {
+            jobject  _jobjectCompletedTask;
+            JavaVM* _jvm;
+            jstring _jstringId;
+          public:
+            CompletedTaskClr2Java(JNIEnv *env, jobject jcompletedTask);
+            virtual void OnError(String^ message);
+            virtual IActiveContextClr2Java^ GetActiveContext();
+            virtual String^ GetId();
+        };
+
+        public ref class SuspendedTaskClr2Java : public ISuspendedTaskClr2Java {
+            jobject  _jobjectSuspendedTask;
+            JavaVM* _jvm;
+            jstring _jstringId;
+          public:
+            SuspendedTaskClr2Java(JNIEnv *env, jobject jobjectSuspendedTask);
+            virtual void OnError(String^ message);
+            virtual IActiveContextClr2Java^ GetActiveContext();
+            virtual String^ GetId();
+            virtual array<byte>^ Get();
+        };
+
+        public ref class CompletedEvaluatorClr2Java : public ICompletedEvaluatorClr2Java {
+            jobject  _jobjectCompletedEvaluator;
+            JavaVM* _jvm;
+            jstring _jstringId;
+          public:
+            CompletedEvaluatorClr2Java(JNIEnv *env, jobject jobjectCompletedEvaluator);
+            virtual void OnError(String^ message);
+            virtual String^ GetId();
+        };
+
+        public ref class ClosedContextClr2Java : public IClosedContextClr2Java {
+            jobject  _jobjectClosedContext;
+            JavaVM* _jvm;
+            jstring _jstringContextId;
+            jstring _jstringEvaluatorId;
+          public:
+            ClosedContextClr2Java(JNIEnv *env, jobject jobjectClosedContext);
+            virtual void OnError(String^ message);
+            virtual String^ GetId();
+            virtual String^ GetEvaluatorId();
+            virtual IEvaluatorDescriptor^ GetEvaluatorDescriptor();
+            virtual IActiveContextClr2Java^ GetParentContext();
+        };
+
+        public ref class FailedContextClr2Java : public IFailedContextClr2Java {
+            jobject  _jobjectFailedContext;
+            JavaVM* _jvm;
+            jstring _jstringContextId;
+            jstring _jstringEvaluatorId;
+            jstring _jstringParentContextId;
+          public:
+            FailedContextClr2Java(JNIEnv *env, jobject jobjectFailedContext);
+            virtual void OnError(String^ message);
+            virtual String^ GetId();
+            virtual String^ GetEvaluatorId();
+            virtual String^ GetParentId();
+            virtual IEvaluatorDescriptor^ GetEvaluatorDescriptor();
+            virtual IActiveContextClr2Java^ GetParentContext();
+        };
+
+        public ref class ContextMessageClr2Java : public IContextMessageClr2Java {
+            jobject  _jobjectContextMessage;
+            JavaVM* _jvm;
+            jbyteArray _jarrayMessage;
+            jstring _jstringId;
+            jstring _jstringSourceId;
+          public:
+            ContextMessageClr2Java(JNIEnv *env, jobject jobjectContextMessage);
+            virtual void OnError(String^ message);
+            virtual array<byte>^ Get();
+            virtual String^ GetId();
+            virtual String^ GetMessageSourceId();
+        };
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/CommonUtilities.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/CommonUtilities.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/CommonUtilities.cpp
new file mode 100644
index 0000000..c9b6cf1
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/CommonUtilities.cpp
@@ -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.
+ */
+#include "Clr2JavaImpl.h"
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Driver {
+      namespace Bridge {
+        ref class ManagedLog {
+          internal:
+            static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>CommonUtilities");
+        };
+
+        IEvaluatorDescriptor^ CommonUtilities::RetrieveEvaluatorDescriptor(jobject object, JavaVM* jvm) {
+          ManagedLog::LOGGER->LogStart("CommonUtilities::GetEvaluatorDescriptor");
+          JNIEnv *env = RetrieveEnv(jvm);
+          jclass jclassActiveContext = env->GetObjectClass (object);
+          jmethodID jmidGetEvaluatorDescriptor = env->GetMethodID(jclassActiveContext, "getEvaluatorDescriptorSring", "()Ljava/lang/String;");
+
+          if (jmidGetEvaluatorDescriptor == NULL) {
+            ManagedLog::LOGGER->Log("jmidGetEvaluatorDescriptor is NULL");
+            return nullptr;
+          }
+          jstring jevaluatorDescriptorString = (jstring)env -> CallObjectMethod(
+                                                 object,
+                                                 jmidGetEvaluatorDescriptor);
+          String^ evaluatorDescriptorString = ManagedStringFromJavaString(env, jevaluatorDescriptorString);
+          ManagedLog::LOGGER->LogStop("InteropUtil::GetEvaluatorDescriptor");
+
+          return gcnew EvaluatorDescriptorImpl(evaluatorDescriptorString);
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/CompletedEvaluatorClr2Java.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/CompletedEvaluatorClr2Java.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/CompletedEvaluatorClr2Java.cpp
new file mode 100644
index 0000000..296670e
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/CompletedEvaluatorClr2Java.cpp
@@ -0,0 +1,58 @@
+/**
+ * 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.
+ */
+#include "Clr2JavaImpl.h"
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Driver {
+      namespace Bridge {
+        ref class ManagedLog {
+          internal:
+            static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>");
+        };
+
+        CompletedEvaluatorClr2Java::CompletedEvaluatorClr2Java(JNIEnv *env, jobject jCompletedEvaluator) {
+          ManagedLog::LOGGER->LogStart("CompletedEvaluatorClr2Java::CompletedEvaluatorClr2Java");
+          pin_ptr<JavaVM*> pJavaVm = &_jvm;
+          if (env->GetJavaVM(pJavaVm) != 0) {
+            ManagedLog::LOGGER->LogError("Failed to get JavaVM", nullptr);
+          }
+          _jobjectCompletedEvaluator = reinterpret_cast<jobject>(env->NewGlobalRef(jCompletedEvaluator));
+
+          jclass jclassCompletedEvaluator = env->GetObjectClass (_jobjectCompletedEvaluator);
+          jfieldID jidEvaluatorId = env->GetFieldID(jclassCompletedEvaluator, "evaluatorId", "Ljava/lang/String;");
+          _jstringId = reinterpret_cast<jstring>(env->NewGlobalRef(env->GetObjectField(_jobjectCompletedEvaluator, jidEvaluatorId)));
+          ManagedLog::LOGGER->LogStop("CompletedEvaluatorClr2Java::CompletedEvaluatorClr2Java");
+        }
+
+        void CompletedEvaluatorClr2Java::OnError(String^ message) {
+          ManagedLog::LOGGER->Log("CompletedEvaluatorClr2Java::OnError");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          HandleClr2JavaError(env, message, _jobjectCompletedEvaluator);
+        }
+
+        String^ CompletedEvaluatorClr2Java::GetId() {
+          ManagedLog::LOGGER->Log("CompletedEvaluatorClr2Java::GetId");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          return ManagedStringFromJavaString(env, _jstringId);
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/CompletedTaskClr2Java.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/CompletedTaskClr2Java.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/CompletedTaskClr2Java.cpp
new file mode 100644
index 0000000..631b2ea
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/CompletedTaskClr2Java.cpp
@@ -0,0 +1,69 @@
+/**
+ * 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.
+ */
+#include "Clr2JavaImpl.h"
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Driver {
+      namespace Bridge {
+        ref class ManagedLog {
+          internal:
+            static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>");
+        };
+
+        CompletedTaskClr2Java::CompletedTaskClr2Java(JNIEnv *env, jobject jobjectCompletedTask) {
+          ManagedLog::LOGGER->LogStart("CompletedTaskClr2Java::CompletedTaskClr2Java");
+          pin_ptr<JavaVM*> pJavaVm = &_jvm;
+          if (env->GetJavaVM(pJavaVm) != 0) {
+            ManagedLog::LOGGER->LogError("Failed to get JavaVM", nullptr);
+          }
+          _jobjectCompletedTask = reinterpret_cast<jobject>(env->NewGlobalRef(jobjectCompletedTask));
+
+          jclass jclassCompletedTask = env->GetObjectClass (_jobjectCompletedTask);
+          jfieldID jidTaskId = env->GetFieldID(jclassCompletedTask, "taskId", "Ljava/lang/String;");
+          _jstringId = reinterpret_cast<jstring>(env->NewGlobalRef(env->GetObjectField(_jobjectCompletedTask, jidTaskId)));
+          ManagedLog::LOGGER->LogStop("CompletedTaskClr2Java::CompletedTaskClr2Java");
+        }
+
+        void CompletedTaskClr2Java::OnError(String^ message) {
+          ManagedLog::LOGGER->Log("CompletedTaskClr2Java::OnError");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          HandleClr2JavaError(env, message, _jobjectCompletedTask);
+        }
+
+        IActiveContextClr2Java^ CompletedTaskClr2Java::GetActiveContext() {
+          ManagedLog::LOGGER->LogStart("CompletedTaskClr2Java::GetActiveContext");
+          JNIEnv *env = RetrieveEnv(_jvm);
+
+          jclass jclassCompletedTask = env->GetObjectClass (_jobjectCompletedTask);
+          jfieldID jidActiveContext = env->GetFieldID(jclassCompletedTask, "jactiveContext", "Lorg/apache/reef/javabridge/ActiveContextBridge;");
+          jobject jobjectActiveContext = env->GetObjectField(_jobjectCompletedTask, jidActiveContext);
+          ManagedLog::LOGGER->LogStop("CompletedTaskClr2Java::GetActiveContext");
+          return gcnew ActiveContextClr2Java(env, jobjectActiveContext);
+        }
+
+        String^ CompletedTaskClr2Java::GetId() {
+          ManagedLog::LOGGER->Log("CompletedTaskClr2Java::GetId");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          return ManagedStringFromJavaString(env, _jstringId);
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ContextMessageClr2Java.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ContextMessageClr2Java.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ContextMessageClr2Java.cpp
new file mode 100644
index 0000000..6f0834a
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ContextMessageClr2Java.cpp
@@ -0,0 +1,76 @@
+/**
+ * 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.
+ */
+#include "Clr2JavaImpl.h"
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Driver {
+      namespace Bridge {
+        ref class ManagedLog {
+          internal:
+            static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>");
+        };
+        ContextMessageClr2Java::ContextMessageClr2Java(JNIEnv *env, jobject jobjectContextMessage) {
+          ManagedLog::LOGGER->LogStart("ContextMessageClr2Java::ContextMessageClr2Java");
+
+          pin_ptr<JavaVM*> pJavaVm = &_jvm;
+          if (env->GetJavaVM(pJavaVm) != 0) {
+            ManagedLog::LOGGER->LogError("Failed to get JavaVM", nullptr);
+          }
+          _jobjectContextMessage = reinterpret_cast<jobject>(env->NewGlobalRef(jobjectContextMessage));
+          jclass jclassContextMessage = env->GetObjectClass (_jobjectContextMessage);
+
+          jfieldID jidId = env->GetFieldID(jclassContextMessage, "contextMessageId", "Ljava/lang/String;");
+          jfieldID jidSourceId = env->GetFieldID(jclassContextMessage, "messageSourceId", "Ljava/lang/String;");
+          jfieldID jidMessage = env->GetFieldID(jclassContextMessage, "message", "()[B");
+
+          _jstringId = reinterpret_cast<jstring>(env->NewGlobalRef(env->GetObjectField(_jobjectContextMessage, jidId)));
+          _jstringSourceId = reinterpret_cast<jstring>(env->NewGlobalRef(env->GetObjectField(_jobjectContextMessage, jidSourceId)));
+          _jarrayMessage = reinterpret_cast<jbyteArray>(env->NewGlobalRef(env->GetObjectField(_jobjectContextMessage, jidMessage)));
+
+          ManagedLog::LOGGER->LogStop("ContextMessageClr2Java::ContextMessageClr2Java");
+        }
+
+        String^ ContextMessageClr2Java::GetId() {
+          ManagedLog::LOGGER->Log("ContextMessageClr2Java::GetId");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          return ManagedStringFromJavaString(env, _jstringId);
+        }
+
+        String^ ContextMessageClr2Java::GetMessageSourceId() {
+          ManagedLog::LOGGER->Log("ContextMessageClr2Java::GetMessageSourceId");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          return ManagedStringFromJavaString(env, _jstringSourceId);
+        }
+
+        array<byte>^ ContextMessageClr2Java::Get() {
+          ManagedLog::LOGGER->Log("ContextMessageClr2Java::Get");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          return ManagedByteArrayFromJavaByteArray(env, _jarrayMessage);
+        }
+
+        void ContextMessageClr2Java::OnError(String^ message) {
+          ManagedLog::LOGGER->Log("ContextMessageClr2Java::OnError");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          HandleClr2JavaError(env, message, _jobjectContextMessage);
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/EvaluatorRequestorClr2Java.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/EvaluatorRequestorClr2Java.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/EvaluatorRequestorClr2Java.cpp
new file mode 100644
index 0000000..eff8e3e
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/EvaluatorRequestorClr2Java.cpp
@@ -0,0 +1,69 @@
+/**
+ * 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.
+ */
+#include "Clr2JavaImpl.h"
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Driver {
+      namespace Bridge {
+        ref class ManagedLog {
+          internal:
+            static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>");
+        };
+
+        EvaluatorRequestorClr2Java::EvaluatorRequestorClr2Java(JNIEnv *env, jobject jevaluatorRequestor) {
+          ManagedLog::LOGGER->LogStart("EvaluatorRequestorClr2Java::EvaluatorRequestorClr2Java");
+          pin_ptr<JavaVM*> pJavaVm = &_jvm;
+          if (env->GetJavaVM(pJavaVm) != 0) {
+            ManagedLog::LOGGER->LogError("Failed to get JavaVM", nullptr);
+          }
+          _jobjectEvaluatorRequestor = reinterpret_cast<jobject>(env->NewGlobalRef(jevaluatorRequestor));
+          ManagedLog::LOGGER->LogStop("EvaluatorRequestorClr2Java::EvaluatorRequestorClr2Java");
+        }
+
+        void EvaluatorRequestorClr2Java::Submit(IEvaluatorRequest^ request) {
+          ManagedLog::LOGGER->LogStart("EvaluatorRequestorClr2Java::Submit");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          jclass jclassEvaluatorRequestor = env->GetObjectClass (_jobjectEvaluatorRequestor);
+          jmethodID jmidSubmit = env->GetMethodID(jclassEvaluatorRequestor, "submit", "(IIILjava/lang/String;)V");
+
+          if (jmidSubmit == NULL) {
+            fprintf(stdout, " jmidSubmit is NULL\n");
+            fflush (stdout);
+            return;
+          }
+          env -> CallObjectMethod(
+            _jobjectEvaluatorRequestor,
+            jmidSubmit,
+            request -> Number,
+            request -> MemoryMegaBytes,
+			request -> VirtualCore,
+            JavaStringFromManagedString(env, request -> Rack));
+          ManagedLog::LOGGER->LogStop("EvaluatorRequestorClr2Java::Submit");
+        }
+
+        void EvaluatorRequestorClr2Java::OnError(String^ message) {
+          ManagedLog::LOGGER->Log("EvaluatorRequestorClr2Java::OnError");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          HandleClr2JavaError(env, message, _jobjectEvaluatorRequestor);
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/FailedContextClr2Java.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/FailedContextClr2Java.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/FailedContextClr2Java.cpp
new file mode 100644
index 0000000..9a6e6d8
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/FailedContextClr2Java.cpp
@@ -0,0 +1,94 @@
+/**
+ * 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.
+ */
+#include "Clr2JavaImpl.h"
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Driver {
+      namespace Bridge {
+        ref class ManagedLog {
+          internal:
+            static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>");
+        };
+        FailedContextClr2Java::FailedContextClr2Java(JNIEnv *env, jobject jobjectFailedContext) {
+          ManagedLog::LOGGER->LogStart("FailedContextClr2Java::FailedContextClr2Java");
+
+          pin_ptr<JavaVM*> pJavaVm = &_jvm;
+          if (env->GetJavaVM(pJavaVm) != 0) {
+            ManagedLog::LOGGER->LogError("Failed to get JavaVM", nullptr);
+          }
+          _jobjectFailedContext = reinterpret_cast<jobject>(env->NewGlobalRef(jobjectFailedContext));
+          jclass jclassFailedContext = env->GetObjectClass (_jobjectFailedContext);
+
+          jfieldID jidContextId = env->GetFieldID(jclassFailedContext, "contextId", "Ljava/lang/String;");
+          jfieldID jidEvaluatorId = env->GetFieldID(jclassFailedContext, "evaluatorId", "Ljava/lang/String;");
+          jfieldID jidParentId = env->GetFieldID(jclassFailedContext, "parentContextId", "Ljava/lang/String;");
+
+          _jstringContextId = reinterpret_cast<jstring>(env->NewGlobalRef(env->GetObjectField(_jobjectFailedContext, jidContextId)));
+          _jstringEvaluatorId = reinterpret_cast<jstring>(env->NewGlobalRef(env->GetObjectField(_jobjectFailedContext, jidEvaluatorId)));
+          _jstringParentContextId = reinterpret_cast<jstring>(env->NewGlobalRef(env->GetObjectField(_jobjectFailedContext, jidParentId)));
+
+          ManagedLog::LOGGER->LogStop("FailedContextClr2Java::FailedContextClr2Java");
+        }
+
+        IActiveContextClr2Java^ FailedContextClr2Java::GetParentContext() {
+          ManagedLog::LOGGER->LogStart("FailedContextClr2Java::GetParentContext");
+
+          JNIEnv *env = RetrieveEnv(_jvm);
+
+          jclass jclassFailedContext = env->GetObjectClass(_jobjectFailedContext);
+          jfieldID jidParentContext = env->GetFieldID(jclassFailedContext, "parentContext", "Lorg/apache/reef/javabridge/ActiveContextBridge;");
+          jobject jobjectParentContext = env->GetObjectField(_jobjectFailedContext, jidParentContext);
+          ManagedLog::LOGGER->LogStop("FailedContextClr2Java::GetParentContext");
+
+          return gcnew ActiveContextClr2Java(env, jobjectParentContext);
+        }
+
+        String^ FailedContextClr2Java::GetId() {
+          ManagedLog::LOGGER->Log("FailedContextClr2Java::GetId");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          return ManagedStringFromJavaString(env, _jstringContextId);
+        }
+
+        String^ FailedContextClr2Java::GetEvaluatorId() {
+          ManagedLog::LOGGER->Log("FailedContextClr2Java::GetEvaluatorId");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          return ManagedStringFromJavaString(env, _jstringEvaluatorId);
+        }
+
+        String^ FailedContextClr2Java::GetParentId() {
+          ManagedLog::LOGGER->Log("FailedContextClr2Java::GetParentId");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          return ManagedStringFromJavaString(env, _jstringParentContextId);
+        }
+
+        IEvaluatorDescriptor^ FailedContextClr2Java::GetEvaluatorDescriptor() {
+          ManagedLog::LOGGER->LogStart("FailedContextClr2Java::GetEvaluatorDescriptor");
+          return CommonUtilities::RetrieveEvaluatorDescriptor(_jobjectFailedContext, _jvm);
+        }
+
+        void FailedContextClr2Java::OnError(String^ message) {
+          ManagedLog::LOGGER->Log("FailedContextClr2Java::OnError");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          HandleClr2JavaError(env, message, _jobjectFailedContext);
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/FailedEvaluatorClr2Java.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/FailedEvaluatorClr2Java.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/FailedEvaluatorClr2Java.cpp
new file mode 100644
index 0000000..d79ecce
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/FailedEvaluatorClr2Java.cpp
@@ -0,0 +1,72 @@
+/**
+ * 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.
+ */
+#include "Clr2JavaImpl.h"
+
+using namespace JavaClrBridge;
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Driver {
+      namespace Bridge {
+        ref class ManagedLog {
+          internal:
+            static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>");
+        };
+
+        FailedEvaluatorClr2Java::FailedEvaluatorClr2Java(JNIEnv *env, jobject jobjectFailedEvaluator) {
+          ManagedLog::LOGGER->LogStart("FailedEvaluatorClr2Java::FailedEvaluatorClr2Java");
+          pin_ptr<JavaVM*> pJavaVm = &_jvm;
+          if (env->GetJavaVM(pJavaVm) != 0) {
+            ManagedLog::LOGGER->LogError("Failed to get JavaVM", nullptr);
+          }
+          _jobjectFailedEvaluator = reinterpret_cast<jobject>(env->NewGlobalRef(jobjectFailedEvaluator));
+
+          jclass jclassFailedEvaluator = env->GetObjectClass(_jobjectFailedEvaluator);
+          jfieldID jidEvaluatorId = env->GetFieldID(jclassFailedEvaluator, "evaluatorId", "Ljava/lang/String;");
+          _jstringId = reinterpret_cast<jstring>(env->NewGlobalRef(env->GetObjectField(_jobjectFailedEvaluator, jidEvaluatorId)));
+          ManagedLog::LOGGER->LogStop("FailedEvaluatorClr2Java::FailedEvaluatorClr2Java");
+        }
+
+        IEvaluatorRequestorClr2Java^ FailedEvaluatorClr2Java::GetEvaluatorRequestor() {
+          ManagedLog::LOGGER->LogStart("FailedEvaluatorClr2Java::GetEvaluatorRequestor");
+          JNIEnv *env = RetrieveEnv(_jvm);
+
+          jclass jclassFailedEvaluator = env->GetObjectClass(_jobjectFailedEvaluator);
+          jfieldID jidEvaluatorRequestor = env->GetFieldID(jclassFailedEvaluator, "evaluatorRequestorBridge", "Lorg/apache/reef/javabridge/EvaluatorRequestorBridge;");
+          jobject jobjectEvaluatorRequestor = env->GetObjectField(_jobjectFailedEvaluator, jidEvaluatorRequestor);
+          ManagedLog::LOGGER->LogStop("FailedEvaluatorClr2Java::GetEvaluatorRequestor");
+          return gcnew EvaluatorRequestorClr2Java(env, jobjectEvaluatorRequestor);
+        }
+
+        String^ FailedEvaluatorClr2Java::GetId() {
+          ManagedLog::LOGGER->Log("FailedEvaluatorClr2Java::GetId");
+
+          JNIEnv *env = RetrieveEnv(_jvm);
+          return ManagedStringFromJavaString(env, _jstringId);
+        }
+
+        void FailedEvaluatorClr2Java::OnError(String^ message) {
+          ManagedLog::LOGGER->Log("FailedEvaluatorClr2Java::OnError");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          HandleClr2JavaError(env, message, _jobjectFailedEvaluator);
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/FailedTaskClr2Java.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/FailedTaskClr2Java.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/FailedTaskClr2Java.cpp
new file mode 100644
index 0000000..32414c6
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/FailedTaskClr2Java.cpp
@@ -0,0 +1,79 @@
+/**
+ * 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.
+ */
+#include "Clr2JavaImpl.h"
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Driver {
+      namespace Bridge {
+        ref class ManagedLog {
+          internal:
+            static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>");
+        };
+
+        FailedTaskClr2Java::FailedTaskClr2Java(JNIEnv *env, jobject jobjectFailedTask) {
+          ManagedLog::LOGGER->LogStart("FailedTaskClr2Java::AllocatedEvaluatorClr2Java");
+          pin_ptr<JavaVM*> pJavaVm = &_jvm;
+          if (env->GetJavaVM(pJavaVm) != 0) {
+            ManagedLog::LOGGER->LogError("Failed to get JavaVM", nullptr);
+          }
+          _jobjectFailedTask = reinterpret_cast<jobject>(env->NewGlobalRef(jobjectFailedTask));
+          ManagedLog::LOGGER->LogStop("FailedTaskClr2Java::AllocatedEvaluatorClr2Java");
+        }
+
+        IActiveContextClr2Java^ FailedTaskClr2Java::GetActiveContext() {
+          ManagedLog::LOGGER->LogStart("FailedTaskClr2Java::GetActiveContext");
+
+          JNIEnv *env = RetrieveEnv(_jvm);
+
+          jclass jclassFailedTask = env->GetObjectClass(_jobjectFailedTask);
+          jfieldID jidActiveContext = env->GetFieldID(jclassFailedTask, "jactiveContext", "Lorg/apache/reef/javabridge/ActiveContextBridge;");
+          jobject jobjectActiveContext = env->GetObjectField(_jobjectFailedTask, jidActiveContext);
+
+          ManagedLog::LOGGER->LogStop("FailedTaskClr2Java::GetActiveContext");
+          return gcnew ActiveContextClr2Java(env, jobjectActiveContext);
+        }
+
+        String^ FailedTaskClr2Java::GetString() {
+          ManagedLog::LOGGER->LogStart("FailedTaskClr2Java::GetString");
+          JNIEnv *env = RetrieveEnv(_jvm);
+
+          jclass jclassFailedTask = env->GetObjectClass (_jobjectFailedTask);
+          jmethodID jmidGetFailedTaskString = env->GetMethodID(jclassFailedTask, "getFailedTaskString", "()Ljava/lang/String;");
+
+          if (jmidGetFailedTaskString == NULL) {
+            ManagedLog::LOGGER->LogStart("jmidGetFailedTaskString is NULL");
+            return nullptr;
+          }
+          jstring jFailedTaskString = (jstring)env -> CallObjectMethod(
+                                        _jobjectFailedTask,
+                                        jmidGetFailedTaskString);
+          ManagedLog::LOGGER->LogStop("FailedTaskClr2Java::GetString");
+          return ManagedStringFromJavaString(env, jFailedTaskString);
+        }
+
+        void FailedTaskClr2Java::OnError(String^ message) {
+          ManagedLog::LOGGER->Log("FailedTaskClr2Java::OnError");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          HandleClr2JavaError(env, message, _jobjectFailedTask);
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/HttpServerClr2Java.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/HttpServerClr2Java.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/HttpServerClr2Java.cpp
new file mode 100644
index 0000000..90a930f
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/HttpServerClr2Java.cpp
@@ -0,0 +1,135 @@
+/**
+ * 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.
+ */
+#include "Clr2JavaImpl.h"
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Driver {
+      namespace Bridge {
+        ref class ManagedLog {
+          internal:
+            static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>");
+        };
+
+        HttpServerClr2Java::HttpServerClr2Java(JNIEnv *env, jobject jhttpServerEventBridge) {
+          ManagedLog::LOGGER->LogStart("HttpServerClr2Java::HttpServerClr2Java");
+          pin_ptr<JavaVM*> pJavaVm = &_jvm;
+          if (env->GetJavaVM(pJavaVm) != 0) {
+            ManagedLog::LOGGER->LogError("Failed to get JavaVM", nullptr);
+          }
+          _jhttpServerEventBridge = reinterpret_cast<jobject>(env->NewGlobalRef(jhttpServerEventBridge));
+          ManagedLog::LOGGER->LogStop("HttpServerClr2Java::HttpServerClr2Java");
+        }
+
+        String^ HttpServerClr2Java::GetQueryString() {
+          ManagedLog::LOGGER->LogStart("HttpServerClr2Java::GetQueryString");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          jclass jclasshttpServerEventBridge = env->GetObjectClass (_jhttpServerEventBridge);
+          jmethodID jmidgetQueryString = env->GetMethodID(jclasshttpServerEventBridge, "getQueryString", "()Ljava/lang/String;");
+          if (jmidgetQueryString == NULL) {
+            fprintf(stdout, " jmidgetQueryString is NULL\n");
+            fflush (stdout);
+            return nullptr;
+          }
+          jstring jQueryString = (jstring) env->CallObjectMethod(
+                                   _jhttpServerEventBridge,
+                                   jmidgetQueryString);
+
+          ManagedLog::LOGGER->LogStop("HttpServerClr2Java::GetQueryString");
+          return ManagedStringFromJavaString(env, jQueryString);
+        }
+
+        array<byte>^ HttpServerClr2Java::GetQueryRequestData() {
+          ManagedLog::LOGGER->LogStart("HttpServerClr2Java::GetQueryRequestData");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          jclass jclasshttpServerEventBridge = env->GetObjectClass (_jhttpServerEventBridge);
+          jmethodID jmidgetQueryBytes = env->GetMethodID(jclasshttpServerEventBridge, "getQueryRequestData", "()[B");
+
+          if (jmidgetQueryBytes == NULL) {
+            ManagedLog::LOGGER->Log("jmidgetQueryBytes is NULL");
+            return nullptr;
+          }
+          jbyteArray jQueryBytes = (jbyteArray) env->CallObjectMethod(
+                                     _jhttpServerEventBridge,
+                                     jmidgetQueryBytes);
+
+          ManagedLog::LOGGER->LogStop("HttpServerClr2Java::GetQueryRequestData");
+          return ManagedByteArrayFromJavaByteArray(env, jQueryBytes);
+        }
+
+        void HttpServerClr2Java::SetQueryResult(String^ queryResult) {
+          ManagedLog::LOGGER->LogStart("HttpServerClr2Java::SetQueryResult");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          jclass jclasshttpServerEventBridge = env->GetObjectClass (_jhttpServerEventBridge);
+          jmethodID jmidsetQueryResult = env->GetMethodID(jclasshttpServerEventBridge, "setQueryResult", "(Ljava/lang/String;)V");
+
+          if (jmidsetQueryResult == NULL) {
+            ManagedLog::LOGGER->Log("jmidsetQueryResult is NULL");
+            return;
+          }
+          env->CallObjectMethod(
+            _jhttpServerEventBridge,
+            jmidsetQueryResult,
+            JavaStringFromManagedString(env, queryResult));
+          ManagedLog::LOGGER->LogStop("HttpServerClr2Java::SetQueryResult");
+        }
+
+        void HttpServerClr2Java::SetQueryResponseData(array<byte>^ queryResponseData) {
+          ManagedLog::LOGGER->LogStart("HttpServerClr2Java::SetQueryResponseData");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          jclass jclasshttpServerEventBridge = env->GetObjectClass (_jhttpServerEventBridge);
+          jmethodID jmidsetQueryResult = env->GetMethodID(jclasshttpServerEventBridge, "setQueryResponseData", "([B)V");
+
+          if (jmidsetQueryResult == NULL) {
+            ManagedLog::LOGGER->Log("jmidsetQueryResult is NULL");
+            return;
+          }
+          env->CallObjectMethod(
+            _jhttpServerEventBridge,
+            jmidsetQueryResult,
+            JavaByteArrayFromManagedByteArray(env, queryResponseData));
+          ManagedLog::LOGGER->LogStop("HttpServerClr2Java::SetQueryResponseData");
+        }
+
+        void HttpServerClr2Java::SetUriSpecification(String^ uriSpecification) {
+          ManagedLog::LOGGER->LogStart("HttpServerClr2Java::SetUriSpecification");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          jclass jclasshttpServerEventBridge = env->GetObjectClass (_jhttpServerEventBridge);
+          jmethodID jmidsetUriSpecification = env->GetMethodID(jclasshttpServerEventBridge, "setUriSpecification", "(Ljava/lang/String;)V");
+
+          if (jmidsetUriSpecification == NULL) {
+            ManagedLog::LOGGER->Log("jmidsetUriSpecification is NULL");
+            return;
+          }
+          env->CallObjectMethod(
+            _jhttpServerEventBridge,
+            jmidsetUriSpecification,
+            JavaStringFromManagedString(env, uriSpecification));
+          ManagedLog::LOGGER->LogStop("HttpServerClr2Java::SetUriSpecification");
+        }
+
+        void HttpServerClr2Java::OnError(String^ message) {
+          ManagedLog::LOGGER->Log("HttpServerClr2Java::OnError");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          HandleClr2JavaError(env, message, _jhttpServerEventBridge);
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropAssemblies.h
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropAssemblies.h b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropAssemblies.h
new file mode 100644
index 0000000..2e80d71
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropAssemblies.h
@@ -0,0 +1,40 @@
+/**
+ * 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.
+ */
+#pragma once
+#define _USING_V110_SDK71_
+
+#pragma warning( push )
+#pragma warning( disable : 4793 )
+#include <jni.h>
+#pragma warning( pop )
+#include "mscoree.h"
+#include "vcclr.h"
+
+using namespace System;
+using namespace System::Reflection;
+using namespace System::Collections::Generic;
+
+public ref class AssemblyUtil {
+  public :
+    static int _asmCount = 0;
+    static Dictionary<String^, System::Reflection::Assembly^>^  asms2 = gcnew Dictionary<String^, Assembly^>();
+    static void Add(Assembly^  myasm);
+    static Assembly^ FindAsm (String^ myasm);
+    static Assembly^ MyResolveEventHandler(Object^ sender, ResolveEventArgs^ args);
+};

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropLogger.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropLogger.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropLogger.cpp
new file mode 100644
index 0000000..418bd55
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropLogger.cpp
@@ -0,0 +1,50 @@
+/**
+ * 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.
+ */
+#include "InteropLogger.h"
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Interop {
+      /// currently not being used
+      InteropLogger::InteropLogger (JNIEnv* env, jobject jobjectInteropLogger) {
+        _env = env;
+        _jobjectInteropLogger = jobjectInteropLogger;
+        _jclassInteropLogger = env->GetObjectClass(jobjectInteropLogger);
+        wchar_t formatBuf[1024];
+        if (NULL == _jclassInteropLogger) {
+          swprintf_s (formatBuf, sizeof(formatBuf) / sizeof(wchar_t), L"_jclassInteropLogger %p\n", _jclassInteropLogger);
+          fwprintf (stdout, formatBuf);
+          fflush (stdout);
+        }
+        _jmidLog  = env->GetMethodID(_jclassInteropLogger, "Log", "(ILjava/lang/String;)V");
+        if (NULL == _jmidLog) {
+          swprintf_s (formatBuf, sizeof(formatBuf) / sizeof(wchar_t), L"_jmidLog %p\n", _jmidLog);
+          fwprintf (stdout, formatBuf);
+          fflush (stdout);
+        }
+
+      }
+      void InteropLogger::Log(TraceLevel traceLevel, String^ message) {
+        pin_ptr<const wchar_t> wch = PtrToStringChars(message);
+        jstring msg = _env->NewString((const jchar*)wch, message->Length);
+        _env->CallObjectMethod(_jobjectInteropLogger, _jmidLog, (int)traceLevel, msg);
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropLogger.h
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropLogger.h b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropLogger.h
new file mode 100644
index 0000000..c2a2e80
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropLogger.h
@@ -0,0 +1,47 @@
+/**
+ * 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.
+ */
+#include "InteropUtil.h"
+#include "org_apache_reef_javabridge_NativeInterop.h"
+#include "JavaClrBridge.h"
+#include "InteropAssemblies.h"
+#using "clrhandler.dll"
+
+using namespace System;
+using namespace System::IO;
+using namespace System::Collections::Generic;
+using namespace System::Runtime::InteropServices;
+using namespace System::Reflection;
+using namespace Microsoft::Reef::Interop;
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Interop {
+      public ref class InteropLogger : public ILogger {
+          jobject _jobjectInteropLogger;
+          jclass  _jclassInteropLogger;
+          jmethodID _jmidLog;
+          JNIEnv* _env;
+
+        public:
+          InteropLogger (JNIEnv* env, jobject jobjectInteropLogger);
+          virtual void Log(TraceLevel traceLevel, String^ message );
+      };
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropReturnInfo.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropReturnInfo.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropReturnInfo.cpp
new file mode 100644
index 0000000..7a0d35a
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropReturnInfo.cpp
@@ -0,0 +1,91 @@
+/**
+ * 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.
+ */
+#include "InteropReturnInfo.h"
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Interop {
+      // currently not being used
+      InteropReturnInfo::InteropReturnInfo (
+        JNIEnv*     env,
+        jobject     jobjectInteropReturnInfo,
+        ILogger^    logger
+      ) {
+        _env = env;
+        _jobjectInteropReturnInfo = jobjectInteropReturnInfo;
+        jclass thisClass = env->GetObjectClass(jobjectInteropReturnInfo);
+        wchar_t formatBuf[1024];
+
+        swprintf_s (formatBuf, sizeof(formatBuf) / sizeof(wchar_t), L"zzzzzzz this should be printed by java jmid 00 %p\n", thisClass);
+        logger->Log(TraceLevel::Error, gcnew String(formatBuf));
+        _jmidAddExceptionString = env->GetMethodID(thisClass, "addExceptionString", "(Ljava/lang/String;)V");
+        if (NULL == _jmidAddExceptionString) {
+          swprintf_s (formatBuf, sizeof(formatBuf) / sizeof(wchar_t), L"_jmidAddExceptionString %p\n", _jmidAddExceptionString);
+          fwprintf (stdout, formatBuf);
+          fflush (stdout);
+        }
+
+        _jmidHasExceptions = env->GetMethodID(thisClass, "hasExceptions", "()Z");
+        if (NULL == _jmidHasExceptions) {
+          swprintf_s (formatBuf, sizeof(formatBuf) / sizeof(wchar_t), L"_jmidHasExceptions %p\n", _jmidHasExceptions);
+          fwprintf (stdout, formatBuf);
+          fflush (stdout);
+        }
+
+        _jmidsetReturnCode = env->GetMethodID(thisClass, "setReturnCode", "(I)V");
+        if (NULL == _jmidsetReturnCode) {
+          swprintf_s (formatBuf, sizeof(formatBuf) / sizeof(wchar_t), L"_jmidsetReturnCode %p\n", _jmidsetReturnCode);
+          fwprintf (stdout, formatBuf);
+          fflush (stdout);
+        }
+
+        _jmidgetReturnCode = env->GetMethodID(thisClass, "getReturnCode", "()I");
+        if (NULL == _jmidgetReturnCode) {
+          swprintf_s (formatBuf, sizeof(formatBuf) / sizeof(wchar_t), L"_jmidgetReturnCode %p\n", _jmidgetReturnCode);
+          fwprintf (stdout, formatBuf);
+          fflush (stdout);
+        }
+
+
+      }
+
+      void InteropReturnInfo::AddExceptionString(String^ exceptionString) {
+        HasExceptions();
+        pin_ptr<const wchar_t> wch = PtrToStringChars(exceptionString);
+        jstring ret = _env->NewString((const jchar*)wch, exceptionString->Length);
+        _env->CallObjectMethod(_jobjectInteropReturnInfo, _jmidAddExceptionString, ret);
+        HasExceptions();
+      }
+
+      Boolean InteropReturnInfo::HasExceptions() {
+        jobject obj = _env->CallObjectMethod(_jobjectInteropReturnInfo, _jmidHasExceptions);
+        return ((int)obj) != 0;
+      }
+      void InteropReturnInfo::SetReturnCode(int rc) {
+        _env->CallObjectMethod(_jobjectInteropReturnInfo, _jmidsetReturnCode, rc);
+        GetReturnCode();
+      }
+      int InteropReturnInfo::GetReturnCode() {
+        jobject obj = _env->CallObjectMethod(_jobjectInteropReturnInfo, _jmidgetReturnCode);
+        return (int)obj;
+      }
+
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropReturnInfo.h
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropReturnInfo.h b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropReturnInfo.h
new file mode 100644
index 0000000..1278516
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropReturnInfo.h
@@ -0,0 +1,57 @@
+/**
+ * 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.
+ */
+#include "InteropUtil.h"
+#include "org_apache_reef_javabridge_NativeInterop.h"
+#include "JavaClrBridge.h"
+#include "InteropAssemblies.h"
+#using "clrhandler.dll"
+
+using namespace System;
+using namespace System::IO;
+using namespace System::Collections::Generic;
+using namespace System::Runtime::InteropServices;
+using namespace System::Reflection;
+using namespace Microsoft::Reef::Interop;
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Interop {
+      public ref class InteropReturnInfo : public IInteropReturnInfo {
+          JNIEnv* _env;
+          jobject   _jobjectInteropReturnInfo;
+
+          jmethodID _jmidAddExceptionString;
+          jmethodID _jmidHasExceptions;
+          jmethodID _jmidsetReturnCode;
+          jmethodID _jmidgetReturnCode;
+
+        public:
+          InteropReturnInfo  (
+            JNIEnv* env,
+            jobject     jobjectInteropReturnInfo,
+            ILogger^    logger
+          );
+          virtual void AddExceptionString(String^ exceptionString);
+          virtual Boolean HasExceptions();
+          virtual void SetReturnCode(int rc);
+          virtual int GetReturnCode();
+      };
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropUtil.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropUtil.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropUtil.cpp
new file mode 100644
index 0000000..be24f32
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropUtil.cpp
@@ -0,0 +1,129 @@
+/**
+ * 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.
+ */
+#include "InteropUtil.h"
+#include "Clr2JavaImpl.h"
+
+using namespace System::Runtime::InteropServices;
+
+ref class ManagedLog {
+  internal:
+    static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>InteropUtil");
+};
+
+const wchar_t* UnicodeCppStringFromJavaString (
+  JNIEnv *env,
+  jstring javaString) {
+  const wchar_t* cppString = NULL;
+  if (NULL != javaString) {
+    cppString = (const wchar_t* )env->GetStringChars( javaString, 0);
+  }
+  return cppString;
+}
+
+void ReleaseUnicodeCppString (
+  JNIEnv*     env,
+  jstring     javaString,
+  jchar*      cppString) {
+  if (NULL != cppString) {
+    env->ReleaseStringChars(javaString, (jchar *)cppString);
+  }
+}
+
+String^ ManagedStringFromJavaString (
+  JNIEnv *env,
+  jstring javaString) {
+  if (javaString != NULL) {
+    int len = env->GetStringLength(javaString);
+    const wchar_t* wcsStr = UnicodeCppStringFromJavaString (env, javaString);
+    String^ managedStr = (NULL == wcsStr || 0 == len) ? nullptr : Marshal::PtrToStringUni((IntPtr)(unsigned short*)wcsStr, len);
+    ReleaseUnicodeCppString (env, javaString, (jchar*)wcsStr);
+    return managedStr;
+  }
+  return nullptr;
+}
+
+jstring JavaStringFromManagedString(
+  JNIEnv *env,
+  String^ managedString) {
+  pin_ptr<const wchar_t> wch = PtrToStringChars(managedString);
+  return env->NewString((const jchar*)wch, managedString->Length);
+}
+
+void HandleClr2JavaError(
+  JNIEnv *env,
+  String^ errorMessage,
+  jobject javaObject) {
+  ManagedLog::LOGGER->LogStart("InteropUtil::HandleClr2JavaError");
+
+  jclass javaClass = env->GetObjectClass (javaObject);
+  jmethodID jmidOnError = env->GetMethodID(javaClass, "onError", "(Ljava/lang/String;)V");
+
+  if (jmidOnError == NULL) {
+    ManagedLog::LOGGER->Log("jmidOnError is NULL");
+    return;
+  }
+  env -> CallObjectMethod(
+    javaObject,
+    jmidOnError,
+    JavaStringFromManagedString(env, errorMessage));
+  ManagedLog::LOGGER->LogStop("InteropUtil::HandleClr2JavaError");
+}
+
+array<byte>^ ManagedByteArrayFromJavaByteArray(
+  JNIEnv *env,
+  jbyteArray javaByteArray) {
+  if (javaByteArray != NULL) {
+    byte* bytes = (byte*)env->GetByteArrayElements (javaByteArray, FALSE);
+    int len = env->GetArrayLength(javaByteArray);
+    array<byte>^  managedByteArray = gcnew array<byte>(len);
+    //System::Array
+    for (int i = 0; i < len; i++) {
+      managedByteArray[i] = bytes[i];
+    }
+    return managedByteArray;
+  }
+  return nullptr;
+}
+
+jbyteArray JavaByteArrayFromManagedByteArray(
+  JNIEnv *env,
+  array<byte>^ managedByteArray) {
+  jbyteArray javaByteArray = env->NewByteArray(managedByteArray->Length);
+  pin_ptr<Byte> p = &managedByteArray[0];
+  env->SetByteArrayRegion(javaByteArray, 0, managedByteArray->Length, (jbyte*) p);
+  return javaByteArray;
+}
+
+jlongArray JavaLongArrayFromManagedLongArray(
+  JNIEnv *env,
+  array<unsigned long long>^ managedLongArray) {
+  jlongArray javaLongArray = env->NewLongArray(managedLongArray->Length);
+  pin_ptr<unsigned long long> p = &managedLongArray[0];
+  env->SetLongArrayRegion(javaLongArray, 0, managedLongArray->Length, (jlong*) p);
+  return javaLongArray;
+}
+
+JNIEnv* RetrieveEnv(JavaVM* jvm) {
+  JNIEnv *env;
+  if (jvm->AttachCurrentThread((void **) &env, NULL) != 0) {
+    ManagedLog::LOGGER->Log("cannot attach jni env to current jvm thread.");
+    throw;
+  }
+  return env;
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropUtil.h
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropUtil.h b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropUtil.h
new file mode 100644
index 0000000..2d95bcc
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/InteropUtil.h
@@ -0,0 +1,65 @@
+/**
+ * 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.
+ */
+#pragma once
+#define _USING_V110_SDK71_
+
+#pragma warning( push )
+#pragma warning( disable : 4793 )
+#include <jni.h>
+#pragma warning( pop )
+#include "mscoree.h"
+#include "vcclr.h"
+
+using namespace System;
+
+const wchar_t* UnicodeCppStringFromJavaString (
+  JNIEnv *env,
+  jstring javaString);
+
+void ReleaseUnicodeCppString (
+  JNIEnv*     env,
+  jstring     javaString,
+  jchar*      cppString);
+
+String^ ManagedStringFromJavaString (
+  JNIEnv *env,
+  jstring javaString);
+
+jstring JavaStringFromManagedString(
+  JNIEnv *env,
+  String^ managedString);
+
+array<byte>^ ManagedByteArrayFromJavaByteArray(
+  JNIEnv *env,
+  jbyteArray javaByteArray);
+
+jbyteArray JavaByteArrayFromManagedByteArray(
+  JNIEnv *env,
+  array<byte>^ managedByteArray);
+
+jlongArray JavaLongArrayFromManagedLongArray(
+  JNIEnv *env,
+  array<unsigned long long>^ managedLongArray);
+
+JNIEnv* RetrieveEnv(JavaVM* jvm);
+
+void HandleClr2JavaError(
+  JNIEnv *env,
+  String^ errorMessage,
+  jobject javaObject);
\ No newline at end of file


[20/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosDriverConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosDriverConfiguration.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosDriverConfiguration.java
new file mode 100644
index 0000000..2ef844d
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosDriverConfiguration.java
@@ -0,0 +1,98 @@
+/**
+ * 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.reef.runtime.mesos.driver;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.reef.io.TempFileCreator;
+import org.apache.reef.io.WorkingDirectoryTempFileCreator;
+import org.apache.reef.runtime.common.driver.api.AbstractDriverRuntimeConfiguration;
+import org.apache.reef.runtime.common.driver.api.ResourceLaunchHandler;
+import org.apache.reef.runtime.common.driver.api.ResourceReleaseHandler;
+import org.apache.reef.runtime.common.driver.api.ResourceRequestHandler;
+import org.apache.reef.runtime.common.files.RuntimeClasspathProvider;
+import org.apache.reef.runtime.common.parameters.JVMHeapSlack;
+import org.apache.reef.runtime.mesos.MesosClasspathProvider;
+import org.apache.reef.runtime.mesos.driver.parameters.MesosMasterIp;
+import org.apache.reef.runtime.mesos.util.HDFSConfigurationConstructor;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.OptionalParameter;
+import org.apache.reef.tang.formats.RequiredParameter;
+import org.apache.reef.wake.EStage;
+import org.apache.reef.wake.StageConfiguration;
+import org.apache.reef.wake.impl.SingleThreadStage;
+import org.apache.reef.wake.time.Clock;
+
+/**
+ * Binds Driver's runtime event handlers
+ */
+public final class MesosDriverConfiguration extends ConfigurationModuleBuilder {
+  /**
+   * @see AbstractDriverRuntimeConfiguration.JobIdentifier.class
+   */
+  public static final RequiredParameter<String> JOB_IDENTIFIER = new RequiredParameter<>();
+
+  /**
+   * @see AbstractDriverRuntimeConfiguration.EvaluatorTimeout
+   */
+  public static final OptionalParameter<Long> EVALUATOR_TIMEOUT = new OptionalParameter<>();
+
+  /**
+   * The ip address of Mesos Master
+   */
+  public static final RequiredParameter<String> MESOS_MASTER_IP = new RequiredParameter<>();
+
+  /**
+   * The client remote identifier.
+   */
+  public static final OptionalParameter<String> CLIENT_REMOTE_IDENTIFIER = new OptionalParameter<>();
+
+  /**
+   * The fraction of the container memory NOT to use for the Java Heap.
+   */
+  public static final OptionalParameter<Double> JVM_HEAP_SLACK = new OptionalParameter<>();
+
+  /**
+   * Capacity for runnning Mesos Scheduler Driver
+   */
+  public static final RequiredParameter<Integer> SCHEDULER_DRIVER_CAPACITY = new RequiredParameter<>();
+
+  public static ConfigurationModule CONF = new MesosDriverConfiguration()
+      .bindImplementation(ResourceLaunchHandler.class, MesosResourceLaunchHandler.class)
+      .bindImplementation(ResourceReleaseHandler.class, MesosResourceReleaseHandler.class)
+      .bindImplementation(ResourceRequestHandler.class, MesosResourceRequestHandler.class)
+      .bindSetEntry(Clock.RuntimeStartHandler.class, MesosRuntimeStartHandler.class)
+      .bindSetEntry(Clock.RuntimeStopHandler.class, MesosRuntimeStopHandler.class)
+      .bindImplementation(TempFileCreator.class, WorkingDirectoryTempFileCreator.class)
+
+      .bindNamedParameter(MesosMasterIp.class, MESOS_MASTER_IP)
+      .bindConstructor(Configuration.class, HDFSConfigurationConstructor.class)
+      .bindImplementation(RuntimeClasspathProvider.class, MesosClasspathProvider.class)
+
+      .bindNamedParameter(StageConfiguration.Capacity.class, SCHEDULER_DRIVER_CAPACITY)
+      .bindNamedParameter(StageConfiguration.StageHandler.class, MesosSchedulerDriverExecutor.class)
+      .bindImplementation(EStage.class, SingleThreadStage.class)
+
+          // Bind the fields bound in AbstractDriverRuntimeConfiguration
+      .bindNamedParameter(AbstractDriverRuntimeConfiguration.JobIdentifier.class, JOB_IDENTIFIER)
+      .bindNamedParameter(AbstractDriverRuntimeConfiguration.EvaluatorTimeout.class, EVALUATOR_TIMEOUT)
+      .bindNamedParameter(AbstractDriverRuntimeConfiguration.ClientRemoteIdentifier.class, CLIENT_REMOTE_IDENTIFIER)
+      .bindNamedParameter(JVMHeapSlack.class, JVM_HEAP_SLACK)
+      .build();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosResourceLaunchHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosResourceLaunchHandler.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosResourceLaunchHandler.java
new file mode 100644
index 0000000..7ce98f8
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosResourceLaunchHandler.java
@@ -0,0 +1,129 @@
+/**
+ * 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.reef.runtime.mesos.driver;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.io.TempFileCreator;
+import org.apache.reef.io.WorkingDirectoryTempFileCreator;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.api.ResourceLaunchHandler;
+import org.apache.reef.runtime.common.files.ClasspathProvider;
+import org.apache.reef.runtime.common.files.JobJarMaker;
+import org.apache.reef.runtime.common.files.REEFFileNames;
+import org.apache.reef.runtime.common.launch.CLRLaunchCommandBuilder;
+import org.apache.reef.runtime.common.launch.JavaLaunchCommandBuilder;
+import org.apache.reef.runtime.common.launch.LaunchCommandBuilder;
+import org.apache.reef.runtime.common.parameters.JVMHeapSlack;
+import org.apache.reef.runtime.common.utils.RemoteManager;
+import org.apache.reef.runtime.mesos.util.EvaluatorLaunch;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.formats.ConfigurationSerializer;
+import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.FileUtil;
+import org.apache.hadoop.fs.Path;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@DriverSide
+@Private
+final class MesosResourceLaunchHandler implements ResourceLaunchHandler {
+  private final ConfigurationSerializer configurationSerializer;
+  private final RemoteManager remoteManager;
+  private final REEFFileNames fileNames;
+  private final ClasspathProvider classpath;
+  private final double jvmHeapFactor;
+  private final REEFExecutors executors;
+  private static final Logger LOG = Logger.getLogger(MesosResourceLaunchHandler.class.getName());
+
+  @Inject
+  MesosResourceLaunchHandler(final ConfigurationSerializer configurationSerializer,
+                             final RemoteManager remoteManager,
+                             final REEFFileNames fileNames,
+                             final REEFExecutors executors,
+                             final ClasspathProvider classpath,
+                             final @Parameter(JVMHeapSlack.class) double jvmHeapSlack) {
+    this.configurationSerializer = configurationSerializer;
+    this.remoteManager = remoteManager;
+    this.fileNames = fileNames;
+    this.executors = executors;
+    this.classpath = classpath;
+    this.jvmHeapFactor = 1.0 - jvmHeapSlack;
+  }
+
+
+  @Override
+  public void onNext(final DriverRuntimeProtocol.ResourceLaunchProto resourceLaunchProto) {
+    try {
+      LOG.log(Level.INFO, "resourceLaunchProto. {0}", resourceLaunchProto.toString());
+
+      final File localStagingFolder =
+          Files.createTempDirectory(this.fileNames.getEvaluatorFolderPrefix()).toFile();
+
+      final Configuration evaluatorConfiguration = Tang.Factory.getTang()
+          .newConfigurationBuilder(this.configurationSerializer.fromString(resourceLaunchProto.getEvaluatorConf()))
+          .bindImplementation(TempFileCreator.class, WorkingDirectoryTempFileCreator.class)
+          .build();
+
+      final File configurationFile = new File(
+          localStagingFolder, this.fileNames.getEvaluatorConfigurationName());
+      this.configurationSerializer.toFile(evaluatorConfiguration, configurationFile);
+
+      JobJarMaker.copy(resourceLaunchProto.getFileList(), localStagingFolder);
+
+      final FileSystem fileSystem = FileSystem.get(new org.apache.hadoop.conf.Configuration());
+      final Path hdfsFolder = new Path(fileSystem.getUri() + "/" + resourceLaunchProto.getIdentifier() + "/");
+      FileUtil.copy(localStagingFolder, fileSystem, hdfsFolder, false, new org.apache.hadoop.conf.Configuration());
+
+      // TODO: Replace REEFExecutor with a simple launch command (we only need to launch REEFExecutor)
+      final LaunchCommandBuilder commandBuilder;
+      switch (resourceLaunchProto.getType()) {
+        case JVM:
+          commandBuilder = new JavaLaunchCommandBuilder().setClassPath(this.classpath.getEvaluatorClasspath());
+          break;
+        case CLR:
+          commandBuilder = new CLRLaunchCommandBuilder();
+          break;
+        default:
+          throw new IllegalArgumentException("Unsupported container type");
+      }
+
+      final List<String> command = commandBuilder
+          .setErrorHandlerRID(this.remoteManager.getMyIdentifier())
+          .setLaunchID(resourceLaunchProto.getIdentifier())
+          .setConfigurationFileName(this.fileNames.getEvaluatorConfigurationPath())
+          .setMemory((int) (this.jvmHeapFactor * this.executors.getMemory(resourceLaunchProto.getIdentifier())))
+          .build();
+
+      this.executors.launchEvaluator(
+          new EvaluatorLaunch(resourceLaunchProto.getIdentifier(), StringUtils.join(command, ' ')));
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosResourceReleaseHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosResourceReleaseHandler.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosResourceReleaseHandler.java
new file mode 100644
index 0000000..41c487e
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosResourceReleaseHandler.java
@@ -0,0 +1,42 @@
+/**
+ * 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.reef.runtime.mesos.driver;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.api.ResourceReleaseHandler;
+
+import javax.inject.Inject;
+
+@DriverSide
+@Private
+final class MesosResourceReleaseHandler implements ResourceReleaseHandler {
+  private final REEFScheduler REEFScheduler;
+
+  @Inject
+  MesosResourceReleaseHandler(final REEFScheduler REEFScheduler) {
+    this.REEFScheduler = REEFScheduler;
+  }
+
+  @Override
+  public void onNext(final DriverRuntimeProtocol.ResourceReleaseProto resourceReleaseProto) {
+    REEFScheduler.onResourceRelease(resourceReleaseProto);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosResourceRequestHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosResourceRequestHandler.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosResourceRequestHandler.java
new file mode 100644
index 0000000..a9c1016
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosResourceRequestHandler.java
@@ -0,0 +1,42 @@
+/**
+ * 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.reef.runtime.mesos.driver;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.api.ResourceRequestHandler;
+
+import javax.inject.Inject;
+
+@DriverSide
+@Private
+final class MesosResourceRequestHandler implements ResourceRequestHandler {
+  private final REEFScheduler REEFScheduler;
+
+  @Inject
+  MesosResourceRequestHandler(final REEFScheduler REEFScheduler) {
+    this.REEFScheduler = REEFScheduler;
+  }
+
+  @Override
+  public void onNext(final DriverRuntimeProtocol.ResourceRequestProto resourceRequestProto) {
+    REEFScheduler.onResourceRequest(resourceRequestProto);
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosRuntimeStartHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosRuntimeStartHandler.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosRuntimeStartHandler.java
new file mode 100644
index 0000000..c29e780
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosRuntimeStartHandler.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.runtime.mesos.driver;
+
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.runtime.event.RuntimeStart;
+
+import javax.inject.Inject;
+
+final class MesosRuntimeStartHandler implements EventHandler<RuntimeStart> {
+  private final REEFScheduler REEFScheduler;
+
+  @Inject
+  MesosRuntimeStartHandler(final REEFScheduler REEFScheduler) {
+    this.REEFScheduler = REEFScheduler;
+  }
+
+  @Override
+  public void onNext(final RuntimeStart runtimeStart){
+    this.REEFScheduler.onStart();
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosRuntimeStopHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosRuntimeStopHandler.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosRuntimeStopHandler.java
new file mode 100644
index 0000000..3d3b86e
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosRuntimeStopHandler.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.runtime.mesos.driver;
+
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.runtime.event.RuntimeStop;
+
+import javax.inject.Inject;
+
+final class MesosRuntimeStopHandler implements EventHandler<RuntimeStop> {
+  private final REEFScheduler REEFScheduler;
+
+  @Inject
+  MesosRuntimeStopHandler(final REEFScheduler REEFScheduler) {
+    this.REEFScheduler = REEFScheduler;
+  }
+
+  @Override
+  public void onNext(final RuntimeStop runtimeStop) {
+    this.REEFScheduler.onStop();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosSchedulerDriverExecutor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosSchedulerDriverExecutor.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosSchedulerDriverExecutor.java
new file mode 100644
index 0000000..abde514
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/MesosSchedulerDriverExecutor.java
@@ -0,0 +1,42 @@
+/**
+ * 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.reef.runtime.mesos.driver;
+
+import org.apache.mesos.Protos;
+import org.apache.mesos.SchedulerDriver;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class MesosSchedulerDriverExecutor implements EventHandler<SchedulerDriver> {
+  private static final Logger LOG = Logger.getLogger(MesosSchedulerDriverExecutor.class.getName());
+
+  @Inject
+  public MesosSchedulerDriverExecutor() {
+  }
+
+  @Override
+  public void onNext(final SchedulerDriver schedulerDriver) {
+    LOG.log(Level.INFO, "MesosMaster(SchedulerDriver) starting");
+    final Protos.Status status = schedulerDriver.run();
+    LOG.log(Level.INFO, "MesosMaster(SchedulerDriver) ended with status {0}", status);
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/REEFEventHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/REEFEventHandlers.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/REEFEventHandlers.java
new file mode 100644
index 0000000..fd5cce2
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/REEFEventHandlers.java
@@ -0,0 +1,65 @@
+/**
+ * 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.reef.runtime.mesos.driver;
+
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.DriverRuntimeProtocol.NodeDescriptorProto;
+import org.apache.reef.proto.DriverRuntimeProtocol.ResourceAllocationProto;
+import org.apache.reef.proto.DriverRuntimeProtocol.ResourceStatusProto;
+import org.apache.reef.proto.DriverRuntimeProtocol.RuntimeStatusProto;
+import org.apache.reef.runtime.common.driver.api.RuntimeParameters;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+
+@Private
+final class REEFEventHandlers {
+  private final EventHandler<ResourceAllocationProto> resourceAllocationEventHandler;
+  private final EventHandler<RuntimeStatusProto> runtimeStatusEventHandler;
+  private final EventHandler<NodeDescriptorProto> nodeDescriptorEventHandler;
+  private final EventHandler<ResourceStatusProto> resourceStatusHandlerEventHandler;
+
+  @Inject
+  REEFEventHandlers(final @Parameter(RuntimeParameters.ResourceAllocationHandler.class) EventHandler<ResourceAllocationProto> resourceAllocationEventHandler,
+                    final @Parameter(RuntimeParameters.RuntimeStatusHandler.class) EventHandler<RuntimeStatusProto> runtimeStatusEventHandler,
+                    final @Parameter(RuntimeParameters.NodeDescriptorHandler.class) EventHandler<NodeDescriptorProto> nodeDescriptorEventHandler,
+                    final @Parameter(RuntimeParameters.ResourceStatusHandler.class) EventHandler<ResourceStatusProto> resourceStatusHandlerEventHandler) {
+    this.resourceAllocationEventHandler = resourceAllocationEventHandler;
+    this.runtimeStatusEventHandler = runtimeStatusEventHandler;
+    this.nodeDescriptorEventHandler = nodeDescriptorEventHandler;
+    this.resourceStatusHandlerEventHandler = resourceStatusHandlerEventHandler;
+  }
+
+  void onNodeDescriptor(final NodeDescriptorProto nodeDescriptorProto) {
+    this.nodeDescriptorEventHandler.onNext(nodeDescriptorProto);
+  }
+
+  void onRuntimeStatus(final RuntimeStatusProto runtimeStatusProto) {
+    this.runtimeStatusEventHandler.onNext(runtimeStatusProto);
+  }
+
+  void onResourceAllocation(final ResourceAllocationProto resourceAllocationProto) {
+    this.resourceAllocationEventHandler.onNext(resourceAllocationProto);
+  }
+
+  void onResourceStatus(final ResourceStatusProto resourceStatusProto) {
+    this.resourceStatusHandlerEventHandler.onNext(resourceStatusProto);
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/REEFExecutor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/REEFExecutor.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/REEFExecutor.java
new file mode 100644
index 0000000..be6045a
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/REEFExecutor.java
@@ -0,0 +1,50 @@
+/**
+ * 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.reef.runtime.mesos.driver;
+
+import org.apache.reef.runtime.mesos.util.EvaluatorControl;
+import org.apache.reef.runtime.mesos.util.EvaluatorLaunch;
+import org.apache.reef.runtime.mesos.util.EvaluatorRelease;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ * The Driver's view of a REEFExecutor running in the cluster.
+ */
+final class REEFExecutor {
+  private final int memory;
+  private final EventHandler<EvaluatorControl> evaluatorControlHandler;
+
+  REEFExecutor(final int memory,
+               final EventHandler<EvaluatorControl> evaluatorControlHandler) {
+    this.memory = memory;
+    this.evaluatorControlHandler = evaluatorControlHandler;
+  }
+
+  public void launchEvaluator(final EvaluatorLaunch evaluatorLaunch) {
+    this.evaluatorControlHandler.onNext(new EvaluatorControl(evaluatorLaunch, null));
+  }
+
+  public void releaseEvaluator(final EvaluatorRelease evaluatorRelease) {
+    this.evaluatorControlHandler.onNext(new EvaluatorControl(null, evaluatorRelease));
+  }
+
+  public int getMemory() {
+    return this.memory;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/REEFExecutors.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/REEFExecutors.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/REEFExecutors.java
new file mode 100644
index 0000000..f70e3fe
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/REEFExecutors.java
@@ -0,0 +1,64 @@
+/**
+ * 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.reef.runtime.mesos.driver;
+
+import org.apache.reef.runtime.mesos.util.EvaluatorControl;
+import org.apache.reef.runtime.mesos.util.EvaluatorLaunch;
+import org.apache.reef.runtime.mesos.util.EvaluatorRelease;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * The Driver's view of MesosExecutors running in the cluster.
+ */
+final class REEFExecutors {
+  private final Map<String, REEFExecutor> executors = new ConcurrentHashMap<>();
+
+  @Inject
+  REEFExecutors() {
+  }
+
+  public void add(final String id,
+                  final int memory,
+                  final EventHandler<EvaluatorControl> evaluatorControlHandler) {
+    executors.put(id, new REEFExecutor(memory, evaluatorControlHandler));
+  }
+
+  public void remove(final String id) {
+    this.executors.remove(id);
+  }
+
+  public Set<String> getExecutorIds() { return executors.keySet(); }
+
+  public int getMemory(final String id) {
+    return executors.get(id).getMemory();
+  }
+
+  public void launchEvaluator(final EvaluatorLaunch evaluatorLaunch) {
+    executors.get(evaluatorLaunch.getIdentifier().toString()).launchEvaluator(evaluatorLaunch);
+  }
+
+  public void releaseEvaluator(final EvaluatorRelease evaluatorRelease) {
+    executors.get(evaluatorRelease.getIdentifier().toString()).releaseEvaluator(evaluatorRelease);
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/REEFScheduler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/REEFScheduler.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/REEFScheduler.java
new file mode 100644
index 0000000..9c2c6d9
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/REEFScheduler.java
@@ -0,0 +1,506 @@
+/**
+ * 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.reef.runtime.mesos.driver;
+
+import com.google.protobuf.ByteString;
+import org.apache.mesos.MesosSchedulerDriver;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.proto.DriverRuntimeProtocol.NodeDescriptorProto;
+import org.apache.reef.proto.DriverRuntimeProtocol.ResourceAllocationProto;
+import org.apache.reef.proto.DriverRuntimeProtocol.ResourceReleaseProto;
+import org.apache.reef.proto.DriverRuntimeProtocol.ResourceRequestProto;
+import org.apache.reef.proto.DriverRuntimeProtocol.RuntimeStatusProto;
+import org.apache.reef.proto.DriverRuntimeProtocol.RuntimeStatusProto.Builder;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.proto.ReefServiceProtos.State;
+import org.apache.reef.runtime.common.driver.api.AbstractDriverRuntimeConfiguration;
+import org.apache.reef.runtime.common.files.ClasspathProvider;
+import org.apache.reef.runtime.common.files.REEFFileNames;
+import org.apache.reef.runtime.mesos.driver.parameters.MesosMasterIp;
+import org.apache.reef.runtime.mesos.evaluator.REEFExecutor;
+import org.apache.reef.runtime.mesos.util.EvaluatorControl;
+import org.apache.reef.runtime.mesos.util.EvaluatorLaunch;
+import org.apache.reef.runtime.mesos.util.EvaluatorRelease;
+import org.apache.reef.runtime.mesos.util.MesosRemoteManager;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.EStage;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.Encoder;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
+import org.apache.commons.compress.utils.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.mesos.Protos;
+import org.apache.mesos.Protos.CommandInfo;
+import org.apache.mesos.Protos.CommandInfo.URI;
+import org.apache.mesos.Protos.ExecutorID;
+import org.apache.mesos.Protos.ExecutorInfo;
+import org.apache.mesos.Protos.Filters;
+import org.apache.mesos.Protos.Offer;
+import org.apache.mesos.Protos.Resource;
+import org.apache.mesos.Protos.TaskID;
+import org.apache.mesos.Protos.TaskInfo;
+import org.apache.mesos.Protos.Value;
+import org.apache.mesos.Protos.Value.Type;
+import org.apache.mesos.Scheduler;
+import org.apache.mesos.SchedulerDriver;
+
+import javax.inject.Inject;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.zip.GZIPOutputStream;
+
+/**
+ * MesosScheduler that interacts with MesosMaster and MesosExecutors.
+ */
+final class REEFScheduler implements Scheduler {
+  private static final Logger LOG = Logger.getLogger(REEFScheduler.class.getName());
+  private static final String REEF_TAR = "reef.tar.gz";
+  private static final String RUNTIME_NAME = "MESOS";
+  private static final int MESOS_SLAVE_PORT = 5051; //  Assumes for now that all slaves use port 5051(default) TODO: make it configurable.
+  private static final String REEF_JOB_NAME_PREFIX = "reef-job-";
+
+  private final String reefTarUri;
+  private final REEFFileNames fileNames;
+  private final ClasspathProvider classpath;
+
+  private final REEFEventHandlers reefEventHandlers;
+  private final MesosRemoteManager mesosRemoteManager;
+
+  private final SchedulerDriver mesosMaster;
+  private final EStage<SchedulerDriver> schedulerDriverEStage;
+  private final Map<String, Offer> offers = new ConcurrentHashMap<>();
+
+  private int outstandingRequestCounter = 0;
+  private final ConcurrentLinkedQueue<ResourceRequestProto> outstandingRequests = new ConcurrentLinkedQueue<>();
+  private final Map<String, ResourceRequestProto> executorIdToLaunchedRequests = new ConcurrentHashMap<>();
+  private final REEFExecutors executors;
+
+  @Inject
+  REEFScheduler(final REEFEventHandlers reefEventHandlers,
+                final MesosRemoteManager mesosRemoteManager,
+                final REEFExecutors executors,
+                final REEFFileNames fileNames,
+                final EStage<SchedulerDriver> schedulerDriverEStage,
+                final ClasspathProvider classpath,
+                final @Parameter(AbstractDriverRuntimeConfiguration.JobIdentifier.class) String jobIdentifier,
+                final @Parameter(MesosMasterIp.class) String masterIp) {
+    this.mesosRemoteManager = mesosRemoteManager;
+    this.reefEventHandlers = reefEventHandlers;
+    this.executors = executors;
+    this.fileNames = fileNames;
+    this.reefTarUri = getReefTarUri(jobIdentifier);
+    this.classpath = classpath;
+    this.schedulerDriverEStage = schedulerDriverEStage;
+
+    final Protos.FrameworkInfo frameworkInfo = Protos.FrameworkInfo.newBuilder()
+        .setUser("") // TODO: make it configurable.
+        .setName(REEF_JOB_NAME_PREFIX + jobIdentifier)
+        .build();
+    this.mesosMaster = new MesosSchedulerDriver(this, frameworkInfo, masterIp);
+  }
+
+  @Override
+  public void registered(final SchedulerDriver driver,
+                         final Protos.FrameworkID frameworkId,
+                         final Protos.MasterInfo masterInfo) {
+    LOG.log(Level.INFO, "Framework ID={0} registration succeeded", frameworkId);
+  }
+
+  @Override
+  public void reregistered(final SchedulerDriver driver, final Protos.MasterInfo masterInfo) {
+    LOG.log(Level.INFO, "Framework reregistered, MasterInfo: {0}", masterInfo);
+  }
+
+  /**
+   * All offers in each batch of offers will be either be launched or declined
+   */
+  @Override
+  public void resourceOffers(final SchedulerDriver driver, final List<Protos.Offer> offers) {
+    final Map<String, NodeDescriptorProto.Builder> nodeDescriptorProtos = new HashMap<>();
+
+    for (final Offer offer : offers) {
+      if (nodeDescriptorProtos.get(offer.getSlaveId().getValue()) == null) {
+        nodeDescriptorProtos.put(offer.getSlaveId().getValue(), NodeDescriptorProto.newBuilder()
+            .setIdentifier(offer.getSlaveId().getValue())
+            .setHostName(offer.getHostname())
+            .setPort(MESOS_SLAVE_PORT)
+            .setMemorySize(getMemory(offer)));
+      } else {
+        final NodeDescriptorProto.Builder builder = nodeDescriptorProtos.get(offer.getSlaveId().getValue());
+        builder.setMemorySize(builder.getMemorySize() + getMemory(offer));
+      }
+
+      this.offers.put(offer.getId().getValue(), offer);
+    }
+
+    for (final NodeDescriptorProto.Builder ndpBuilder : nodeDescriptorProtos.values()) {
+      this.reefEventHandlers.onNodeDescriptor(ndpBuilder.build());
+    }
+
+    if (outstandingRequests.size() > 0) {
+      doResourceRequest(outstandingRequests.remove());
+    }
+  }
+
+  @Override
+  public void offerRescinded(final SchedulerDriver driver, final Protos.OfferID offerId) {
+    for (final String executorId : this.executorIdToLaunchedRequests.keySet()) {
+      if (executorId.startsWith(offerId.getValue())) {
+        this.outstandingRequests.add(this.executorIdToLaunchedRequests.remove(executorId));
+      }
+    }
+  }
+
+  @Override
+  public void statusUpdate(final SchedulerDriver driver, final Protos.TaskStatus taskStatus) {
+    LOG.log(Level.SEVERE, "Task Status Update:", taskStatus.toString());
+
+    final DriverRuntimeProtocol.ResourceStatusProto.Builder resourceStatus =
+        DriverRuntimeProtocol.ResourceStatusProto.newBuilder().setIdentifier(taskStatus.getTaskId().getValue());
+
+    switch(taskStatus.getState()) {
+      case TASK_STARTING:
+        handleNewExecutor(taskStatus); // As there is only one Mesos Task per Mesos Executor, this is a new executor.
+        return;
+      case TASK_RUNNING:
+        resourceStatus.setState(State.RUNNING);
+        break;
+      case TASK_FINISHED:
+        if (taskStatus.getData().toStringUtf8().equals("eval_not_run")) { // TODO: a hack to pass closeEvaluator test, replace this with a better interface
+          return;
+        }
+        resourceStatus.setState(State.DONE);
+        break;
+      case TASK_KILLED:
+        resourceStatus.setState(State.KILLED);
+        break;
+      case TASK_LOST:
+      case TASK_FAILED:
+        resourceStatus.setState(State.FAILED);
+        break;
+      case TASK_STAGING:
+        throw new RuntimeException("TASK_STAGING should not be used for status update");
+      default:
+        throw new RuntimeException("Unknown TaskStatus");
+    }
+
+    if (taskStatus.getMessage() != null) {
+      resourceStatus.setDiagnostics(taskStatus.getMessage());
+    }
+
+    this.reefEventHandlers.onResourceStatus(resourceStatus.build());
+  }
+
+  @Override
+  public void frameworkMessage(final SchedulerDriver driver,
+                               final Protos.ExecutorID executorId,
+                               final Protos.SlaveID slaveId,
+                               final byte[] data) {
+    LOG.log(Level.INFO, "Framework Message. driver: {0} executorId: {1} slaveId: {2} data: {3}",
+        new Object[]{driver, executorId, slaveId, data});
+  }
+
+  @Override
+  public void disconnected(final SchedulerDriver driver) {
+    this.onRuntimeError(new RuntimeException("Scheduler disconnected from MesosMaster"));
+  }
+
+  @Override
+  public void slaveLost(final SchedulerDriver driver, final Protos.SlaveID slaveId) {
+    LOG.log(Level.SEVERE, "Slave Lost. {0}", slaveId.getValue());
+  }
+
+  @Override
+  public void executorLost(final SchedulerDriver driver,
+                           final Protos.ExecutorID executorId,
+                           final Protos.SlaveID slaveId,
+                           final int status) {
+    final String diagnostics = "Executor Lost. executorid: "+executorId.getValue()+" slaveid: "+slaveId.getValue();
+    final DriverRuntimeProtocol.ResourceStatusProto resourceStatus =
+        DriverRuntimeProtocol.ResourceStatusProto.newBuilder()
+            .setIdentifier(executorId.getValue())
+            .setState(State.FAILED)
+            .setExitCode(status)
+            .setDiagnostics(diagnostics)
+            .build();
+
+    this.reefEventHandlers.onResourceStatus(resourceStatus);
+  }
+
+  @Override
+  public void error(final SchedulerDriver driver, final String message) {
+    this.onRuntimeError(new RuntimeException(message));
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // HELPER METHODS
+
+  public void onStart() {
+    this.schedulerDriverEStage.onNext(this.mesosMaster);
+  }
+
+  public void onStop() {
+    this.mesosMaster.stop();
+    try {
+      this.schedulerDriverEStage.close();
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  public void onResourceRequest(final ResourceRequestProto resourceRequestProto) {
+    this.outstandingRequestCounter += resourceRequestProto.getResourceCount();
+    updateRuntimeStatus();
+    doResourceRequest(resourceRequestProto);
+  }
+
+  public void onResourceRelease(final ResourceReleaseProto resourceReleaseProto) {
+    this.executors.releaseEvaluator(new EvaluatorRelease(resourceReleaseProto.getIdentifier()));
+    this.executors.remove(resourceReleaseProto.getIdentifier());
+    updateRuntimeStatus();
+  }
+
+  /**
+   * Greedily acquire resources by launching a Mesos Task(w/ our custom MesosExecutor) on REEF Evaluator request.
+   * Either called from onResourceRequest(for a new request) or resourceOffers(for an outstanding request).
+   * TODO: reflect priority and rack/node locality specified in resourceRequestProto.
+   */
+  private synchronized void doResourceRequest(final ResourceRequestProto resourceRequestProto) {
+    int tasksToLaunchCounter = resourceRequestProto.getResourceCount();
+
+    for (final Offer offer : this.offers.values()) {
+      final int cpuSlots = getCpu(offer) / resourceRequestProto.getVirtualCores();
+      final int memSlots = getMemory(offer) / resourceRequestProto.getMemorySize();
+      final int taskNum = Math.min(Math.min(cpuSlots, memSlots), tasksToLaunchCounter);
+
+      if (taskNum > 0 && satisfySlaveConstraint(resourceRequestProto, offer)) {
+        final List<TaskInfo> tasksToLaunch = new ArrayList<>();
+        tasksToLaunchCounter -= taskNum;
+
+        // Launch as many MesosTasks on the same node(offer) as possible to exploit locality.
+        for (int j = 0; j < taskNum; j++) {
+          final String id = offer.getId().getValue() + "-" + String.valueOf(j);
+          final String executorLaunchCommand = getExecutorLaunchCommand(id, resourceRequestProto.getMemorySize());
+
+          final ExecutorInfo executorInfo = ExecutorInfo.newBuilder()
+              .setExecutorId(ExecutorID.newBuilder()
+                  .setValue(id)
+                  .build())
+              .setCommand(CommandInfo.newBuilder()
+                  .setValue(executorLaunchCommand)
+                  .addUris(URI.newBuilder().setValue(reefTarUri).build())
+                  .build())
+              .build();
+
+          final TaskInfo taskInfo = TaskInfo.newBuilder()
+              .setTaskId(TaskID.newBuilder()
+                  .setValue(id)
+                  .build())
+              .setName(id)
+              .setSlaveId(offer.getSlaveId())
+              .addResources(Resource.newBuilder()
+                  .setName("mem")
+                  .setType(Type.SCALAR)
+                  .setScalar(Value.Scalar.newBuilder()
+                      .setValue(resourceRequestProto.getMemorySize())
+                      .build())
+                  .build())
+              .addResources(Resource.newBuilder()
+                  .setName("cpus")
+                  .setType(Type.SCALAR)
+                  .setScalar(Value.Scalar.newBuilder()
+                      .setValue(resourceRequestProto.getVirtualCores())
+                      .build())
+                  .build())
+              .setExecutor(executorInfo)
+              .build();
+
+          tasksToLaunch.add(taskInfo);
+          this.executorIdToLaunchedRequests.put(id, resourceRequestProto);
+        }
+
+        final Filters filters = Filters.newBuilder().setRefuseSeconds(0).build();
+        mesosMaster.launchTasks(Collections.singleton(offer.getId()), tasksToLaunch, filters);
+      } else {
+        mesosMaster.declineOffer(offer.getId());
+      }
+    }
+
+    // the offers are no longer valid(all launched or declined)
+    this.offers.clear();
+
+    // Save leftovers that couldn't be launched
+    outstandingRequests.add(ResourceRequestProto.newBuilder()
+        .mergeFrom(resourceRequestProto)
+        .setResourceCount(tasksToLaunchCounter)
+        .build());
+  }
+
+  private void handleNewExecutor(final Protos.TaskStatus taskStatus) {
+    final ResourceRequestProto resourceRequestProto =
+        this.executorIdToLaunchedRequests.remove(taskStatus.getTaskId().getValue());
+
+    final EventHandler<EvaluatorControl> evaluatorControlHandler =
+        this.mesosRemoteManager.getHandler(taskStatus.getMessage(), EvaluatorControl.class);
+    this.executors.add(taskStatus.getTaskId().getValue(), resourceRequestProto.getMemorySize(), evaluatorControlHandler);
+
+    final ResourceAllocationProto alloc = DriverRuntimeProtocol.ResourceAllocationProto.newBuilder()
+        .setIdentifier(taskStatus.getTaskId().getValue())
+        .setNodeId(taskStatus.getSlaveId().getValue())
+        .setResourceMemory(resourceRequestProto.getMemorySize())
+        .build();
+    reefEventHandlers.onResourceAllocation(alloc);
+
+    this.outstandingRequestCounter--;
+    this.updateRuntimeStatus();
+  }
+
+  private synchronized void updateRuntimeStatus() {
+    final Builder builder = DriverRuntimeProtocol.RuntimeStatusProto.newBuilder()
+        .setName(RUNTIME_NAME)
+        .setState(State.RUNNING)
+        .setOutstandingContainerRequests(this.outstandingRequestCounter);
+
+    for (final String executorId : this.executors.getExecutorIds()) {
+      builder.addContainerAllocation(executorId);
+    }
+
+    this.reefEventHandlers.onRuntimeStatus(builder.build());
+  }
+
+  private void onRuntimeError(final Throwable throwable) {
+    this.mesosMaster.stop();
+    try {
+      this.schedulerDriverEStage.close();
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+
+    final Builder runtimeStatusBuilder = RuntimeStatusProto.newBuilder()
+        .setState(State.FAILED)
+        .setName(RUNTIME_NAME);
+
+    final Encoder<Throwable> codec = new ObjectSerializableCodec<>();
+    runtimeStatusBuilder.setError(ReefServiceProtos.RuntimeErrorProto.newBuilder()
+        .setName(RUNTIME_NAME)
+        .setMessage(throwable.getMessage())
+        .setException(ByteString.copyFrom(codec.encode(throwable)))
+        .build());
+
+    this.reefEventHandlers.onRuntimeStatus(runtimeStatusBuilder.build());
+  }
+
+  private boolean satisfySlaveConstraint(final ResourceRequestProto resourceRequestProto, final Offer offer) {
+    return resourceRequestProto.getNodeNameCount() == 0 ||
+        resourceRequestProto.getNodeNameList().contains(offer.getSlaveId().getValue());
+  }
+
+  private int getMemory(final Offer offer) {
+    for (final Resource resource : offer.getResourcesList()) {
+      switch (resource.getName()) {
+        case "mem":
+          return (int)resource.getScalar().getValue();
+      }
+    }
+    return 0;
+  }
+
+  private int getCpu(final Offer offer) {
+    for (final Resource resource : offer.getResourcesList()) {
+      switch (resource.getName()) {
+        case "cpus":
+          return (int)resource.getScalar().getValue();
+      }
+    }
+    return 0;
+  }
+
+  private String getExecutorLaunchCommand(final String executorID, final int memorySize) {
+    final String DEFAULT_JAVA_PATH = System.getenv("JAVA_HOME") + "/bin/" +  "java";
+    final String classPath = "-classpath " + StringUtils.join(this.classpath.getEvaluatorClasspath(), ":");
+    final String logging = "-Djava.util.logging.config.class=org.apache.reef.util.logging.Config";
+    final String mesosExecutorId = "-mesos_executor_id " + executorID;
+
+    return (new StringBuilder()
+        .append(DEFAULT_JAVA_PATH + " ")
+        .append("-XX:PermSize=128m" + " ")
+        .append("-XX:MaxPermSize=128m" + " ")
+        .append("-Xmx" + String.valueOf(memorySize) + "m" + " ")
+        .append(classPath + " ")
+        .append(logging + " ")
+        .append(REEFExecutor.class.getName() + " ")
+        .append(mesosExecutorId + " ")
+        .toString());
+  }
+
+  private String getReefTarUri(final String jobIdentifier) {
+    try {
+      // Create REEF_TAR
+      final FileOutputStream fileOutputStream = new FileOutputStream(REEF_TAR);
+      final TarArchiveOutputStream tarArchiveOutputStream =
+          new TarArchiveOutputStream(new GZIPOutputStream(fileOutputStream));
+      final File globalFolder = new File(this.fileNames.getGlobalFolderPath());
+      final DirectoryStream<Path> directoryStream = Files.newDirectoryStream(globalFolder.toPath());
+
+      for (final Path path : directoryStream) {
+        tarArchiveOutputStream.putArchiveEntry(new TarArchiveEntry(path.toFile(),
+            globalFolder + "/" + path.getFileName()));
+
+        final BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(path.toFile()));
+        IOUtils.copy(bufferedInputStream, tarArchiveOutputStream);
+        bufferedInputStream.close();
+
+        tarArchiveOutputStream.closeArchiveEntry();
+      }
+      directoryStream.close();
+      tarArchiveOutputStream.close();
+      fileOutputStream.close();
+
+      // Upload REEF_TAR to HDFS
+      final FileSystem fileSystem = FileSystem.get(new Configuration());
+      final org.apache.hadoop.fs.Path src = new org.apache.hadoop.fs.Path(REEF_TAR);
+      final String reefTarUri = fileSystem.getUri().toString() + "/" + jobIdentifier + "/" + REEF_TAR;
+      final org.apache.hadoop.fs.Path dst = new org.apache.hadoop.fs.Path(reefTarUri);
+      fileSystem.copyFromLocalFile(src, dst);
+
+      return reefTarUri;
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/parameters/MesosMasterIp.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/parameters/MesosMasterIp.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/parameters/MesosMasterIp.java
new file mode 100644
index 0000000..863f5b3
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/driver/parameters/MesosMasterIp.java
@@ -0,0 +1,26 @@
+/**
+ * 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.reef.runtime.mesos.driver.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+@NamedParameter(doc = "The ip address of Mesos Master")
+public final class MesosMasterIp implements Name<String> {
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/evaluator/EvaluatorControlHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/evaluator/EvaluatorControlHandler.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/evaluator/EvaluatorControlHandler.java
new file mode 100644
index 0000000..20287e1
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/evaluator/EvaluatorControlHandler.java
@@ -0,0 +1,55 @@
+/**
+ * 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.reef.runtime.mesos.evaluator;
+
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.runtime.mesos.util.EvaluatorControl;
+import org.apache.reef.tang.InjectionFuture;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.RemoteMessage;
+
+import javax.inject.Inject;
+
+/**
+ * Handles evaluator launch requests via MesosRemoteManager from MesosResourceLaunchHandler
+ */
+@EvaluatorSide
+@Private
+final class EvaluatorControlHandler implements EventHandler<RemoteMessage<EvaluatorControl>> {
+  // EvaluatorLaunchHandler is registered in MesosExecutor. Hence, we need an InjectionFuture here.
+  private final InjectionFuture<REEFExecutor> mesosExecutor;
+
+  @Inject
+  EvaluatorControlHandler(final InjectionFuture<REEFExecutor> mesosExecutor) {
+    this.mesosExecutor = mesosExecutor;
+  }
+
+  @Override
+  public void onNext(final RemoteMessage<EvaluatorControl> remoteMessage) {
+    final EvaluatorControl evaluatorControl = remoteMessage.getMessage();
+    if (evaluatorControl.getEvaluatorLaunch() != null) {
+      this.mesosExecutor.get().onEvaluatorLaunch(evaluatorControl.getEvaluatorLaunch());
+    } else if (evaluatorControl.getEvaluatorRelease() != null) {
+      this.mesosExecutor.get().onEvaluatorRelease(evaluatorControl.getEvaluatorRelease());
+    } else {
+      throw new IllegalArgumentException();
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/evaluator/REEFExecutor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/evaluator/REEFExecutor.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/evaluator/REEFExecutor.java
new file mode 100644
index 0000000..7225f92
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/evaluator/REEFExecutor.java
@@ -0,0 +1,249 @@
+/**
+ * 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.reef.runtime.mesos.evaluator;
+
+import com.google.protobuf.ByteString;
+import org.apache.reef.runtime.common.files.REEFFileNames;
+import org.apache.reef.runtime.mesos.evaluator.parameters.MesosExecutorId;
+import org.apache.reef.runtime.mesos.util.EvaluatorControl;
+import org.apache.reef.runtime.mesos.util.EvaluatorLaunch;
+import org.apache.reef.runtime.mesos.util.EvaluatorRelease;
+import org.apache.reef.runtime.mesos.util.MesosRemoteManager;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.formats.CommandLine;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.FileUtil;
+import org.apache.hadoop.fs.Path;
+import org.apache.mesos.Executor;
+import org.apache.mesos.ExecutorDriver;
+import org.apache.mesos.MesosExecutorDriver;
+import org.apache.mesos.Protos.ExecutorInfo;
+import org.apache.mesos.Protos.FrameworkInfo;
+import org.apache.mesos.Protos.SlaveInfo;
+import org.apache.mesos.Protos.Status;
+import org.apache.mesos.Protos.TaskID;
+import org.apache.mesos.Protos.TaskInfo;
+import org.apache.mesos.Protos.TaskState;
+import org.apache.mesos.Protos.TaskStatus;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public final class REEFExecutor implements Executor {
+  private final static Logger LOG = Logger.getLogger(REEFExecutor.class.getName());
+
+  private final MesosExecutorDriver mesosExecutorDriver;
+  private final MesosRemoteManager mesosRemoteManager;
+  private final ExecutorService executorService;
+  private final REEFFileNames fileNames;
+  private final String mesosExecutorId;
+
+  private Process evaluatorProcess;
+  private Integer evaluatorProcessExitValue;
+
+  @Inject
+  REEFExecutor(final EvaluatorControlHandler evaluatorControlHandler,
+               final MesosRemoteManager mesosRemoteManager,
+               final REEFFileNames fileNames,
+               final @Parameter(MesosExecutorId.class) String mesosExecutorId) {
+    this.mesosRemoteManager = mesosRemoteManager;
+    this.mesosRemoteManager.registerHandler(EvaluatorControl.class, evaluatorControlHandler);
+    this.mesosExecutorDriver = new MesosExecutorDriver(this);
+    this.executorService = Executors.newCachedThreadPool();
+    this.fileNames = fileNames;
+    this.mesosExecutorId = mesosExecutorId;
+  }
+
+  @Override
+  public final void registered(final ExecutorDriver driver,
+                         final ExecutorInfo executorInfo,
+                         final FrameworkInfo frameworkInfo,
+                         final SlaveInfo slaveInfo) {
+    LOG.log(Level.FINEST, "Executor registered. driver: {0} executorInfo: {1} frameworkInfo: {2} slaveInfo {3}",
+        new Object[]{driver, executorInfo, frameworkInfo, slaveInfo});
+  }
+
+  @Override
+  public final void reregistered(final ExecutorDriver driver, final SlaveInfo slaveInfo) {
+    LOG.log(Level.FINEST, "Executor reregistered. driver: {0}", driver);
+  }
+
+  @Override
+  public final void disconnected(final ExecutorDriver driver) {
+    this.onRuntimeError();
+  }
+
+  /**
+   * We assume a long-running Mesos Task that manages a REEF Evaluator process, leveraging Mesos Executor's interface.
+   */
+  @Override
+  public final void launchTask(final ExecutorDriver driver, final TaskInfo task) {
+    driver.sendStatusUpdate(TaskStatus.newBuilder()
+        .setTaskId(TaskID.newBuilder().setValue(this.mesosExecutorId).build())
+        .setState(TaskState.TASK_STARTING)
+        .setSlaveId(task.getSlaveId())
+        .setMessage(this.mesosRemoteManager.getMyIdentifier())
+        .build());
+  }
+
+  @Override
+  public final void killTask(final ExecutorDriver driver, final TaskID taskId) {
+    this.onStop();
+  }
+
+  @Override
+  public final void frameworkMessage(final ExecutorDriver driver, final byte[] data) {
+    LOG.log(Level.FINEST, "Framework Messge. ExecutorDriver: {0}, data: {1}.",
+        new Object[]{driver, data});
+  }
+
+  @Override
+  public final void shutdown(final ExecutorDriver driver) {
+    this.onStop();
+  }
+
+  @Override
+  public final void error(final ExecutorDriver driver, final String message) {
+    this.onRuntimeError();
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // HELPER METHODS
+
+  private void onStart() {
+    this.executorService.submit(new Thread() { public void run() {
+      final Status status;
+      status = mesosExecutorDriver.run();
+      LOG.log(Level.INFO, "MesosExecutorDriver ended with status {0}", status);
+    }});
+  }
+
+  private void onStop() {
+    // Shutdown REEF Evaluator
+    if (this.evaluatorProcess != null) {
+      this.evaluatorProcess.destroy();
+      mesosExecutorDriver.sendStatusUpdate(TaskStatus.newBuilder()
+          .setTaskId(TaskID.newBuilder()
+              .setValue(mesosExecutorId)
+              .build())
+          .setState(TaskState.TASK_FINISHED)
+          .setMessage("Evaluator Process exited with status " + String.valueOf(evaluatorProcessExitValue))
+          .build());
+    } else {
+      mesosExecutorDriver.sendStatusUpdate(TaskStatus.newBuilder()
+          .setTaskId(TaskID.newBuilder()
+              .setValue(mesosExecutorId)
+              .build())
+          .setState(TaskState.TASK_FINISHED)
+          .setData(ByteString.copyFromUtf8("eval_not_run")) // TODO: a hack to pass closeEvaluator test, replace this with a better interface
+          .setMessage("Evaluator Process exited with status " + String.valueOf(evaluatorProcessExitValue))
+          .build());
+    }
+
+    // Shutdown Mesos Executor
+    this.executorService.shutdown();
+    this.mesosExecutorDriver.stop();
+  }
+
+  private void onRuntimeError() {
+    // Shutdown REEF Evaluator
+    if (this.evaluatorProcess != null) {
+      this.evaluatorProcess.destroy();
+    }
+    mesosExecutorDriver.sendStatusUpdate(TaskStatus.newBuilder()
+        .setTaskId(TaskID.newBuilder()
+            .setValue(mesosExecutorId)
+            .build())
+        .setState(TaskState.TASK_FAILED)
+        .setMessage("Evaluator Process exited with status " + String.valueOf(evaluatorProcessExitValue))
+        .build());
+
+    // Shutdown Mesos Executor
+    this.executorService.shutdown();
+    this.mesosExecutorDriver.stop();
+  }
+
+  public final void onEvaluatorRelease(final EvaluatorRelease evaluatorRelease) {
+    LOG.log(Level.INFO, "Release!!!! {0}", evaluatorRelease.toString());
+    assert(evaluatorRelease.getIdentifier().toString().equals(this.mesosExecutorId));
+    this.onStop();
+  }
+
+  public final void onEvaluatorLaunch(final EvaluatorLaunch evaluatorLaunch) {
+    LOG.log(Level.INFO, "Launch!!!! {0}", evaluatorLaunch.toString());
+    assert(evaluatorLaunch.getIdentifier().toString().equals(this.mesosExecutorId));
+    final ExecutorService evaluatorLaunchExecutorService = Executors.newSingleThreadExecutor();
+    evaluatorLaunchExecutorService.submit(new Thread() {
+      public void run() {
+        try {
+          final List<String> command = Arrays.asList(evaluatorLaunch.getCommand().toString().split(" "));
+          LOG.log(Level.INFO, "Command!!!! {0}", command);
+          final FileSystem fileSystem = FileSystem.get(new Configuration());
+          final Path hdfsFolder = new Path(fileSystem.getUri() + "/" + mesosExecutorId);
+          final File localFolder = new File(fileNames.getREEFFolderName(), fileNames.getLocalFolderName());
+
+          FileUtil.copy(fileSystem, hdfsFolder, localFolder, true, new Configuration());
+
+          evaluatorProcess = new ProcessBuilder()
+              .command(command)
+              .redirectError(new File(fileNames.getEvaluatorStderrFileName()))
+              .redirectOutput(new File(fileNames.getEvaluatorStdoutFileName()))
+              .start();
+
+          evaluatorProcessExitValue = evaluatorProcess.waitFor();
+
+          fileSystem.close();
+        } catch (IOException | InterruptedException e) {
+          throw new RuntimeException(e);
+        }
+      }
+    });
+    evaluatorLaunchExecutorService.shutdown();
+  }
+
+  public static org.apache.reef.tang.Configuration parseCommandLine(final String[] args) throws IOException {
+    final JavaConfigurationBuilder confBuilder = Tang.Factory.getTang().newConfigurationBuilder();
+
+    new CommandLine(confBuilder)
+        .registerShortNameOfClass(MesosExecutorId.class)
+        .processCommandLine(args);
+
+    return confBuilder.build();
+  }
+
+  /**
+   * The starting point of the executor.
+   */
+  public static void main(final String[] args) throws Exception {
+    final Injector injector = Tang.Factory.getTang().newInjector(parseCommandLine(args));
+    final REEFExecutor REEFExecutor = injector.getInstance(REEFExecutor.class);
+    REEFExecutor.onStart();
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/evaluator/parameters/MesosExecutorId.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/evaluator/parameters/MesosExecutorId.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/evaluator/parameters/MesosExecutorId.java
new file mode 100644
index 0000000..0f2044c
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/evaluator/parameters/MesosExecutorId.java
@@ -0,0 +1,26 @@
+/**
+ * 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.reef.runtime.mesos.evaluator.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+@NamedParameter(doc = "The Executor's id", short_name = "mesos_executor_id")
+public final class MesosExecutorId implements Name<String> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/util/HDFSConfigurationConstructor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/util/HDFSConfigurationConstructor.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/util/HDFSConfigurationConstructor.java
new file mode 100644
index 0000000..f028274
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/util/HDFSConfigurationConstructor.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.runtime.mesos.util;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.reef.tang.ExternalConstructor;
+
+import javax.inject.Inject;
+
+public final class HDFSConfigurationConstructor implements ExternalConstructor<Configuration> {
+  @Inject
+  HDFSConfigurationConstructor() {
+  }
+
+  @Override
+  public Configuration newInstance() {
+    return new Configuration();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/util/MesosErrorHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/util/MesosErrorHandler.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/util/MesosErrorHandler.java
new file mode 100644
index 0000000..19ec56a
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/util/MesosErrorHandler.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.runtime.mesos.util;
+
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * ErrorHandler for MesosRemoteManager.
+ * TODO: Replace this class once Tang's namespace feature is enabled
+ */
+public final class MesosErrorHandler implements EventHandler<Throwable> {
+
+  private static final Logger LOG = Logger.getLogger(MesosErrorHandler.class.getName());
+
+  @Inject
+  MesosErrorHandler() {
+  }
+
+  @Override
+  public void onNext(final Throwable e) {
+    LOG.log(Level.SEVERE, "MesosRemoteManager Error", e);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/util/MesosRemoteManager.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/util/MesosRemoteManager.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/util/MesosRemoteManager.java
new file mode 100644
index 0000000..b32475d
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/util/MesosRemoteManager.java
@@ -0,0 +1,62 @@
+/**
+ * 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.reef.runtime.mesos.util;
+
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.RemoteIdentifierFactory;
+import org.apache.reef.wake.remote.RemoteManager;
+import org.apache.reef.wake.remote.RemoteMessage;
+import org.apache.reef.wake.remote.impl.DefaultRemoteManagerImplementation;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+import org.apache.reef.wake.remote.impl.StringCodec;
+
+import javax.inject.Inject;
+
+/**
+ * Since the existing RemoteManager cannot use an additional codec,
+ * we need this additional RemoteManager to use MesosMessageCodec.
+ * TODO: Replace this class once Tang's namespace feature is enabled
+ */
+public final class MesosRemoteManager {
+  private final RemoteManager raw;
+  private final RemoteIdentifierFactory factory;
+
+  @Inject
+  MesosRemoteManager(final RemoteIdentifierFactory factory,
+                     final MesosErrorHandler mesosErrorHandler,
+                     final MesosRemoteManagerCodec codec) {
+    this.factory = factory;
+    this.raw = new DefaultRemoteManagerImplementation("MESOS_EXECUTOR", "##UNKNOWN##", 0,
+        codec, mesosErrorHandler, false, 3, 10000);
+  }
+
+  public <T> EventHandler<T> getHandler(
+      final String destinationIdentifier, final Class<? extends T> messageType) {
+    return this.raw.getHandler(factory.getNewInstance(destinationIdentifier), messageType);
+  }
+
+  public <T, U extends T> AutoCloseable registerHandler(
+      final Class<U> messageType, final EventHandler<RemoteMessage<T>> theHandler) {
+    return this.raw.registerHandler(messageType, theHandler);
+  }
+
+  public String getMyIdentifier() {
+    return this.raw.getMyIdentifier().toString();
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/util/MesosRemoteManagerCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/util/MesosRemoteManagerCodec.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/util/MesosRemoteManagerCodec.java
new file mode 100644
index 0000000..aa4c853
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/util/MesosRemoteManagerCodec.java
@@ -0,0 +1,68 @@
+/**
+ * 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.reef.runtime.mesos.util;
+
+import org.apache.avro.io.*;
+import org.apache.avro.specific.SpecificDatumReader;
+import org.apache.avro.specific.SpecificDatumWriter;
+import org.apache.reef.wake.remote.Codec;
+import org.apache.reef.wake.remote.exception.RemoteRuntimeException;
+
+import javax.inject.Inject;
+import java.io.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class MesosRemoteManagerCodec implements Codec<EvaluatorControl> {
+  private static final Logger LOG = Logger.getLogger(MesosRemoteManagerCodec.class.getName());
+
+  @Inject
+  public MesosRemoteManagerCodec() {
+  }
+
+ @Override
+  public byte[] encode(final EvaluatorControl evaluatorControl) {
+    try {
+      LOG.log(Level.INFO, "Before Eecoding: {0}", evaluatorControl.toString());
+      final ByteArrayOutputStream out = new ByteArrayOutputStream();
+      final BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(out, null);
+      final DatumWriter<EvaluatorControl> writer = new SpecificDatumWriter<>(EvaluatorControl.getClassSchema());
+      writer.write(evaluatorControl, encoder);
+      encoder.flush();
+      out.close();
+      LOG.log(Level.INFO, "After Encoding");
+      return out.toByteArray();
+    } catch (final IOException ex) {
+      throw new RemoteRuntimeException(ex);
+    }
+  }
+
+  @Override
+  public EvaluatorControl decode(final byte[] buf) {
+    try {
+      LOG.log(Level.INFO, "Before Decoding: {0}", buf);
+      final SpecificDatumReader<EvaluatorControl> reader = new SpecificDatumReader<>(EvaluatorControl.getClassSchema());
+      final Decoder decoder = DecoderFactory.get().binaryDecoder(buf, null);
+      LOG.log(Level.INFO, "After Decoding");
+      return reader.read(null, decoder);
+    } catch (final IOException ex) {
+      throw new RemoteRuntimeException(ex);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/pom.xml b/lang/java/reef-runtime-yarn/pom.xml
new file mode 100644
index 0000000..faa1c22
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/pom.xml
@@ -0,0 +1,80 @@
+<?xml version="1.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.
+-->
+<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.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+    <name>REEF Runtime for YARN</name>
+    <artifactId>reef-runtime-yarn</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-utils-hadoop</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-yarn-common</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-common</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-yarn-client</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-all</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <resources>
+            <resource>
+                <targetPath>META-INF/</targetPath>
+                <filtering>false</filtering>
+                <directory>${basedir}/conf</directory>
+                <includes>
+                    <include>*.xml</include>
+                    <include>*.properties</include>
+                </includes>
+                <excludes>
+                </excludes>
+            </resource>
+        </resources>
+    </build>
+
+</project>


[29/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerREEFYarn.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerREEFYarn.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerREEFYarn.java
new file mode 100644
index 0000000..c42cba5
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerREEFYarn.java
@@ -0,0 +1,46 @@
+/**
+ * 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.reef.examples.scheduler;
+
+import org.apache.commons.cli.ParseException;
+import org.apache.reef.runtime.yarn.client.YarnClientConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.InjectionException;
+
+import java.io.IOException;
+
+import static org.apache.reef.examples.scheduler.SchedulerREEF.runTaskScheduler;
+
+/**
+ * REEF TaskScheduler on YARN runtime.
+ */
+public final class SchedulerREEFYarn {
+  /**
+   * Launch the scheduler with YARN client configuration
+   * @param args
+   * @throws InjectionException
+   * @throws java.io.IOException
+   */
+  public final static void main(String[] args)
+    throws InjectionException, IOException, ParseException {
+    final Configuration runtimeConfiguration =
+      YarnClientConfiguration.CONF.build();
+    runTaskScheduler(runtimeConfiguration, args);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerResponse.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerResponse.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerResponse.java
new file mode 100644
index 0000000..50293e6
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerResponse.java
@@ -0,0 +1,114 @@
+/**
+ * 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.reef.examples.scheduler;
+
+/**
+ * This class specifies the response from the Scheduler.
+ * It includes the status code and message.
+ */
+final class SchedulerResponse {
+  /**
+   * 200 OK : The request succeeded normally.
+   */
+  private static final int SC_OK = 200;
+
+  /**
+   * 400 BAD REQUEST : The request is syntactically incorrect.
+   */
+  private static final int SC_BAD_REQUEST = 400;
+
+  /**
+   * 403 FORBIDDEN : Syntactically okay but refused to process.
+   */
+  private static final int SC_FORBIDDEN = 403;
+
+  /**
+   * 404 NOT FOUND :  The resource is not available.
+   */
+  private static final int SC_NOT_FOUND = 404;
+
+  /**
+   * Create a response with OK status
+   */
+  public static SchedulerResponse OK(final String message){
+    return new SchedulerResponse (SC_OK, message);
+  }
+
+  /**
+   * Create a response with BAD_REQUEST status
+   */
+  public static SchedulerResponse BAD_REQUEST(final String message){
+    return new SchedulerResponse (SC_BAD_REQUEST, message);
+  }
+
+  /**
+   * Create a response with FORBIDDEN status
+   */
+  public static SchedulerResponse FORBIDDEN(final String message){
+    return new SchedulerResponse (SC_FORBIDDEN, message);
+  }
+
+  /**
+   * Create a response with NOT FOUND status
+   */
+  public static SchedulerResponse NOT_FOUND(final String message){
+    return new SchedulerResponse (SC_NOT_FOUND, message);
+  }
+
+  /**
+   * Return {@code true} if the response is OK.
+   */
+  public boolean isOK(){
+    return this.status == SC_OK;
+  }
+
+  /**
+   * Status code of the request based on RFC 2068.
+   */
+  private int status;
+
+  /**
+   * Message to send.
+   */
+  private String message;
+
+  /**
+   * Constructor using status code and message.
+   * @param status
+   * @param message
+   */
+  private SchedulerResponse(final int status, final String message) {
+    this.status = status;
+    this.message = message;
+  }
+
+  /**
+   * Return the status code of this response.
+   */
+  int getStatus() {
+    return status;
+  }
+
+  /**
+   * Return the message of this response.
+   */
+  String getMessage() {
+    return message;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/TaskEntity.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/TaskEntity.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/TaskEntity.java
new file mode 100644
index 0000000..fe777ff
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/TaskEntity.java
@@ -0,0 +1,71 @@
+/**
+ * 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.reef.examples.scheduler;
+
+/**
+ * TaskEntity represent a single entry of task queue used in
+ * scheduler. Since REEF already has the class named {Task},
+ * a different name is used for this class.
+ */
+final class TaskEntity {
+  private final int taskId;
+  private final String command;
+
+  public TaskEntity(final int taskId, final String command) {
+    this.taskId = taskId;
+    this.command = command;
+  }
+
+  /**
+   * Return the TaskID assigned to this Task.
+   */
+  int getId() {
+    return taskId;
+  }
+
+  String getCommand() {
+    return command;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    TaskEntity that = (TaskEntity) o;
+
+    if (taskId != that.taskId) return false;
+    if (!command.equals(that.command)) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = taskId;
+    result = 31 * result + command.hashCode();
+    return result;
+  }
+
+  @Override
+  public String toString() {
+    return new StringBuilder().append("<Id=").append(taskId).
+      append(", Command=").append(command).append(">").toString();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/package-info.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/package-info.java
new file mode 100644
index 0000000..728806c
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Task scheduler example based on reef-webserver
+ */
+package org.apache.reef.examples.scheduler;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/Control.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/Control.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/Control.java
new file mode 100644
index 0000000..db312ce
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/Control.java
@@ -0,0 +1,103 @@
+/**
+ * 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.reef.examples.suspend;
+
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.formats.CommandLine;
+import org.apache.reef.wake.EStage;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.impl.LoggingEventHandler;
+import org.apache.reef.wake.impl.ThreadPoolStage;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+import org.apache.reef.wake.remote.impl.TransportEvent;
+import org.apache.reef.wake.remote.transport.Link;
+import org.apache.reef.wake.remote.transport.Transport;
+import org.apache.reef.wake.remote.transport.netty.NettyMessagingTransport;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public final class Control {
+
+  private static final Logger LOG = Logger.getLogger(Control.class.getName());
+  private final transient String command;
+  private final transient String taskId;
+  private final transient int port;
+
+  @Inject
+  public Control(@Parameter(SuspendClientControl.Port.class) final int port,
+                 @Parameter(TaskId.class) final String taskId,
+                 @Parameter(Command.class) final String command) {
+    this.command = command.trim().toLowerCase();
+    this.taskId = taskId;
+    this.port = port;
+  }
+
+  private static Configuration getConfig(final String[] args) throws IOException, BindException {
+    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    new CommandLine(cb).processCommandLine(args, SuspendClientControl.Port.class, TaskId.class, Command.class);
+    return cb.build();
+  }
+
+  public static void main(final String[] args) throws Exception {
+    final Configuration config = getConfig(args);
+    final Injector injector = Tang.Factory.getTang().newInjector(config);
+    final Control control = injector.getInstance(Control.class);
+    control.run();
+  }
+
+  public void run() throws Exception {
+
+    LOG.log(Level.INFO, "command: {0} task: {1} port: {2}",
+        new Object[]{this.command, this.taskId, this.port});
+
+    final ObjectSerializableCodec<String> codec = new ObjectSerializableCodec<>();
+
+    final EStage<TransportEvent> stage = new ThreadPoolStage<>("suspend-control-client",
+        new LoggingEventHandler<TransportEvent>(), 1, new EventHandler<Throwable>() {
+      @Override
+      public void onNext(final Throwable throwable) {
+        throw new RuntimeException(throwable);
+      }
+    });
+
+    try (final Transport transport = new NettyMessagingTransport("localhost", 0, stage, stage, 1, 10000)) {
+      final Link link = transport.open(new InetSocketAddress("localhost", this.port), codec, null);
+      link.write(this.command + " " + this.taskId);
+    }
+  }
+
+  @NamedParameter(doc = "Task id", short_name = "task")
+  public static final class TaskId implements Name<String> {
+  }
+
+  @NamedParameter(doc = "Command: 'suspend' or 'resume'", short_name = "cmd")
+  public static final class Command implements Name<String> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/Launch.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/Launch.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/Launch.java
new file mode 100644
index 0000000..696d02d
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/Launch.java
@@ -0,0 +1,174 @@
+/**
+ * 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.reef.examples.suspend;
+
+import org.apache.reef.client.ClientConfiguration;
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.runtime.yarn.client.YarnClientConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.AvroConfigurationSerializer;
+import org.apache.reef.tang.formats.CommandLine;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Suspend/Resume example - main class.
+ */
+public final class Launch {
+
+  /**
+   * Standard Java logger
+   */
+  private static final Logger LOG = Logger.getLogger(Launch.class.getName());
+  /**
+   * Number of REEF worker threads in local mode.
+   */
+  private static final int NUM_LOCAL_THREADS = 4;
+
+  /**
+   * This class should not be instantiated.
+   */
+  private Launch() {
+    throw new RuntimeException("Do not instantiate this class!");
+  }
+
+  /**
+   * @param args command line arguments, as passed to main()
+   * @return Configuration object.
+   */
+  private static Configuration parseCommandLine(final String[] args)
+      throws IOException, BindException {
+    final JavaConfigurationBuilder confBuilder = Tang.Factory.getTang().newConfigurationBuilder();
+    final CommandLine cl = new CommandLine(confBuilder);
+    cl.registerShortNameOfClass(Local.class);
+    cl.registerShortNameOfClass(NumCycles.class);
+    cl.registerShortNameOfClass(Delay.class);
+    cl.registerShortNameOfClass(SuspendClientControl.Port.class);
+    cl.processCommandLine(args);
+    return confBuilder.build();
+  }
+
+  private static Configuration cloneCommandLineConfiguration(final Configuration commandLineConf)
+      throws InjectionException, BindException {
+    final Injector injector = Tang.Factory.getTang().newInjector(commandLineConf);
+    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindNamedParameter(NumCycles.class, String.valueOf(injector.getNamedInstance(NumCycles.class)));
+    cb.bindNamedParameter(Delay.class, String.valueOf(injector.getNamedInstance(Delay.class)));
+    cb.bindNamedParameter(SuspendClientControl.Port.class,
+        String.valueOf(injector.getNamedInstance(SuspendClientControl.Port.class)));
+    return cb.build();
+  }
+
+  /**
+   * Parse command line arguments and create TANG configuration ready to be submitted to REEF.
+   *
+   * @param args Command line arguments, as passed into main().
+   * @return (immutable) TANG Configuration object.
+   * @throws BindException      if configuration commandLineInjector fails.
+   * @throws InjectionException if configuration commandLineInjector fails.
+   * @throws IOException        error reading the configuration.
+   */
+  private static Configuration getClientConfiguration(final String[] args)
+      throws BindException, InjectionException, IOException {
+    final Configuration commandLineConf = parseCommandLine(args);
+
+    final Configuration clientConfiguration = ClientConfiguration.CONF
+        .set(ClientConfiguration.ON_JOB_RUNNING, SuspendClient.RunningJobHandler.class)
+        .set(ClientConfiguration.ON_JOB_FAILED, SuspendClient.FailedJobHandler.class)
+        .set(ClientConfiguration.ON_JOB_COMPLETED, SuspendClient.CompletedJobHandler.class)
+        .set(ClientConfiguration.ON_RUNTIME_ERROR, SuspendClient.RuntimeErrorHandler.class)
+        .build();
+
+    // TODO: Remove the injector, have stuff injected.
+    final Injector commandLineInjector = Tang.Factory.getTang().newInjector(commandLineConf);
+    final boolean isLocal = commandLineInjector.getNamedInstance(Local.class);
+    final Configuration runtimeConfiguration;
+    if (isLocal) {
+      LOG.log(Level.INFO, "Running on the local runtime");
+      runtimeConfiguration = LocalRuntimeConfiguration.CONF
+          .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, NUM_LOCAL_THREADS)
+          .build();
+    } else {
+      LOG.log(Level.INFO, "Running on YARN");
+      runtimeConfiguration = YarnClientConfiguration.CONF.build();
+    }
+
+    return Tang.Factory.getTang()
+        .newConfigurationBuilder(runtimeConfiguration, clientConfiguration,
+            cloneCommandLineConfiguration(commandLineConf))
+        .build();
+  }
+
+  /**
+   * Main method that runs the example.
+   *
+   * @param args command line parameters.
+   */
+  public static void main(final String[] args) {
+    try {
+      final Configuration config = getClientConfiguration(args);
+
+      LOG.log(Level.INFO, "Configuration:\n--\n{0}--",
+          new AvroConfigurationSerializer().toString(config));
+
+      final Injector injector = Tang.Factory.getTang().newInjector(config);
+      final SuspendClient client = injector.getInstance(SuspendClient.class);
+
+      client.submit();
+      client.waitForCompletion();
+      LOG.info("Done!");
+
+    } catch (final BindException | IOException | InjectionException ex) {
+      LOG.log(Level.SEVERE, "Cannot launch: configuration error", ex);
+    } catch (final Exception ex) {
+      LOG.log(Level.SEVERE, "Cleanup error", ex);
+    }
+  }
+
+  /**
+   * Command line parameter = true to run locally, or false to run on YARN.
+   */
+  @NamedParameter(doc = "Whether or not to run on the local runtime",
+      short_name = "local", default_value = "true")
+  public static final class Local implements Name<Boolean> {
+  }
+
+  /**
+   * Command line parameter: number of iterations to run.
+   */
+  @NamedParameter(doc = "Number of iterations to run", short_name = "cycles", default_value = "20")
+  public static final class NumCycles implements Name<Integer> {
+  }
+
+  /**
+   * Command line parameter: delay in seconds for each cycle.
+   */
+  @NamedParameter(doc = "Delay in seconds between the cycles", short_name = "delay", default_value = "1")
+  public static final class Delay implements Name<Integer> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/ObjectWritableCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/ObjectWritableCodec.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/ObjectWritableCodec.java
new file mode 100644
index 0000000..72b257a
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/ObjectWritableCodec.java
@@ -0,0 +1,93 @@
+/**
+ * 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.reef.examples.suspend;
+
+import org.apache.hadoop.io.Writable;
+import org.apache.reef.wake.remote.Codec;
+import org.apache.reef.wake.remote.exception.RemoteRuntimeException;
+
+import java.io.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Codec for Hadoop Writable object serialization.
+ *
+ * @param <T> Class derived from Hadoop Writable.
+ */
+public class ObjectWritableCodec<T extends Writable> implements Codec<T> {
+
+  /**
+   * Standard Java logger
+   */
+  private static final Logger LOG = Logger.getLogger(ObjectWritableCodec.class.getName());
+
+  /**
+   * we need it to invoke the class constructor.
+   */
+  private final Class<? extends T> writableClass;
+
+  /**
+   * Create a new codec for Hadoop Writables.
+   *
+   * @param clazz we need it to invoke the class constructor.
+   */
+  public ObjectWritableCodec(final Class<? extends T> clazz) {
+    this.writableClass = clazz;
+  }
+
+  /**
+   * Encodes Hadoop Writable object into a byte array.
+   *
+   * @param writable the object to encode.
+   * @return serialized object as byte array.
+   * @throws RemoteRuntimeException if serialization fails.
+   */
+  @Override
+  public byte[] encode(T writable) {
+    try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+         final DataOutputStream dos = new DataOutputStream(bos)) {
+      writable.write(dos);
+      return bos.toByteArray();
+    } catch (final IOException ex) {
+      LOG.log(Level.SEVERE, "Cannot encode object " + writable, ex);
+      throw new RemoteRuntimeException(ex);
+    }
+  }
+
+  /**
+   * Decode Hadoop Writable object from a byte array.
+   *
+   * @param buffer serialized version of the Writable object (as a byte array).
+   * @return a Writable object.
+   * @throws RemoteRuntimeException if deserialization fails.
+   */
+  @Override
+  public T decode(byte[] buffer) {
+    try (final ByteArrayInputStream bis = new ByteArrayInputStream(buffer);
+         final DataInputStream dis = new DataInputStream(bis)) {
+      final T writable = this.writableClass.newInstance();
+      writable.readFields(dis);
+      return writable;
+    } catch (final IOException | InstantiationException | IllegalAccessException ex) {
+      LOG.log(Level.SEVERE, "Cannot decode class " + this.writableClass, ex);
+      throw new RemoteRuntimeException(ex);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/SuspendClient.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/SuspendClient.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/SuspendClient.java
new file mode 100644
index 0000000..e57e9b5
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/SuspendClient.java
@@ -0,0 +1,172 @@
+/**
+ * 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.reef.examples.suspend;
+
+import org.apache.reef.client.*;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.util.EnvironmentUtils;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+public class SuspendClient {
+
+  /**
+   * Standard java logger.
+   */
+  private final static Logger LOG = Logger.getLogger(SuspendClient.class.getName());
+
+  /**
+   * Job Driver configuration.
+   */
+  private final Configuration driverConfig;
+
+  /**
+   * Reference to the REEF framework.
+   */
+  private final REEF reef;
+
+  /**
+   * Controller that listens for suspend/resume commands on a specified port.
+   */
+  private final SuspendClientControl controlListener;
+
+  /**
+   * @param reef      reference to the REEF framework.
+   * @param port      port to listen to for suspend/resume commands.
+   * @param numCycles number of cycles to run in the task.
+   * @param delay     delay in seconds between cycles in the task.
+   */
+  @Inject
+  SuspendClient(
+      final REEF reef,
+      final @Parameter(SuspendClientControl.Port.class) int port,
+      final @Parameter(Launch.NumCycles.class) int numCycles,
+      final @Parameter(Launch.Delay.class) int delay) throws BindException, IOException {
+
+    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder()
+        .bindNamedParameter(Launch.NumCycles.class, Integer.toString(numCycles))
+        .bindNamedParameter(Launch.Delay.class, Integer.toString(delay));
+
+    cb.addConfiguration(DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(SuspendDriver.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "suspend-" + System.currentTimeMillis())
+        .set(DriverConfiguration.ON_TASK_RUNNING, SuspendDriver.RunningTaskHandler.class)
+        .set(DriverConfiguration.ON_TASK_COMPLETED, SuspendDriver.CompletedTaskHandler.class)
+        .set(DriverConfiguration.ON_TASK_SUSPENDED, SuspendDriver.SuspendedTaskHandler.class)
+        .set(DriverConfiguration.ON_TASK_MESSAGE, SuspendDriver.TaskMessageHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, SuspendDriver.AllocatedEvaluatorHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_ACTIVE, SuspendDriver.ActiveContextHandler.class)
+        .set(DriverConfiguration.ON_CLIENT_MESSAGE, SuspendDriver.ClientMessageHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_STARTED, SuspendDriver.StartHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_STOP, SuspendDriver.StopHandler.class)
+        .build());
+
+    this.driverConfig = cb.build();
+    this.reef = reef;
+    this.controlListener = new SuspendClientControl(port);
+  }
+
+  /**
+   * Start the job driver.
+   */
+  public void submit() {
+    LOG.info("Start the job driver");
+    this.reef.submit(this.driverConfig);
+  }
+
+  /**
+   * Wait for the job to complete.
+   */
+  public void waitForCompletion() throws Exception {
+    LOG.info("Waiting for the Job Driver to complete.");
+    try {
+      synchronized (this) {
+        this.wait();
+      }
+    } catch (final InterruptedException ex) {
+      LOG.log(Level.WARNING, "Waiting for result interrupted.", ex);
+    }
+    this.reef.close();
+    this.controlListener.close();
+  }
+
+  /**
+   * Receive notification from the driver that the job is about to run.
+   * RunningJob object is a proxy to the running job driver that can be used for sending messages.
+   */
+  final class RunningJobHandler implements EventHandler<RunningJob> {
+    @Override
+    public void onNext(final RunningJob job) {
+      LOG.log(Level.INFO, "Running job: {0}", job.getId());
+      SuspendClient.this.controlListener.setRunningJob(job);
+    }
+  }
+
+  /**
+   * Receive notification from the driver that the job had failed.
+   * <p/>
+   * FailedJob is a proxy for the failed job driver
+   * (contains job ID and exception thrown from the driver).
+   */
+  final class FailedJobHandler implements EventHandler<FailedJob> {
+    @Override
+    public void onNext(final FailedJob job) {
+      LOG.log(Level.SEVERE, "Failed job: " + job.getId(), job.getReason().orElse(null));
+      synchronized (SuspendClient.this) {
+        SuspendClient.this.notify();
+      }
+    }
+  }
+
+  /**
+   * Receive notification from the driver that the job had completed successfully.
+   */
+  final class CompletedJobHandler implements EventHandler<CompletedJob> {
+    @Override
+    public void onNext(final CompletedJob job) {
+      LOG.log(Level.INFO, "Completed job: {0}", job.getId());
+      synchronized (SuspendClient.this) {
+        SuspendClient.this.notify();
+      }
+    }
+  }
+
+  /**
+   * Receive notification that there was an exception thrown from the job driver.
+   */
+  final class RuntimeErrorHandler implements EventHandler<FailedRuntime> {
+    @Override
+    public void onNext(final FailedRuntime error) {
+      LOG.log(Level.SEVERE, "ERROR: " + error, error.getReason().orElse(null));
+      synchronized (SuspendClient.class) {
+        SuspendClient.this.notify();
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/SuspendClientControl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/SuspendClientControl.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/SuspendClientControl.java
new file mode 100644
index 0000000..accb5a8
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/SuspendClientControl.java
@@ -0,0 +1,92 @@
+/**
+ * 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.reef.examples.suspend;
+
+import org.apache.reef.client.RunningJob;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.EStage;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.impl.ThreadPoolStage;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+import org.apache.reef.wake.remote.impl.TransportEvent;
+import org.apache.reef.wake.remote.transport.Transport;
+import org.apache.reef.wake.remote.transport.netty.NettyMessagingTransport;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * (Wake) listener to get suspend/resume commands from Control process.
+ */
+public class SuspendClientControl implements AutoCloseable {
+
+  private static final Logger LOG = Logger.getLogger(Control.class.getName());
+  private static final ObjectSerializableCodec<byte[]> CODEC = new ObjectSerializableCodec<>();
+  private final transient Transport transport;
+  private transient RunningJob runningJob;
+
+  @Inject
+  public SuspendClientControl(
+      final @Parameter(SuspendClientControl.Port.class) int port) throws IOException {
+
+    LOG.log(Level.INFO, "Listen to control port {0}", port);
+
+    final EStage<TransportEvent> stage = new ThreadPoolStage<>(
+        "suspend-control-server", new ControlMessageHandler(), 1, new EventHandler<Throwable>() {
+      @Override
+      public void onNext(final Throwable throwable) {
+        throw new RuntimeException(throwable);
+      }
+    });
+
+    this.transport = new NettyMessagingTransport("localhost", port, stage, stage, 1, 10000);
+  }
+
+  public synchronized void setRunningJob(final RunningJob job) {
+    this.runningJob = job;
+  }
+
+  @Override
+  public void close() throws Exception {
+    this.transport.close();
+  }
+
+  @NamedParameter(doc = "Port for suspend/resume control commands",
+      short_name = "port", default_value = "7008")
+  public static final class Port implements Name<Integer> {
+  }
+
+  /**
+   * Forward remote message to the job driver.
+   */
+  private class ControlMessageHandler implements EventHandler<TransportEvent> {
+    @Override
+    public synchronized void onNext(final TransportEvent msg) {
+      LOG.log(Level.INFO, "Control message: {0} destination: {1}",
+          new Object[]{CODEC.decode(msg.getData()), runningJob});
+      if (runningJob != null) {
+        runningJob.send(msg.getData());
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/SuspendDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/SuspendDriver.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/SuspendDriver.java
new file mode 100644
index 0000000..38d7542
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/SuspendDriver.java
@@ -0,0 +1,340 @@
+/**
+ * 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.reef.examples.suspend;
+
+import org.apache.reef.driver.client.JobMessageObserver;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorDescriptor;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.driver.task.*;
+import org.apache.reef.io.checkpoint.fs.FSCheckPointServiceConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+import org.apache.reef.wake.time.event.StartTime;
+import org.apache.reef.wake.time.event.StopTime;
+
+import javax.inject.Inject;
+import javax.xml.bind.DatatypeConverter;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Suspend/resume example job driver. Execute a simple task in all evaluators,
+ * and sendEvaluatorControlMessage suspend/resume events properly.
+ */
+@Unit
+public class SuspendDriver {
+
+  /**
+   * Standard Java logger.
+   */
+  private static final Logger LOG = Logger.getLogger(SuspendDriver.class.getName());
+
+  /**
+   * Number of evaluators to request
+   */
+  private static final int NUM_EVALUATORS = 2;
+
+  /**
+   * String codec is used to encode the results driver sends to the client.
+   */
+  private static final ObjectSerializableCodec<String> CODEC_STR = new ObjectSerializableCodec<>();
+
+  /**
+   * Integer codec is used to decode the results driver gets from the tasks.
+   */
+  private static final ObjectSerializableCodec<Integer> CODEC_INT = new ObjectSerializableCodec<>();
+
+  /**
+   * Job observer on the client.
+   * We use it to send results from the driver back to the client.
+   */
+  private final JobMessageObserver jobMessageObserver;
+
+  /**
+   * Job driver uses EvaluatorRequestor to request Evaluators that will run the Tasks.
+   */
+  private final EvaluatorRequestor evaluatorRequestor;
+
+  /**
+   * TANG Configuration of the Task.
+   */
+  private final Configuration contextConfig;
+
+  /**
+   * Map from task ID (a string) to the TaskRuntime instance (that can be suspended).
+   */
+  private final Map<String, RunningTask> runningTasks =
+      Collections.synchronizedMap(new HashMap<String, RunningTask>());
+
+  /**
+   * Map from task ID (a string) to the SuspendedTask instance (that can be resumed).
+   */
+  private final Map<String, SuspendedTask> suspendedTasks = new HashMap<>();
+
+  /**
+   * Job driver constructor.
+   * All parameters are injected from TANG automatically.
+   *
+   * @param evaluatorRequestor is used to request Evaluators.
+   * @param numCycles          number of cycles to run in the task.
+   * @param delay              delay in seconds between cycles in the task.
+   */
+  @Inject
+  SuspendDriver(
+      final JobMessageObserver jobMessageObserver,
+      final EvaluatorRequestor evaluatorRequestor,
+      final @Parameter(Launch.Local.class) boolean isLocal,
+      final @Parameter(Launch.NumCycles.class) int numCycles,
+      final @Parameter(Launch.Delay.class) int delay) {
+
+    this.jobMessageObserver = jobMessageObserver;
+    this.evaluatorRequestor = evaluatorRequestor;
+
+    try {
+
+      final Configuration checkpointServiceConfig = FSCheckPointServiceConfiguration.CONF
+          .set(FSCheckPointServiceConfiguration.IS_LOCAL, Boolean.toString(isLocal))
+          .set(FSCheckPointServiceConfiguration.PATH, "/tmp")
+          .set(FSCheckPointServiceConfiguration.PREFIX, "reef-checkpoint-")
+          .set(FSCheckPointServiceConfiguration.REPLICATION_FACTOR, "3")
+          .build();
+
+      final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder()
+          .bindNamedParameter(Launch.NumCycles.class, Integer.toString(numCycles))
+          .bindNamedParameter(Launch.Delay.class, Integer.toString(delay));
+
+      cb.addConfiguration(checkpointServiceConfig);
+      this.contextConfig = cb.build();
+
+    } catch (final BindException ex) {
+      throw new RuntimeException(ex);
+    }
+  }
+
+  /**
+   * Receive notification that the Task is ready to run.
+   */
+  final class RunningTaskHandler implements EventHandler<RunningTask> {
+    @Override
+    public final void onNext(final RunningTask task) {
+      LOG.log(Level.INFO, "Running task: {0}", task.getId());
+      runningTasks.put(task.getId(), task);
+      jobMessageObserver.sendMessageToClient(CODEC_STR.encode("start task: " + task.getId()));
+    }
+  }
+
+  /**
+   * Receive notification that the Task has completed successfully.
+   */
+  final class CompletedTaskHandler implements EventHandler<CompletedTask> {
+    @Override
+    public final void onNext(final CompletedTask task) {
+
+      final EvaluatorDescriptor e = task.getActiveContext().getEvaluatorDescriptor();
+      final String msg = "Task completed " + task.getId() + " on node " + e;
+      LOG.info(msg);
+
+      jobMessageObserver.sendMessageToClient(CODEC_STR.encode(msg));
+      runningTasks.remove(task.getId());
+      task.getActiveContext().close();
+
+      final boolean noTasks;
+
+      synchronized (suspendedTasks) {
+        LOG.log(Level.INFO, "Tasks running: {0} suspended: {1}", new Object[]{
+            runningTasks.size(), suspendedTasks.size()});
+        noTasks = runningTasks.isEmpty() && suspendedTasks.isEmpty();
+      }
+
+      if (noTasks) {
+        LOG.info("All tasks completed; shutting down.");
+      }
+    }
+  }
+
+  /**
+   * Receive notification that the Task has been suspended.
+   */
+  final class SuspendedTaskHandler implements EventHandler<SuspendedTask> {
+    @Override
+    public final void onNext(final SuspendedTask task) {
+
+      final String msg = "Task suspended: " + task.getId();
+      LOG.info(msg);
+
+      synchronized (suspendedTasks) {
+        suspendedTasks.put(task.getId(), task);
+        runningTasks.remove(task.getId());
+      }
+
+      jobMessageObserver.sendMessageToClient(CODEC_STR.encode(msg));
+    }
+  }
+
+  /**
+   * Receive message from the Task.
+   */
+  final class TaskMessageHandler implements EventHandler<TaskMessage> {
+    @Override
+    public void onNext(final TaskMessage message) {
+      final int result = CODEC_INT.decode(message.get());
+      final String msg = "Task message " + message.getId() + ": " + result;
+      LOG.info(msg);
+      jobMessageObserver.sendMessageToClient(CODEC_STR.encode(msg));
+    }
+  }
+
+  /**
+   * Receive notification that an Evaluator had been allocated,
+   * and submitTask a new Task in that Evaluator.
+   */
+  final class AllocatedEvaluatorHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator eval) {
+      try {
+
+        LOG.log(Level.INFO, "Allocated Evaluator: {0}", eval.getId());
+
+        final Configuration thisContextConfiguration = ContextConfiguration.CONF.set(
+            ContextConfiguration.IDENTIFIER, eval.getId() + "_context").build();
+
+        eval.submitContext(Tang.Factory.getTang()
+            .newConfigurationBuilder(thisContextConfiguration, contextConfig).build());
+
+      } catch (final BindException ex) {
+        throw new RuntimeException(ex);
+      }
+    }
+  }
+
+  /**
+   * Receive notification that a new Context is available.
+   * Submit a new Task to that Context.
+   */
+  final class ActiveContextHandler implements EventHandler<ActiveContext> {
+    @Override
+    public synchronized void onNext(final ActiveContext context) {
+      LOG.log(Level.INFO, "Active Context: {0}", context.getId());
+      try {
+        context.submitTask(TaskConfiguration.CONF
+            .set(TaskConfiguration.IDENTIFIER, context.getId() + "_task")
+            .set(TaskConfiguration.TASK, SuspendTestTask.class)
+            .set(TaskConfiguration.ON_SUSPEND, SuspendTestTask.SuspendHandler.class)
+            .build());
+      } catch (final BindException ex) {
+        LOG.log(Level.SEVERE, "Bad Task configuration for context: " + context.getId(), ex);
+        throw new RuntimeException(ex);
+      }
+    }
+  }
+
+  /**
+   * Handle notifications from the client.
+   */
+  final class ClientMessageHandler implements EventHandler<byte[]> {
+    @Override
+    public void onNext(final byte[] message) {
+
+      final String commandStr = CODEC_STR.decode(message);
+      LOG.log(Level.INFO, "Client message: {0}", commandStr);
+
+      final String[] split = commandStr.split("\\s+", 2);
+      if (split.length != 2) {
+        throw new IllegalArgumentException("Bad command: " + commandStr);
+      } else {
+
+        final String command = split[0].toLowerCase().intern();
+        final String taskId = split[1];
+
+        switch (command) {
+
+          case "suspend": {
+            final RunningTask task = runningTasks.get(taskId);
+            if (task != null) {
+              task.suspend();
+            } else {
+              throw new IllegalArgumentException("Suspend: Task not found: " + taskId);
+            }
+            break;
+          }
+
+          case "resume": {
+            final SuspendedTask suspendedTask;
+            synchronized (suspendedTasks) {
+              suspendedTask = suspendedTasks.remove(taskId);
+            }
+            if (suspendedTask != null) {
+              try {
+                suspendedTask.getActiveContext().submitTask(TaskConfiguration.CONF
+                    .set(TaskConfiguration.IDENTIFIER, taskId)
+                    .set(TaskConfiguration.MEMENTO,
+                        DatatypeConverter.printBase64Binary(suspendedTask.get()))
+                    .build());
+              } catch (final BindException e) {
+                throw new RuntimeException(e);
+              }
+            } else {
+              throw new IllegalArgumentException("Resume: Task not found: " + taskId);
+            }
+            break;
+          }
+
+          default:
+            throw new IllegalArgumentException("Bad command: " + command);
+        }
+      }
+    }
+  }
+
+  /**
+   * Job Driver is ready and the clock is set up: request the evaluators.
+   */
+  final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime time) {
+      LOG.log(Level.INFO, "StartTime: {0}", time);
+      evaluatorRequestor.submit(EvaluatorRequest.newBuilder()
+          .setMemory(128).setNumberOfCores(1).setNumber(NUM_EVALUATORS).build());
+    }
+  }
+
+  /**
+   * Shutting down the job driver: close the evaluators.
+   */
+  final class StopHandler implements EventHandler<StopTime> {
+    @Override
+    public void onNext(final StopTime time) {
+      LOG.log(Level.INFO, "StopTime: {0}", time);
+      jobMessageObserver.sendMessageToClient(CODEC_STR.encode("got StopTime"));
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/SuspendTestTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/SuspendTestTask.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/SuspendTestTask.java
new file mode 100644
index 0000000..5eedf1f
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/SuspendTestTask.java
@@ -0,0 +1,179 @@
+/**
+ * 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.reef.examples.suspend;
+
+import org.apache.reef.io.checkpoint.CheckpointID;
+import org.apache.reef.io.checkpoint.CheckpointService;
+import org.apache.reef.io.checkpoint.CheckpointService.CheckpointReadChannel;
+import org.apache.reef.io.checkpoint.CheckpointService.CheckpointWriteChannel;
+import org.apache.reef.io.checkpoint.fs.FSCheckpointID;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.task.Task;
+import org.apache.reef.task.TaskMessage;
+import org.apache.reef.task.TaskMessageSource;
+import org.apache.reef.task.events.SuspendEvent;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Simple do-nothing task that can send messages to the Driver and can be suspended/resumed.
+ */
+@Unit
+public class SuspendTestTask implements Task, TaskMessageSource {
+
+  /**
+   * Standard java logger.
+   */
+  private static final Logger LOG = Logger.getLogger(SuspendTestTask.class.getName());
+  private final CheckpointService checkpointService;
+  /**
+   * number of cycles to run in the task.
+   */
+  private final int numCycles;
+  /**
+   * delay in milliseconds between cycles in the task.
+   */
+  private final int delay;
+  /**
+   * Codec to serialize/deserialize counter values for the updates.
+   */
+  private final ObjectSerializableCodec<Integer> codecInt = new ObjectSerializableCodec<>();
+  /**
+   * Codec to serialize/deserialize checkpoint IDs for suspend/resume.
+   */
+  private final ObjectWritableCodec<CheckpointID> codecCheckpoint =
+      new ObjectWritableCodec<CheckpointID>(FSCheckpointID.class);
+  /**
+   * Current value of the counter.
+   */
+  private int counter = 0;
+  /**
+   * True if the suspend message has been received, false otherwise.
+   */
+  private boolean suspended = false;
+
+  /**
+   * Task constructor: invoked by TANG.
+   *
+   * @param numCycles number of cycles to run in the task.
+   * @param delay     delay in seconds between cycles in the task.
+   */
+  @Inject
+  public SuspendTestTask(
+      final CheckpointService checkpointService,
+      @Parameter(Launch.NumCycles.class) final int numCycles,
+      @Parameter(Launch.Delay.class) final int delay) {
+    this.checkpointService = checkpointService;
+    this.numCycles = numCycles;
+    this.delay = delay * 1000;
+  }
+
+  /**
+   * Main method of the task: run cycle from 0 to numCycles,
+   * and sleep for delay seconds on each cycle.
+   *
+   * @param memento serialized version of the counter.
+   *                Empty array for initial run, but can contain value for resumed job.
+   * @return serialized version of the counter.
+   */
+  @Override
+  public synchronized byte[] call(final byte[] memento) throws IOException, InterruptedException {
+
+    LOG.log(Level.INFO, "Start: {0} counter: {1}/{2}",
+        new Object[]{this, this.counter, this.numCycles});
+
+    if (memento != null && memento.length > 0) {
+      this.restore(memento);
+    }
+
+    this.suspended = false;
+    for (; this.counter < this.numCycles && !this.suspended; ++this.counter) {
+      try {
+        LOG.log(Level.INFO, "Run: {0} counter: {1}/{2} sleep: {3}",
+            new Object[]{this, this.counter, this.numCycles, this.delay});
+        this.wait(this.delay);
+      } catch (final InterruptedException ex) {
+        LOG.log(Level.INFO, "{0} interrupted. counter: {1}: {2}",
+            new Object[]{this, this.counter, ex});
+      }
+    }
+
+    return this.suspended ? this.save() : this.codecInt.encode(this.counter);
+  }
+
+  /**
+   * Update driver on current state of the task.
+   *
+   * @return serialized version of the counter.
+   */
+  @Override
+  public synchronized Optional<TaskMessage> getMessage() {
+    LOG.log(Level.INFO, "Message from Task {0} to the Driver: counter: {1}",
+        new Object[]{this, this.counter});
+    return Optional.of(TaskMessage.from(SuspendTestTask.class.getName(), this.codecInt.encode(this.counter)));
+  }
+
+  /**
+   * Save current state of the task in the checkpoint.
+   *
+   * @return checkpoint ID (serialized)
+   */
+  private synchronized byte[] save() throws IOException, InterruptedException {
+    try (final CheckpointWriteChannel channel = this.checkpointService.create()) {
+      channel.write(ByteBuffer.wrap(this.codecInt.encode(this.counter)));
+      return this.codecCheckpoint.encode(this.checkpointService.commit(channel));
+    }
+  }
+
+  /**
+   * Restore the task state from the given checkpoint.
+   *
+   * @param memento serialized checkpoint ID
+   */
+  private synchronized void restore(final byte[] memento) throws IOException, InterruptedException {
+    final CheckpointID checkpointId = this.codecCheckpoint.decode(memento);
+    try (final CheckpointReadChannel channel = this.checkpointService.open(checkpointId)) {
+      final ByteBuffer buffer = ByteBuffer.wrap(this.codecInt.encode(this.counter));
+      channel.read(buffer);
+      this.counter = this.codecInt.decode(buffer.array());
+    }
+    this.checkpointService.delete(checkpointId);
+  }
+
+  public class SuspendHandler implements EventHandler<SuspendEvent> {
+
+    @Override
+    public void onNext(SuspendEvent suspendEvent) {
+      final byte[] message = suspendEvent.get().get();
+      LOG.log(Level.INFO, "Suspend: {0} with: {1} bytes; counter: {2}",
+          new Object[]{this, message.length, SuspendTestTask.this.counter});
+      SuspendTestTask.this.suspended = true;
+      SuspendTestTask.this.notify();
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/package-info.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/package-info.java
new file mode 100644
index 0000000..9017daa
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/suspend/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * suspend/resume demo.
+ */
+package org.apache.reef.examples.suspend;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/utils/wake/BlockingEventHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/utils/wake/BlockingEventHandler.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/utils/wake/BlockingEventHandler.java
new file mode 100644
index 0000000..e6a5d6c
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/utils/wake/BlockingEventHandler.java
@@ -0,0 +1,63 @@
+/**
+ * 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.reef.examples.utils.wake;
+
+import org.apache.reef.wake.EventHandler;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An EventHandler that blocks until a set number of Events has been received.
+ * Once they have been received, the downstream event handler is called with an
+ * Iterable of the events spooled.
+ *
+ * @param <T>
+ */
+public final class BlockingEventHandler<T> implements EventHandler<T> {
+
+  private final int expectedSize;
+  private final EventHandler<Iterable<T>> destination;
+  private List<T> events = new ArrayList<>();
+
+  public BlockingEventHandler(final int expectedSize, final EventHandler<Iterable<T>> destination) {
+    this.expectedSize = expectedSize;
+    this.destination = destination;
+  }
+
+  @Override
+  public final void onNext(final T event) {
+    if (this.isComplete()) {
+      throw new IllegalStateException("Received more Events than expected");
+    }
+    this.events.add(event);
+    if (this.isComplete()) {
+      this.destination.onNext(events);
+      this.reset();
+    }
+  }
+
+  private boolean isComplete() {
+    return this.events.size() >= expectedSize;
+  }
+
+  private void reset() {
+    this.events = new ArrayList<>();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/utils/wake/LoggingEventHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/utils/wake/LoggingEventHandler.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/utils/wake/LoggingEventHandler.java
new file mode 100644
index 0000000..9d2d5b8
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/utils/wake/LoggingEventHandler.java
@@ -0,0 +1,58 @@
+/**
+ * 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.reef.examples.utils.wake;
+
+import org.apache.reef.wake.EventHandler;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * An EventHandler that logs its events before handing it to a downstream
+ * EventHandler.
+ *
+ * @param <T>
+ */
+public class LoggingEventHandler<T> implements EventHandler<T> {
+
+  private final EventHandler<T> downstreamEventHandler;
+  private final String prefix;
+  private final String suffix;
+
+  /**
+   * @param prefix                 to be logged before the event
+   * @param downstreamEventHandler the event handler to hand the event to
+   * @param suffix                 to be logged after the event
+   */
+  public LoggingEventHandler(final String prefix, EventHandler<T> downstreamEventHandler, final String suffix) {
+    this.downstreamEventHandler = downstreamEventHandler;
+    this.prefix = prefix;
+    this.suffix = suffix;
+  }
+
+  public LoggingEventHandler(final EventHandler<T> downstreamEventHandler) {
+    this("", downstreamEventHandler, "");
+  }
+
+  @Override
+  public void onNext(final T value) {
+    Logger.getLogger(LoggingEventHandler.class.getName()).log(Level.INFO, prefix + value.toString() + suffix);
+    this.downstreamEventHandler.onNext(value);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/test/java/org/apache/reef/examples/hello/HelloHttpTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/test/java/org/apache/reef/examples/hello/HelloHttpTest.java b/lang/java/reef-examples/src/test/java/org/apache/reef/examples/hello/HelloHttpTest.java
new file mode 100644
index 0000000..14812ca
--- /dev/null
+++ b/lang/java/reef-examples/src/test/java/org/apache/reef/examples/hello/HelloHttpTest.java
@@ -0,0 +1,41 @@
+/**
+ * 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.reef.examples.hello;
+
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.examples.hellohttp.HelloREEFHttp;
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class HelloHttpTest {
+  @Test
+  public void testHttpServer() throws BindException, InjectionException {
+
+    final Configuration runtimeConfiguration = LocalRuntimeConfiguration.CONF
+        .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, 2)
+        .build();
+
+    final LauncherStatus status = HelloREEFHttp.runHelloReef(runtimeConfiguration, 10 * 1000);
+    Assert.assertEquals(LauncherStatus.FORCE_CLOSED, status); // must be force closed by timeout
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/test/java/org/apache/reef/examples/suspend/ObjectWritableCodecTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/test/java/org/apache/reef/examples/suspend/ObjectWritableCodecTest.java b/lang/java/reef-examples/src/test/java/org/apache/reef/examples/suspend/ObjectWritableCodecTest.java
new file mode 100644
index 0000000..827d57a
--- /dev/null
+++ b/lang/java/reef-examples/src/test/java/org/apache/reef/examples/suspend/ObjectWritableCodecTest.java
@@ -0,0 +1,50 @@
+/**
+ * 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.reef.examples.suspend;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.reef.io.checkpoint.CheckpointID;
+import org.apache.reef.io.checkpoint.fs.FSCheckpointID;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ObjectWritableCodecTest {
+
+  private static ObjectWritableCodec<CheckpointID> codec;
+
+  /**
+   * Test class setup - create the codec.
+   */
+  @BeforeClass
+  public static void setUpClass() {
+    codec = new ObjectWritableCodec<CheckpointID>(FSCheckpointID.class);
+  }
+
+  /**
+   * After the encode/decode cycle result equals to the original object.
+   */
+  @Test
+  public void testFSCheckpointIdCodec() {
+    final CheckpointID checkpoint1 = new FSCheckpointID(new Path("path"));
+    final byte[] serialized = codec.encode(checkpoint1);
+    final CheckpointID checkpoint2 = codec.decode(serialized);
+    Assert.assertEquals(checkpoint1, checkpoint2);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/pom.xml b/lang/java/reef-io/pom.xml
new file mode 100644
index 0000000..c517e38
--- /dev/null
+++ b/lang/java/reef-io/pom.xml
@@ -0,0 +1,143 @@
+<?xml version="1.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.
+-->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+         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.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+    <artifactId>reef-io</artifactId>
+    <name>REEF IO</name>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-antrun-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>generate-sources</id>
+                        <phase>generate-sources</phase>
+                        <configuration>
+                            <tasks>
+                                <mkdir dir="target/generated-sources/proto"/>
+                                <exec executable="protoc">
+                                    <arg value="--proto_path=src/main/proto/"/>
+                                    <arg value="--java_out=target/generated-sources/proto"/>
+                                    <arg value="src/main/proto/ns_protocol.proto"/>
+                                </exec>
+                            </tasks>
+                            <sourceRoot>target/generated-sources/proto</sourceRoot>
+                        </configuration>
+                        <goals>
+                            <goal>run</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>add-source</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>target/generated-sources/proto</source>
+                                <source>target/generated-sources/avro</source>
+                            </sources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.avro</groupId>
+                <artifactId>avro-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-webserver</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.avro</groupId>
+            <artifactId>avro</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+        <!-- HADOOP -->
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-common</artifactId>
+            <version>${hadoop.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-yarn-common</artifactId>
+            <version>${hadoop.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-yarn</artifactId>
+            <version>${hadoop.version}</version>
+            <type>pom</type>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-hdfs</artifactId>
+            <version>${hadoop.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-yarn-client</artifactId>
+            <version>${hadoop.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-minicluster</artifactId>
+            <version>${hadoop.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <!-- END OF HADOOP -->
+    </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/avro/nameservice.avsc
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/avro/nameservice.avsc b/lang/java/reef-io/src/main/avro/nameservice.avsc
new file mode 100644
index 0000000..9a10478
--- /dev/null
+++ b/lang/java/reef-io/src/main/avro/nameservice.avsc
@@ -0,0 +1,64 @@
+/**
+ * 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.
+ */
+ [
+{
+    "namespace":"org.apache.reef.io.network.naming.avro",
+    "type":"record",
+    "name":"AvroNamingLookupRequest",
+    "fields":[
+	   {"name":"ids","type":{"type":"array", "items":"string"}}
+    ]
+},
+{
+    "namespace":"org.apache.reef.io.network.naming.avro",
+    "type":"record",
+    "name":"AvroNamingAssignment",
+    "fields":[
+	   {"name":"id","type":"string"},
+	   {"name":"host","type":"string"},
+     {"name":"port","type":"int"}
+    ]
+},
+{
+    "namespace":"org.apache.reef.io.network.naming.avro",
+    "type":"record",
+    "name":"AvroNamingLookupResponse",
+    "fields":[
+	   {"name":"tuples","type":{"type":"array", "items":"AvroNamingAssignment"}}
+    ]
+},
+{
+    "namespace":"org.apache.reef.io.network.naming.avro",
+    "type":"record",
+    "name":"AvroNamingRegisterRequest",
+    "fields":[
+	   {"name":"id","type":"string"},
+	   {"name":"host","type":"string"},
+     {"name":"port","type":"int"}
+    ]
+},
+{
+    "namespace":"org.apache.reef.io.network.naming.avro",
+    "type":"record",
+    "name":"AvroNamingUnRegisterRequest",
+    "fields":[
+	   {"name":"id","type":"string"}
+    ]
+}
+]

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataLoader.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataLoader.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataLoader.java
new file mode 100644
index 0000000..632a349
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataLoader.java
@@ -0,0 +1,236 @@
+/**
+ * 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.reef.io.data.loading.api;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.driver.evaluator.FailedEvaluator;
+import org.apache.reef.io.data.loading.impl.EvaluatorRequestSerializer;
+import org.apache.reef.io.network.util.Pair;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.impl.SingleThreadStage;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.event.Alarm;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The driver component for the DataLoadingService
+ * Also acts as the central point for resource requests
+ * All the allocated evaluators pass through this and
+ * the ones that need data loading have a context stacked
+ * that enables a task to get access to Data via the
+ * {@link DataSet}.
+ * <p/>
+ * TODO: Add timeouts
+ */
+@DriverSide
+@Unit
+public class DataLoader {
+
+  private static final Logger LOG = Logger.getLogger(DataLoader.class.getName());
+
+  private final ConcurrentMap<String, Pair<Configuration, Configuration>> submittedDataEvalConfigs = new ConcurrentHashMap<>();
+  private final ConcurrentMap<String, Configuration> submittedComputeEvalConfigs = new ConcurrentHashMap<>();
+  private final BlockingQueue<Configuration> failedComputeEvalConfigs = new LinkedBlockingQueue<>();
+  private final BlockingQueue<Pair<Configuration, Configuration>> failedDataEvalConfigs = new LinkedBlockingQueue<>();
+
+  private final AtomicInteger numComputeRequestsToSubmit = new AtomicInteger(0);
+
+  private final DataLoadingService dataLoadingService;
+  private final int dataEvalMemoryMB;
+  private final int dataEvalCore;
+  private final EvaluatorRequest computeRequest;
+  private final SingleThreadStage<EvaluatorRequest> resourceRequestStage;
+  private final ResourceRequestHandler resourceRequestHandler;
+  private final int computeEvalMemoryMB;
+  private final int computeEvalCore;
+  private final EvaluatorRequestor requestor;
+
+  @Inject
+  public DataLoader(
+      final Clock clock,
+      final EvaluatorRequestor requestor,
+      final DataLoadingService dataLoadingService,
+      final @Parameter(DataLoadingRequestBuilder.DataLoadingEvaluatorMemoryMB.class) int dataEvalMemoryMB,
+      final @Parameter(DataLoadingRequestBuilder.DataLoadingEvaluatorNumberOfCores.class) int dataEvalCore,
+      final @Parameter(DataLoadingRequestBuilder.DataLoadingComputeRequest.class) String serializedComputeRequest) {
+
+    // FIXME: Issue #855: We need this alarm to look busy for REEF.
+    clock.scheduleAlarm(30000, new EventHandler<Alarm>() {
+      @Override
+      public void onNext(final Alarm time) {
+        LOG.log(Level.FINE, "Received Alarm: {0}", time);
+      }
+    });
+
+    this.requestor = requestor;
+    this.dataLoadingService = dataLoadingService;
+    this.dataEvalMemoryMB = dataEvalMemoryMB;
+    this.dataEvalCore = dataEvalCore;
+    this.resourceRequestHandler = new ResourceRequestHandler(requestor);
+    this.resourceRequestStage = new SingleThreadStage<>(this.resourceRequestHandler, 2);
+
+    if (serializedComputeRequest.equals("NULL")) {
+      this.computeRequest = null;
+      this.computeEvalMemoryMB = -1;
+      computeEvalCore = 1;
+    } else {
+      this.computeRequest = EvaluatorRequestSerializer.deserialize(serializedComputeRequest);
+      this.computeEvalMemoryMB = this.computeRequest.getMegaBytes();
+      this.computeEvalCore = this.computeRequest.getNumberOfCores();
+      this.numComputeRequestsToSubmit.set(this.computeRequest.getNumber());
+
+      this.resourceRequestStage.onNext(this.computeRequest);
+    }
+
+    this.resourceRequestStage.onNext(getDataLoadingRequest());
+  }
+
+  private EvaluatorRequest getDataLoadingRequest() {
+    return EvaluatorRequest.newBuilder()
+        .setNumber(this.dataLoadingService.getNumberOfPartitions())
+        .setMemory(this.dataEvalMemoryMB)
+        .setNumberOfCores(this.dataEvalCore)
+        .build();
+  }
+
+  public class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime startTime) {
+      LOG.log(Level.INFO, "StartTime: {0}", startTime);
+      resourceRequestHandler.releaseResourceRequestGate();
+    }
+  }
+
+  public class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+
+    @Override
+    public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+
+      final String evalId = allocatedEvaluator.getId();
+      LOG.log(Level.FINEST, "Allocated evaluator: {0}", evalId);
+
+      if (!failedComputeEvalConfigs.isEmpty()) {
+        LOG.log(Level.FINE, "Failed Compute requests need to be satisfied for {0}", evalId);
+        final Configuration conf = failedComputeEvalConfigs.poll();
+        if (conf != null) {
+          LOG.log(Level.FINE, "Satisfying failed configuration for {0}", evalId);
+          allocatedEvaluator.submitContext(conf);
+          submittedComputeEvalConfigs.put(evalId, conf);
+          return;
+        }
+      }
+
+      if (!failedDataEvalConfigs.isEmpty()) {
+        LOG.log(Level.FINE, "Failed Data requests need to be satisfied for {0}", evalId);
+        final Pair<Configuration, Configuration> confPair = failedDataEvalConfigs.poll();
+        if (confPair != null) {
+          LOG.log(Level.FINE, "Satisfying failed configuration for {0}", evalId);
+          allocatedEvaluator.submitContextAndService(confPair.first, confPair.second);
+          submittedDataEvalConfigs.put(evalId, confPair);
+          return;
+        }
+      }
+
+      final int evaluatorsForComputeRequest = numComputeRequestsToSubmit.decrementAndGet();
+      LOG.log(Level.FINE, "Evaluators for compute request: {0}", evaluatorsForComputeRequest);
+
+      if (evaluatorsForComputeRequest >= 0) {
+        try {
+          final Configuration idConfiguration = ContextConfiguration.CONF
+              .set(ContextConfiguration.IDENTIFIER,
+                  dataLoadingService.getComputeContextIdPrefix() + evaluatorsForComputeRequest)
+              .build();
+          LOG.log(Level.FINE, "Submitting Compute Context to {0}", evalId);
+          allocatedEvaluator.submitContext(idConfiguration);
+          submittedComputeEvalConfigs.put(allocatedEvaluator.getId(), idConfiguration);
+          if (evaluatorsForComputeRequest == 0) {
+            LOG.log(Level.FINE, "All Compute requests satisfied. Releasing gate");
+            resourceRequestHandler.releaseResourceRequestGate();
+          }
+        } catch (final BindException e) {
+          throw new RuntimeException("Unable to bind context id for Compute request", e);
+        }
+
+      } else {
+
+        final Pair<Configuration, Configuration> confPair = new Pair<>(
+            dataLoadingService.getContextConfiguration(allocatedEvaluator),
+            dataLoadingService.getServiceConfiguration(allocatedEvaluator));
+
+        LOG.log(Level.FINE, "Submitting data loading context to {0}", evalId);
+        allocatedEvaluator.submitContextAndService(confPair.first, confPair.second);
+        submittedDataEvalConfigs.put(allocatedEvaluator.getId(), confPair);
+      }
+    }
+  }
+
+  public class EvaluatorFailedHandler implements EventHandler<FailedEvaluator> {
+    @Override
+    public void onNext(final FailedEvaluator failedEvaluator) {
+
+      final String evalId = failedEvaluator.getId();
+
+      final Configuration computeConfig = submittedComputeEvalConfigs.remove(evalId);
+      if (computeConfig != null) {
+
+        LOG.log(Level.INFO, "Received failed compute evaluator: {0}", evalId);
+        failedComputeEvalConfigs.add(computeConfig);
+
+        requestor.submit(EvaluatorRequest.newBuilder()
+            .setMemory(computeEvalMemoryMB).setNumber(1).setNumberOfCores(computeEvalCore).build());
+
+      } else {
+
+        final Pair<Configuration, Configuration> confPair = submittedDataEvalConfigs.remove(evalId);
+        if (confPair != null) {
+
+          LOG.log(Level.INFO, "Received failed data evaluator: {0}", evalId);
+          failedDataEvalConfigs.add(confPair);
+
+          requestor.submit(EvaluatorRequest.newBuilder()
+              .setMemory(dataEvalMemoryMB).setNumber(1).setNumberOfCores(dataEvalCore).build());
+
+        } else {
+
+          LOG.log(Level.SEVERE, "Received unknown failed evaluator " + evalId,
+              failedEvaluator.getEvaluatorException());
+
+          throw new RuntimeException("Received failed evaluator that I did not submit: " + evalId);
+        }
+      }
+    }
+  }
+}


[44/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/ResourceManagerErrorHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/ResourceManagerErrorHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/ResourceManagerErrorHandler.java
new file mode 100644
index 0000000..61b958e
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/ResourceManagerErrorHandler.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.client.parameters;
+
+import org.apache.reef.client.FailedRuntime;
+import org.apache.reef.runtime.common.client.defaults.DefaultRuntimeErrorHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ * Client EventHandler triggered on resource manager error.
+ */
+@NamedParameter(doc = "Client EventHandler triggered on resource manager error.",
+    default_classes = DefaultRuntimeErrorHandler.class)
+public final class ResourceManagerErrorHandler implements Name<EventHandler<FailedRuntime>> {
+  private ResourceManagerErrorHandler() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/package-info.java
new file mode 100644
index 0000000..af1ae50
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Named parameters for the REEF client API.
+ */
+package org.apache.reef.client.parameters;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/common/AbstractFailure.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/common/AbstractFailure.java b/lang/java/reef-common/src/main/java/org/apache/reef/common/AbstractFailure.java
new file mode 100644
index 0000000..80cf4ac
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/common/AbstractFailure.java
@@ -0,0 +1,151 @@
+/**
+ * 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.reef.common;
+
+import org.apache.reef.util.Optional;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * Common data and functionality for all error messages in REEF.
+ */
+public abstract class AbstractFailure implements Failure {
+
+  /**
+   * Identifier of the entity that produced the error. Cannot be null.
+   */
+  protected final String id;
+
+  /**
+   * One-line error message. For wrapped exceptions, this equals
+   * to the Exception.getMessage() result. Cannot be null.
+   */
+  protected final String message;
+
+  /**
+   * Optional error description (long).
+   * For exceptions it is by default populates with the stack trace.
+   */
+  protected final Optional<String> description;
+
+  /**
+   * Optional Java exception that caused the error.
+   */
+  protected final Optional<Throwable> cause;
+
+  /**
+   * Optional byte array that contains serialized version of the exception.
+   */
+  protected final Optional<byte[]> data;
+
+  /**
+   * @param id          Identifier of the entity that produced the error. Cannot be null.
+   * @param message     One-line error message. Cannot be null.
+   * @param description Long error description. Can be null.
+   * @param cause       Java Exception that caused the error. Can be null.
+   * @param data        byte array that contains serialized version of the error. Can be null.
+   */
+  protected AbstractFailure(final String id,
+                            final String message,
+                            final Optional<String> description,
+                            final Optional<Throwable> cause,
+                            final Optional<byte[]> data) {
+    this.id = id;
+    this.message = message;
+    this.description = description;
+    this.cause = cause;
+    this.data = data;
+  }
+
+
+  /**
+   * Helper function: produce the string that contains the given exception's stack trace.
+   * Returns null if the argument is null.
+   *
+   * @param cause Java Exception or null.
+   * @return A string that contains the exception stack trace, or null.
+   */
+  protected static String getStackTrace(final Throwable cause) {
+    if (cause == null) {
+      return null;
+    } else {
+      final StringWriter writer = new StringWriter();
+      cause.printStackTrace(new PrintWriter(writer));
+      return writer.toString();
+    }
+  }
+
+  /**
+   * @return Identifier of the entity that produced the error. Never null.
+   */
+  @Override
+  public String getId() {
+    return this.id;
+  }
+
+  /**
+   * @return One-line error message. Never null.
+   */
+  @Override
+  public String getMessage() {
+    return this.message;
+  }
+
+  /**
+   * @return Optional long error description. For Java Exceptions, can contain stack trace.
+   */
+  @Override
+  public Optional<String> getDescription() {
+    return this.description;
+  }
+
+  @Override
+  public Optional<Throwable> getReason() {
+    return this.cause;
+  }
+
+  /**
+   * @return Optional serialized version of the error message.
+   */
+  @Override
+  public Optional<byte[]> getData() {
+    return this.data;
+  }
+
+  /**
+   * Return the original Java Exception, or generate a new one if it does not exists.
+   * ALWAYS returns an exception.
+   * FIXME: Replace RuntimeException with a better class.
+   *
+   * @return A java exception. Never null.
+   */
+  @Override
+  public Throwable asError() {
+    return this.cause.isPresent() ? this.cause.get() : new RuntimeException(this.toString());
+  }
+
+  /**
+   * @return Human-readable string representation of an error message.
+   */
+  @Override
+  public String toString() {
+    return this.getClass().getName() + " id=" + this.getId() + " failed: " + this.getMessage();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/common/Failure.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/common/Failure.java b/lang/java/reef-common/src/main/java/org/apache/reef/common/Failure.java
new file mode 100644
index 0000000..211f971
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/common/Failure.java
@@ -0,0 +1,58 @@
+/**
+ * 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.reef.common;
+
+import org.apache.reef.io.naming.Identifiable;
+import org.apache.reef.util.Optional;
+
+/**
+ * Common interface for all error messages in REEF.
+ * Most of its functionality is generic and implemented in the AbstractFailure class.
+ */
+public interface Failure extends Identifiable {
+
+  /**
+   * @return One-line error message. Should never be null.
+   */
+  String getMessage();
+
+  /**
+   * @return Optional long error description.
+   */
+  Optional<String> getDescription();
+
+  /**
+   * @return Java Exception that caused the error, if any.
+   */
+  Optional<Throwable> getReason();
+
+
+  /**
+   * @return Optional serialized version of the error message.
+   */
+  Optional<byte[]> getData();
+
+  /**
+   * Return the original Java Exception, or generate a new one if it does not exists.
+   * ALWAYS returns an exception.
+   *
+   * @return A java exception. Never null.
+   */
+  Throwable asError();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/ContextAndTaskSubmittable.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/ContextAndTaskSubmittable.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/ContextAndTaskSubmittable.java
new file mode 100644
index 0000000..5bd62e5
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/ContextAndTaskSubmittable.java
@@ -0,0 +1,64 @@
+/**
+ * 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.reef.driver;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.tang.Configuration;
+
+/**
+ * Base interface for classes that support the simultaneous submission of both Context and Task configurations.
+ */
+@DriverSide
+@Provided
+@Public
+public interface ContextAndTaskSubmittable {
+  /**
+   * Submit a Context and a Task.
+   * <p/>
+   * The semantics of this call are the same as first submitting the context and then, on the fired ActiveContext event
+   * to submit the Task. The performance of this will be better, though as it potentially saves some roundtrips on
+   * the network.
+   * <p/>
+   * REEF will not fire an ActiveContext as a result of this. Instead, it will fire a TaskRunning event.
+   *
+   * @param contextConfiguration the Configuration of the EvaluatorContext. See ContextConfiguration for details.
+   * @param taskConfiguration    the Configuration of the Task. See TaskConfiguration for details.
+   */
+  public void submitContextAndTask(final Configuration contextConfiguration, final Configuration taskConfiguration);
+
+  /**
+   * Subkit a Context with Services and a Task.
+   * <p/>
+   * The semantics of this call are the same as first submitting the context and services and then, on the fired
+   * ActiveContext event to submit the Task. The performance of this will be better, though as it potentially saves
+   * some roundtrips on the network.
+   * <p/>
+   * REEF will not fire an ActiveContext as a result of this. Instead, it will fire a TaskRunning event.
+   *
+   * @param contextConfiguration
+   * @param serviceConfiguration
+   * @param taskConfiguration
+   */
+  public void submitContextAndServiceAndTask(final Configuration contextConfiguration,
+                                             final Configuration serviceConfiguration,
+                                             final Configuration taskConfiguration);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/ContextSubmittable.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/ContextSubmittable.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/ContextSubmittable.java
new file mode 100644
index 0000000..f9721fa
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/ContextSubmittable.java
@@ -0,0 +1,49 @@
+/**
+ * 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.reef.driver;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.tang.Configuration;
+
+/**
+ * Base interface for classes that support Context submission.
+ */
+@DriverSide
+@Provided
+@Public
+public interface ContextSubmittable {
+
+  /**
+   * Submit a Context.
+   *
+   * @param contextConfiguration the Configuration of the EvaluatorContext. See ContextConfiguration for details.
+   */
+  public void submitContext(final Configuration contextConfiguration);
+
+  /**
+   * Submit a Context and a Service Configuration.
+   *
+   * @param contextConfiguration the Configuration of the EvaluatorContext. See ContextConfiguration for details.
+   * @param serviceConfiguration the Configuration for the Services. See ServiceConfiguration for details.
+   */
+  public void submitContextAndService(final Configuration contextConfiguration, final Configuration serviceConfiguration);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/FlexiblePreemptionEvent.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/FlexiblePreemptionEvent.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/FlexiblePreemptionEvent.java
new file mode 100644
index 0000000..a9aeaf7
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/FlexiblePreemptionEvent.java
@@ -0,0 +1,47 @@
+/**
+ * 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.reef.driver;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.Unstable;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+
+import java.util.Set;
+
+/**
+ * Represents a flexible preemption request: It contains:
+ * <p/>
+ * <ol>
+ * <li>a set of EvaluatorRequests that the resource manager wants to have satisfied and also</li>
+ * <li>a set of Evaluators it will choose to kill if the request isn't satisfied otherwise.</li>
+ * </ol>
+ * <p/>
+ * NOTE: This currently not implemented. Consider it a preview of the API.
+ */
+@Private
+@Provided
+@Unstable
+public interface FlexiblePreemptionEvent extends PreemptionEvent {
+
+  /**
+   * @return the set of EvaluatorRequests that the underlying resource manager seeks to satisfy.
+   */
+  public Set<EvaluatorRequest> getEvaluatorRequest();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/PreemptionEvent.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/PreemptionEvent.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/PreemptionEvent.java
new file mode 100644
index 0000000..2d84d01
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/PreemptionEvent.java
@@ -0,0 +1,47 @@
+/**
+ * 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.reef.driver;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.Unstable;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+
+/**
+ * Represents Preemption requests issued by the underlying resource manager.
+ * <p/>
+ * REEF exposes two kinds of preemption requests: Strict ones merely inform the Driver about machines that are about to
+ * be preempted. Flexible ones provide that list, but also expose the resource request that the underlying resource
+ * manager wants to satisfy, thereby giving the Driver a chance to satisfy it in another way.
+ * <p/>
+ * NOTE: This currently not implemented. Consider it a preview of the API.
+ */
+@DriverSide
+@Public
+@Provided
+@Unstable
+public interface PreemptionEvent {
+
+  /**
+   * @return the Set of RunningEvaluators that the underlying resource manager is about to take away from the Driver.
+   */
+  // TODO: We need to have a set of things to present to the user as preempted. Probably a Set<String> with the Evaluator IDs.
+  // public Set<RunningEvaluator> getToBePreemptedEvaluators();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/PreemptionHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/PreemptionHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/PreemptionHandler.java
new file mode 100644
index 0000000..db15d13
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/PreemptionHandler.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.driver;
+
+import org.apache.reef.annotations.Optional;
+import org.apache.reef.annotations.Unstable;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ * This EventHandler will receive preemption events from the underlying resourcemanager.
+ * NOTE: This currently not implemented. Consider it a preview of the API.
+ */
+@DriverSide
+@Public
+@Optional
+@Unstable
+public interface PreemptionHandler extends EventHandler<PreemptionEvent> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/StrictPreemptionEvent.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/StrictPreemptionEvent.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/StrictPreemptionEvent.java
new file mode 100644
index 0000000..99e8bfb
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/StrictPreemptionEvent.java
@@ -0,0 +1,37 @@
+/**
+ * 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.reef.driver;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.Unstable;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+
+/**
+ * Represents a strict preemption event: It contains the set of Evaluators that the underlying resource manager will
+ * take away from the Driver.
+ * <p/>
+ * NOTE: This currently not implemented. Consider it a preview of the API.
+ */
+@Unstable
+@DriverSide
+@Public
+@Provided
+public interface StrictPreemptionEvent extends PreemptionEvent {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/TaskSubmittable.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/TaskSubmittable.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/TaskSubmittable.java
new file mode 100644
index 0000000..22f8e8d
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/TaskSubmittable.java
@@ -0,0 +1,40 @@
+/**
+ * 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.reef.driver;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.tang.Configuration;
+
+/**
+ * Base interface for classes that support Task submission.
+ */
+@DriverSide
+@Provided
+@Public
+public interface TaskSubmittable {
+
+  /**
+   * Submits a Task (encoded in the Configuration) for execution.
+   *
+   * @param taskConf the Configuration. See TaskConfiguration for details
+   */
+  public void submitTask(final Configuration taskConf);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/catalog/NodeDescriptor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/catalog/NodeDescriptor.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/catalog/NodeDescriptor.java
new file mode 100644
index 0000000..f222df8
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/catalog/NodeDescriptor.java
@@ -0,0 +1,42 @@
+/**
+ * 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.reef.driver.catalog;
+
+import org.apache.reef.annotations.Unstable;
+import org.apache.reef.io.naming.Identifiable;
+
+import java.net.InetSocketAddress;
+
+/**
+ * Descriptor of the physical setup of an Evaluator.
+ */
+@Unstable
+public interface NodeDescriptor extends ResourceCatalog.Descriptor, Identifiable {
+  /**
+   * Access the inet address of the Evaluator.
+   *
+   * @return the inet address of the Evaluator.
+   */
+  public InetSocketAddress getInetSocketAddress();
+
+  /**
+   * @return the rack descriptor that contains this node
+   */
+  public RackDescriptor getRackDescriptor();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/catalog/RackDescriptor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/catalog/RackDescriptor.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/catalog/RackDescriptor.java
new file mode 100644
index 0000000..cb34005
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/catalog/RackDescriptor.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.catalog;
+
+import org.apache.reef.annotations.Unstable;
+
+import java.util.List;
+
+/**
+ * A rack in the cluster.
+ */
+@Unstable
+public interface RackDescriptor extends ResourceCatalog.Descriptor {
+
+  /**
+   * @return the list of nodes in this rack.
+   */
+  public List<NodeDescriptor> getNodes();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/catalog/ResourceCatalog.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/catalog/ResourceCatalog.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/catalog/ResourceCatalog.java
new file mode 100644
index 0000000..62f4d6b
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/catalog/ResourceCatalog.java
@@ -0,0 +1,65 @@
+/**
+ * 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.reef.driver.catalog;
+
+import org.apache.reef.annotations.Unstable;
+
+import java.util.Collection;
+
+/**
+ * A catalog of the resources available to a REEF instance.
+ * <p/>
+ * This catalog contains static information about the resources and does not
+ * reflect that dynamic availability of resources. In other words: Its entries
+ * are an upper bound to what is available to a REEF {@link Driver} at any given
+ * moment in time.
+ */
+@Unstable
+public interface ResourceCatalog {
+
+  /**
+   * The global list of resources.
+   *
+   * @return a list of all the static resources available. This is an upper
+   * bound.
+   */
+  public Collection<NodeDescriptor> getNodes();
+
+  /**
+   * The global list of racks
+   *
+   * @return list of all rack descriptors
+   */
+  public Collection<RackDescriptor> getRacks();
+
+  /**
+   * Get the node descriptor with the given identifier.
+   *
+   * @param id of the node.
+   * @return the node descriptor assigned to the identifier.
+   */
+  public NodeDescriptor getNode(String nodeId);
+
+  public interface Descriptor {
+
+    public String getName();
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/client/JobMessageObserver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/client/JobMessageObserver.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/client/JobMessageObserver.java
new file mode 100644
index 0000000..3cc3b0b
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/client/JobMessageObserver.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.driver.client;
+
+import org.apache.reef.annotations.Optional;
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+
+/**
+ * The driver uses this interface to communicate with the job client.
+ * <p/>
+ * Note that as of REEF 0.4, the presence of a client is no longer guaranteed, depending on the deployment environment.
+ */
+@Public
+@DriverSide
+@Provided
+@Optional
+public interface JobMessageObserver {
+
+  /**
+   * Send a message to the client.
+   *
+   * @param message a message to be sent to the client
+   */
+  public void sendMessageToClient(final byte[] message);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/client/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/client/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/client/package-info.java
new file mode 100644
index 0000000..c68dabf
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/client/package-info.java
@@ -0,0 +1,25 @@
+/**
+ * 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.
+ */
+/**
+ * Representations of the Client (i.e. the job submitter) to a Driver.
+ * Note that as of REEF 0.3, the client is optional and may not be available to a driver.
+ */
+@DriverSide package org.apache.reef.driver.client;
+
+import org.apache.reef.annotations.audience.DriverSide;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ActiveContext.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ActiveContext.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ActiveContext.java
new file mode 100644
index 0000000..05ed8e3
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ActiveContext.java
@@ -0,0 +1,71 @@
+/**
+ * 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.reef.driver.context;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.driver.ContextSubmittable;
+import org.apache.reef.driver.TaskSubmittable;
+import org.apache.reef.io.naming.Identifiable;
+import org.apache.reef.tang.Configuration;
+
+/**
+ * Represents an active context on an Evaluator.
+ * <p/>
+ * A context consists of twp configurations:
+ * <ol>
+ * <li>ContextConfiguration: Its visibility is limited to the context itself and tasks spawned from it.</li>
+ * <li>ServiceConfiguration: This is "inherited" by child context spawned.</li>
+ * </ol>
+ * <p/>
+ * Contexts have identifiers. A context is instantiated on a single Evaluator. Contexts are either created on an
+ * AllocatedEvaluator (for what is called the "root Context") or by forming sub-Contexts.
+ * <p/>
+ * Contexts form a stack. Only the topmost context is active. Child Contexts or Tasks can be submitted to the
+ * active Context. Contexts can be closed, in which case their parent becomes active.
+ * In the case of the root context, closing is equivalent to releasing the Evaluator. A child context "sees" all
+ * Configuration in its parent Contexts.
+ */
+@Public
+@DriverSide
+@Provided
+public interface ActiveContext extends Identifiable, AutoCloseable, ContextBase, TaskSubmittable, ContextSubmittable {
+
+  @Override
+  public void close();
+
+  @Override
+  public void submitTask(final Configuration taskConf);
+
+  @Override
+  public void submitContext(final Configuration contextConfiguration);
+
+  @Override
+  public void submitContextAndService(final Configuration contextConfiguration, final Configuration serviceConfiguration);
+
+  /**
+   * Send the active context the message, which will be delivered to all registered
+   * {@link org.apache.reef.evaluator.context.ContextMessageHandler}, for this context.
+   *
+   * @param message
+   */
+  public void sendMessage(final byte[] message);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ClosedContext.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ClosedContext.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ClosedContext.java
new file mode 100644
index 0000000..ca7b5eb
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ClosedContext.java
@@ -0,0 +1,37 @@
+/**
+ * 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.reef.driver.context;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+
+/**
+ * Represents a Context that has been closed succesfully.
+ */
+@Public
+@DriverSide
+@Provided
+public interface ClosedContext extends ContextBase {
+
+  /**
+   * @return the new top of the stack of context.
+   */
+  public ActiveContext getParentContext();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ContextBase.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ContextBase.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ContextBase.java
new file mode 100644
index 0000000..e7bcb69
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ContextBase.java
@@ -0,0 +1,56 @@
+/**
+ * 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.reef.driver.context;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.driver.evaluator.EvaluatorDescriptor;
+import org.apache.reef.io.naming.Identifiable;
+import org.apache.reef.util.Optional;
+
+/**
+ * A common base interface for all Driver-side representations of Contexts.
+ */
+@Public
+@DriverSide
+@Provided
+public interface ContextBase extends Identifiable {
+
+  /**
+   * @return the ID of the Context.
+   */
+  @Override
+  String getId();
+
+  /**
+   * @return the identifier of the Evaluator this Context is instantiated on.
+   */
+  String getEvaluatorId();
+
+  /**
+   * @return the ID of the parent context, if there is one.
+   */
+  Optional<String> getParentId();
+
+  /**
+   * @return the descriptor of the Evaluator this Context is on.
+   */
+  EvaluatorDescriptor getEvaluatorDescriptor();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ContextConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ContextConfiguration.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ContextConfiguration.java
new file mode 100644
index 0000000..a4e61b1
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ContextConfiguration.java
@@ -0,0 +1,109 @@
+/**
+ * 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.reef.driver.context;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.driver.task.TaskConfigurationOptions;
+import org.apache.reef.evaluator.context.ContextMessageHandler;
+import org.apache.reef.evaluator.context.ContextMessageSource;
+import org.apache.reef.evaluator.context.events.ContextStart;
+import org.apache.reef.evaluator.context.events.ContextStop;
+import org.apache.reef.evaluator.context.parameters.*;
+import org.apache.reef.runtime.common.evaluator.DefaultDriverConnection;
+import org.apache.reef.runtime.common.evaluator.DriverConnection;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.OptionalImpl;
+import org.apache.reef.tang.formats.RequiredParameter;
+import org.apache.reef.task.events.TaskStart;
+import org.apache.reef.task.events.TaskStop;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ * A ConfigurationModule for Context Configuration.
+ */
+@Public
+@DriverSide
+@Provided
+public class ContextConfiguration extends ConfigurationModuleBuilder {
+
+  /**
+   * The identifier of the Context.
+   */
+  public static final RequiredParameter<String> IDENTIFIER = new RequiredParameter<>();
+
+  /**
+   * Event handler for context start. Defaults to logging if not bound.
+   */
+  public static final OptionalImpl<EventHandler<ContextStart>> ON_CONTEXT_STARTED = new OptionalImpl<>();
+
+  /**
+   * Event handler for context stop. Defaults to logging if not bound.
+   */
+  public static final OptionalImpl<EventHandler<ContextStop>> ON_CONTEXT_STOP = new OptionalImpl<>();
+
+  /**
+   * Event handlers to be informed right before a Task enters its call() method.
+   */
+  public static final OptionalImpl<EventHandler<TaskStart>> ON_TASK_STARTED = new OptionalImpl<>();
+
+  /**
+   * Event handlers to be informed right after a Task exits its call() method.
+   */
+  public static final OptionalImpl<EventHandler<TaskStop>> ON_TASK_STOP = new OptionalImpl<>();
+
+  /**
+   * Source of messages to be called whenever the evaluator is about to make a heartbeat.
+   */
+  public static final OptionalImpl<ContextMessageSource> ON_SEND_MESSAGE = new OptionalImpl<>();
+
+  /**
+   * Driver has sent the context a message, and this parameter is used to register a handler
+   * on the context for processing that message.
+   */
+  public static final OptionalImpl<ContextMessageHandler> ON_MESSAGE = new OptionalImpl<>();
+
+  /**
+   * Implementation for reconnecting to driver after driver restart
+   */
+  public static final OptionalImpl<DriverConnection> ON_DRIVER_RECONNECT = new OptionalImpl<>();
+
+  /**
+   * A ConfigurationModule for context.
+   */
+  public static final ConfigurationModule CONF = new ContextConfiguration()
+      .bindNamedParameter(ContextIdentifier.class, IDENTIFIER)
+      .bindNamedParameter(DriverReconnect.class, ON_DRIVER_RECONNECT)
+      .bindSetEntry(ContextStartHandlers.class, ON_CONTEXT_STARTED)
+      .bindSetEntry(ContextStopHandlers.class, ON_CONTEXT_STOP)
+      .bindSetEntry(ContextMessageSources.class, ON_SEND_MESSAGE)
+      .bindSetEntry(ContextMessageHandlers.class, ON_MESSAGE)
+      .bindSetEntry(TaskConfigurationOptions.StartHandlers.class, ON_TASK_STARTED)
+      .bindSetEntry(TaskConfigurationOptions.StopHandlers.class, ON_TASK_STOP)
+      .build();
+
+  @NamedParameter(doc = "House the implementation for re-connecting to driver after driver restart",
+      default_classes = DefaultDriverConnection.class)
+  public static final class DriverReconnect implements Name<DriverConnection> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ContextMessage.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ContextMessage.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ContextMessage.java
new file mode 100644
index 0000000..568bc89
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ContextMessage.java
@@ -0,0 +1,52 @@
+/**
+ * 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.reef.driver.context;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.io.Message;
+import org.apache.reef.io.naming.Identifiable;
+
+/**
+ * Driver-side representation of a message sent by a Context to the Driver.
+ */
+@Public
+@DriverSide
+@Provided
+public interface ContextMessage extends Message, Identifiable {
+
+  /**
+   * @return the message sent by the Context.
+   */
+  @Override
+  public byte[] get();
+
+  /**
+   * @return the ID of the sending Context.
+   */
+  @Override
+  public String getId();
+
+  /**
+   * @return the ID of the ContextMessageSource that sent the message on the Context.
+   */
+  public String getMessageSourceID();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/FailedContext.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/FailedContext.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/FailedContext.java
new file mode 100644
index 0000000..a152255
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/FailedContext.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.driver.context;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.common.Failure;
+import org.apache.reef.util.Optional;
+
+/**
+ * Represents Context that failed.
+ * A typical case would be that its ContextStartHandler threw an exception.
+ * <p/>
+ * The underlying Evaluator is still accessible and a new context can be established. Note that REEF can't guarantee
+ * consistency of the Evaluator for all applications. It is up to the application to decide whether it is safe to keep
+ * using the Evaluator.
+ */
+@Public
+@Provided
+@DriverSide
+public interface FailedContext extends Failure, ContextBase {
+
+  /**
+   * @return the new top of the stack of context if there is one.
+   */
+  Optional<ActiveContext> getParentContext();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ServiceConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ServiceConfiguration.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ServiceConfiguration.java
new file mode 100644
index 0000000..93a50d6
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/context/ServiceConfiguration.java
@@ -0,0 +1,79 @@
+/**
+ * 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.reef.driver.context;
+
+import org.apache.reef.driver.task.TaskConfigurationOptions;
+import org.apache.reef.evaluator.context.events.ContextStart;
+import org.apache.reef.evaluator.context.events.ContextStop;
+import org.apache.reef.evaluator.context.parameters.ContextStartHandlers;
+import org.apache.reef.evaluator.context.parameters.ContextStopHandlers;
+import org.apache.reef.evaluator.context.parameters.Services;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.OptionalImpl;
+import org.apache.reef.tang.formats.OptionalParameter;
+import org.apache.reef.task.events.TaskStart;
+import org.apache.reef.task.events.TaskStop;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ * Configuration module for services. The configuration created here can be passed alongside a ContextConfiguration
+ * to form a context. Different from bindings made in the ContextConfiguration, those made here will be passed along
+ * to child context.
+ */
+public class ServiceConfiguration extends ConfigurationModuleBuilder {
+
+  /**
+   * A set of services to instantiate. All classes given here will be instantiated in the context, and their references
+   * will be made available to child context and tasks.
+   */
+  public static final OptionalParameter<Object> SERVICES = new OptionalParameter<>();
+
+  /**
+   * Event handler for context start. Defaults to logging if not bound.
+   */
+  public static final OptionalImpl<EventHandler<ContextStart>> ON_CONTEXT_STARTED = new OptionalImpl<>();
+
+  /**
+   * Event handler for context stop. Defaults to logging if not bound.
+   */
+  public static final OptionalImpl<EventHandler<ContextStop>> ON_CONTEXT_STOP = new OptionalImpl<>();
+
+  /**
+   * Event handlers to be informed right before a Task enters its call() method.
+   */
+  public static final OptionalImpl<EventHandler<TaskStart>> ON_TASK_STARTED = new OptionalImpl<>();
+
+  /**
+   * Event handlers to be informed right after a Task exits its call() method.
+   */
+  public static final OptionalImpl<EventHandler<TaskStop>> ON_TASK_STOP = new OptionalImpl<>();
+
+  /**
+   * ConfigurationModule for services.
+   */
+  public static final ConfigurationModule CONF = new ServiceConfiguration()
+      .bindSetEntry(Services.class, SERVICES)
+      .bindSetEntry(ContextStartHandlers.class, ON_CONTEXT_STARTED)
+      .bindSetEntry(ContextStopHandlers.class, ON_CONTEXT_STOP)
+      .bindSetEntry(TaskConfigurationOptions.StartHandlers.class, ON_TASK_STARTED)
+      .bindSetEntry(TaskConfigurationOptions.StopHandlers.class, ON_TASK_STOP)
+      .build();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/AllocatedEvaluator.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/AllocatedEvaluator.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/AllocatedEvaluator.java
new file mode 100644
index 0000000..198bf00
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/AllocatedEvaluator.java
@@ -0,0 +1,101 @@
+/**
+ * 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.reef.driver.evaluator;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.driver.ContextAndTaskSubmittable;
+import org.apache.reef.driver.ContextSubmittable;
+import org.apache.reef.driver.TaskSubmittable;
+import org.apache.reef.io.naming.Identifiable;
+import org.apache.reef.tang.Configuration;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Represents an Evaluator that is allocated, but is not running yet.
+ */
+@Public
+@DriverSide
+@Provided
+public interface AllocatedEvaluator
+    extends AutoCloseable, Identifiable, ContextSubmittable, ContextAndTaskSubmittable, TaskSubmittable {
+
+  /**
+   * Puts the given file into the working directory of the Evaluator.
+   *
+   * @param file the file to be copied
+   * @throws IOException if the copy fails.
+   */
+  void addFile(final File file);
+
+  /**
+   * Puts the given file into the working directory of the Evaluator and adds it to its classpath.
+   *
+   * @param file the file to be copied
+   * @throws IOException if the copy fails.
+   */
+  void addLibrary(final File file);
+
+  /**
+   * @return the evaluator descriptor of this evaluator.
+   */
+  EvaluatorDescriptor getEvaluatorDescriptor();
+
+  /**
+   * Set the type of Evaluator to be instantiated. Defaults to EvaluatorType.JVM.
+   *
+   * @param type
+   */
+  void setType(final EvaluatorType type);
+
+  /**
+   * Releases the allocated evaluator back to the resource manager.
+   */
+  @Override
+  void close();
+
+  /**
+   * Submits the given Task for execution.
+   * <p/>
+   * This generates a ContextConfiguration for the root context with a generated ID derived from the EvaluatorId.
+   *
+   * @param taskConfiguration the Configuration. See TaskConfiguration for details.
+   */
+  @Override
+  void submitTask(final Configuration taskConfiguration);
+
+  @Override
+  void submitContext(final Configuration contextConfiguration);
+
+  @Override
+  void submitContextAndService(final Configuration contextConfiguration,
+                               final Configuration serviceConfiguration);
+
+  @Override
+  void submitContextAndTask(final Configuration contextConfiguration,
+                            final Configuration taskConfiguration);
+
+  @Override
+  void submitContextAndServiceAndTask(final Configuration contextConfiguration,
+                                      final Configuration serviceConfiguration,
+                                      final Configuration taskConfiguration);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/CompletedEvaluator.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/CompletedEvaluator.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/CompletedEvaluator.java
new file mode 100644
index 0000000..70e34a5
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/CompletedEvaluator.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.driver.evaluator;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.io.naming.Identifiable;
+
+/**
+ * Represents a successfully closed Evaluator.
+ */
+@DriverSide
+@Public
+@Provided
+public interface CompletedEvaluator extends Identifiable {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/EvaluatorDescriptor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/EvaluatorDescriptor.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/EvaluatorDescriptor.java
new file mode 100644
index 0000000..55a0ddd
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/EvaluatorDescriptor.java
@@ -0,0 +1,47 @@
+/**
+ * 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.reef.driver.evaluator;
+
+import org.apache.reef.driver.catalog.NodeDescriptor;
+
+/**
+ * Metadata about an Evaluator.
+ */
+public interface EvaluatorDescriptor {
+
+  /**
+   * @return the NodeDescriptor of the node where this Evaluator is running.
+   */
+  public NodeDescriptor getNodeDescriptor();
+
+  /**
+   * @return the type of Evaluator.
+   */
+  public EvaluatorType getType();
+
+  /**
+   * @return the amount of memory allocated to this Evaluator.
+   */
+  public int getMemory();
+
+  /**
+   * @return the number of virtual core allocated to this Evaluator.
+   */
+  public int getNumberOfCores();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/EvaluatorRequest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/EvaluatorRequest.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/EvaluatorRequest.java
new file mode 100644
index 0000000..7094a42
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/EvaluatorRequest.java
@@ -0,0 +1,171 @@
+/**
+ * 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.reef.driver.evaluator;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.driver.catalog.NodeDescriptor;
+import org.apache.reef.driver.catalog.ResourceCatalog;
+
+/**
+ * A request for one ore more Evaluators.
+ */
+@Public
+@DriverSide
+@Provided
+public final class EvaluatorRequest {
+
+  private final int megaBytes;
+  private final int number;
+  private final int cores;
+  private final ResourceCatalog.Descriptor descriptor;
+
+  EvaluatorRequest(final int number,
+                   final int megaBytes,
+                   final int cores,
+                   final ResourceCatalog.Descriptor descriptor) {
+    this.number = number;
+    this.megaBytes = megaBytes;
+    this.cores = cores;
+    this.descriptor = descriptor;
+  }
+
+  /**
+   * @return a new EvaluatorRequest Builder.
+   */
+  public static Builder newBuilder() {
+    return new Builder();
+  }
+
+  /**
+   * @return a new EvaluatorRequest Builder with settings initialized
+   * from an existing request.
+   */
+  public static Builder newBuilder(final EvaluatorRequest request) {
+    return new Builder(request);
+  }
+
+  /**
+   * Access the number of Evaluators requested.
+   *
+   * @return the number of Evaluators requested.
+   */
+  public int getNumber() {
+    return this.number;
+  }
+
+  /**
+   * Access the number of core of Evaluators requested.
+   *
+   * @return the number of cores requested.
+   */
+  public int getNumberOfCores() {
+    return this.cores;
+  }
+
+  /**
+   * Access the {@link NodeDescriptor} used as the template for this
+   * {@link EvaluatorRequest}.
+   *
+   * @return the {@link NodeDescriptor} used as the template for this
+   * {@link EvaluatorRequest}.
+   */
+  public final ResourceCatalog.Descriptor getDescriptor() {
+    return this.descriptor;
+  }
+
+  /**
+   * @return the minimum size of Evaluator requested.
+   */
+  public int getMegaBytes() {
+    return megaBytes;
+  }
+
+  /**
+   * {@link EvaluatorRequest}s are build using this Builder.
+   */
+  public static class Builder implements org.apache.reef.util.Builder<EvaluatorRequest> {
+
+    private int n = 1;
+    private ResourceCatalog.Descriptor descriptor = null;
+    private int megaBytes = -1;
+    private int cores = 1; //if not set, default to 1
+
+    private Builder() {
+    }
+
+    private Builder(final EvaluatorRequest request) {
+      setNumber(request.getNumber());
+      fromDescriptor(request.getDescriptor());
+    }
+
+    /**
+     * @param megaBytes the amount of megabytes to request for the Evaluator.
+     * @return this builder
+     */
+    public Builder setMemory(final int megaBytes) {
+      this.megaBytes = megaBytes;
+      return this;
+    }
+
+    /**
+     * set number of cores
+     *
+     * @param cores the number of cores
+     * @return
+     */
+    public Builder setNumberOfCores(final int cores) {
+      this.cores = cores;
+      return this;
+    }
+
+    /**
+     * Set the number of Evaluators requested.
+     *
+     * @param n
+     * @return this Builder.
+     */
+    public Builder setNumber(final int n) {
+      this.n = n;
+      return this;
+    }
+
+    /**
+     * Builds the {@link EvaluatorRequest}.
+     */
+    @Override
+    public EvaluatorRequest build() {
+      return new EvaluatorRequest(this.n, this.megaBytes, this.cores, this.descriptor);
+    }
+
+    /**
+     * Pre-fill this {@link EvaluatorRequest} from the given
+     * {@link NodeDescriptor}. Any value not changed in subsequent calls to
+     * this Builder will be taken from the given descriptor.
+     *
+     * @param rd the descriptor used to pre-fill this request.
+     * @return this
+     */
+    public Builder fromDescriptor(final ResourceCatalog.Descriptor rd) {
+      this.descriptor = rd;
+      return this;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/EvaluatorRequestor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/EvaluatorRequestor.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/EvaluatorRequestor.java
new file mode 100644
index 0000000..6999298
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/EvaluatorRequestor.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.driver.evaluator;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+
+/**
+ * Interface through which Evaluators can be requested.
+ */
+@Public
+@DriverSide
+@Provided
+public interface EvaluatorRequestor {
+
+  /**
+   * Submit the request for new evaluator.
+   * The response will surface in the AllocatedEvaluator message handler.
+   */
+  public void submit(final EvaluatorRequest req);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/EvaluatorType.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/EvaluatorType.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/EvaluatorType.java
new file mode 100644
index 0000000..6c27db8
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/EvaluatorType.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.driver.evaluator;
+
+/**
+ * Enumeration of all Evaluator types supported by REEF.
+ */
+public enum EvaluatorType {
+  /**
+   * Indicates an Evaluator that runs on the JVM
+   */
+  JVM,
+  /**
+   * Indicates an Evaluator that runs on the CLR
+   */
+  CLR,
+  /**
+   * Indicates an Evaluator whose type hasn't been decided yet. This is common e.g. between Evaluator allocation
+   * and launch.
+   */
+  UNDECIDED
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/FailedEvaluator.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/FailedEvaluator.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/FailedEvaluator.java
new file mode 100644
index 0000000..c173457
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/evaluator/FailedEvaluator.java
@@ -0,0 +1,55 @@
+/**
+ * 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.reef.driver.evaluator;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.driver.task.FailedTask;
+import org.apache.reef.exception.EvaluatorException;
+import org.apache.reef.io.naming.Identifiable;
+import org.apache.reef.util.Optional;
+
+import java.util.List;
+
+/**
+ * Represents an Evaluator that became unavailable.
+ */
+@DriverSide
+@Public
+@Provided
+public interface FailedEvaluator extends Identifiable {
+
+  /**
+   * @return the reason for the failure.
+   */
+  public EvaluatorException getEvaluatorException();
+
+  /**
+   * @return the list of all context that failed due to the evaluator failure.
+   */
+  public List<FailedContext> getFailedContextList();
+
+  /**
+   * @return the failed task, if there was one running at the time of the evaluator failure.
+   */
+  public Optional<FailedTask> getFailedTask();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/package-info.java
new file mode 100644
index 0000000..c03ab68
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Driver APIs for REEF in terms of Rx.
+ */
+package org.apache.reef.driver;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ClientCloseHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ClientCloseHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ClientCloseHandlers.java
new file mode 100644
index 0000000..b2d45f9
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ClientCloseHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.runtime.common.driver.defaults.DefaultClientCloseHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Handles close requests from the client.
+ */
+@NamedParameter(doc = "Handles close requests from the client.", default_classes = DefaultClientCloseHandler.class)
+public final class ClientCloseHandlers implements Name<Set<EventHandler<Void>>> {
+  private ClientCloseHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ClientCloseWithMessageHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ClientCloseWithMessageHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ClientCloseWithMessageHandlers.java
new file mode 100644
index 0000000..708301d
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ClientCloseWithMessageHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.runtime.common.driver.defaults.DefaultClientCloseWithMessageHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Handles client close requests
+ */
+@NamedParameter(doc = "Handles client close requests", default_classes = DefaultClientCloseWithMessageHandler.class)
+public final class ClientCloseWithMessageHandlers implements Name<Set<EventHandler<byte[]>>> {
+  private ClientCloseWithMessageHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ClientMessageHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ClientMessageHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ClientMessageHandlers.java
new file mode 100644
index 0000000..82b61de
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ClientMessageHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.runtime.common.driver.defaults.DefaultClientMessageHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Handles message from the Client.
+ */
+@NamedParameter(doc = "Handles message from the Client.", default_classes = DefaultClientMessageHandler.class)
+public final class ClientMessageHandlers implements Name<Set<EventHandler<byte[]>>> {
+  private ClientMessageHandlers() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ContextActiveHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ContextActiveHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ContextActiveHandlers.java
new file mode 100644
index 0000000..724d7a8
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/parameters/ContextActiveHandlers.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.driver.parameters;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.runtime.common.driver.defaults.DefaultContextActiveHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Handler for ActiveContext
+ */
+@NamedParameter(doc = "Handler for ActiveContext", default_classes = DefaultContextActiveHandler.class)
+public final class ContextActiveHandlers implements Name<Set<EventHandler<ActiveContext>>> {
+  private ContextActiveHandlers() {
+  }
+}


[24/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/MergingIteratorTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/MergingIteratorTest.java b/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/MergingIteratorTest.java
new file mode 100644
index 0000000..8898dfe
--- /dev/null
+++ b/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/MergingIteratorTest.java
@@ -0,0 +1,54 @@
+/**
+ * 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.reef.services.storage;
+
+import org.apache.reef.io.storage.MergingIterator;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Iterator;
+
+public class MergingIteratorTest {
+
+  @Test
+  public void testMergingIterator() {
+    Comparator<Integer> cmp = new Comparator<Integer>() {
+
+      @Override
+      public int compare(Integer o1, Integer o2) {
+        return Integer.compare(o1, o2);
+      }
+    };
+    @SuppressWarnings("unchecked")
+    Iterator<Integer>[] its = new Iterator[]{
+        Arrays.asList(new Integer[]{1, 4, 7, 10}).iterator(),
+        Arrays.asList(new Integer[]{2, 5, 8, 11}).iterator(),
+        Arrays.asList(new Integer[]{3, 6, 9, 12}).iterator()
+    };
+    MergingIterator<Integer> merge = new MergingIterator<Integer>(cmp, its);
+    int i = 1;
+    while (merge.hasNext()) {
+      Assert.assertEquals(i, (int) merge.next());
+      i++;
+    }
+    Assert.assertEquals(13, i);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/SortingSpoolTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/SortingSpoolTest.java b/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/SortingSpoolTest.java
new file mode 100644
index 0000000..59aac5c
--- /dev/null
+++ b/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/SortingSpoolTest.java
@@ -0,0 +1,117 @@
+/**
+ * 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.reef.services.storage;
+
+import org.apache.reef.exception.evaluator.ServiceException;
+import org.apache.reef.io.Accumulator;
+import org.apache.reef.io.Spool;
+import org.apache.reef.io.storage.ram.SortingRamSpool;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.*;
+
+public class SortingSpoolTest {
+
+  @Test
+  public void testRamSpool() throws ServiceException {
+    genericTest(new SortingRamSpool<Integer>(), new Comparator<Integer>() {
+
+      @Override
+      public int compare(Integer o1, Integer o2) {
+        return Integer.compare(o1, o2);
+      }
+
+    });
+  }
+
+  @Test
+  public void testRamSpoolComparator() throws ServiceException {
+    Comparator<Integer> backwards = new Comparator<Integer>() {
+
+      @Override
+      public int compare(Integer o1, Integer o2) {
+        return -1 * o1.compareTo(o2);
+      }
+
+    };
+    genericTest(new SortingRamSpool<Integer>(backwards), backwards);
+  }
+
+  @Test(expected = IllegalStateException.class)
+  public void testRamSpoolAddAfterClose() throws ServiceException {
+    Spool<Integer> s = new SortingRamSpool<>();
+    genericAddAfterCloseTest(s);
+  }
+
+  @Test(expected = UnsupportedOperationException.class)
+  public void testRamSpoolCantRemove() throws ServiceException {
+    Spool<Integer> s = new SortingRamSpool<>();
+    genericCantRemove(s);
+  }
+
+  @Test(expected = IllegalStateException.class)
+  public void testIteratorBeforeClose() throws ServiceException {
+    Spool<Integer> s = new SortingRamSpool<>();
+    genericIteratorBeforeClose(s);
+  }
+
+  void genericTest(Spool<Integer> s, Comparator<Integer> comparator)
+      throws ServiceException {
+    List<Integer> l = new ArrayList<Integer>();
+    Random r = new Random(42);
+    while (l.size() < 100) {
+      l.add(r.nextInt(75));
+    }
+    Accumulator<Integer> a = s.accumulator();
+    for (int i = 0; i < 100; i++) {
+      a.add(l.get(i));
+    }
+    a.close();
+    List<Integer> m = new ArrayList<Integer>();
+    for (int i : s) {
+      m.add(i);
+    }
+    Integer[] sorted = l.toArray(new Integer[0]);
+    Arrays.sort(sorted, 0, sorted.length, comparator);
+    Integer[] shouldBeSorted = m.toArray(new Integer[0]);
+    Assert.assertArrayEquals(sorted, shouldBeSorted);
+  }
+
+  void genericAddAfterCloseTest(Spool<?> s) throws ServiceException {
+    Accumulator<?> a = s.accumulator();
+    a.close();
+    a.add(null);
+  }
+
+  void genericCantRemove(Spool<Integer> s) throws ServiceException {
+    Accumulator<Integer> a = s.accumulator();
+    a.add(10);
+    a.close();
+    Iterator<?> it = s.iterator();
+    it.remove();
+  }
+
+  void genericIteratorBeforeClose(Spool<Integer> s) throws ServiceException {
+    Accumulator<Integer> a = s.accumulator();
+    a.add(10);
+    s.iterator();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/SpoolFileTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/SpoolFileTest.java b/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/SpoolFileTest.java
new file mode 100644
index 0000000..afc3d2b
--- /dev/null
+++ b/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/SpoolFileTest.java
@@ -0,0 +1,206 @@
+/**
+ * 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.reef.services.storage;
+
+import org.apache.reef.exception.evaluator.ServiceException;
+import org.apache.reef.io.Accumulable;
+import org.apache.reef.io.Accumulator;
+import org.apache.reef.io.Spool;
+import org.apache.reef.io.serialization.Codec;
+import org.apache.reef.io.serialization.Deserializer;
+import org.apache.reef.io.serialization.Serializer;
+import org.apache.reef.io.storage.local.CodecFileAccumulable;
+import org.apache.reef.io.storage.local.CodecFileIterable;
+import org.apache.reef.io.storage.local.LocalStorageService;
+import org.apache.reef.io.storage.local.SerializerFileSpool;
+import org.apache.reef.io.storage.ram.RamSpool;
+import org.apache.reef.io.storage.ram.RamStorageService;
+import org.apache.reef.io.storage.util.IntegerCodec;
+import org.apache.reef.tang.ConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.AvroConfigurationSerializer;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Iterator;
+
+public class SpoolFileTest {
+  private final Serializer<Integer, OutputStream> serializer = new Serializer<Integer, OutputStream>() {
+    @Override
+    public Accumulable<Integer> create(final OutputStream out) {
+      return new Accumulable<Integer>() {
+
+        @Override
+        public Accumulator<Integer> accumulator() {
+          return new Accumulator<Integer>() {
+
+            @Override
+            public void add(Integer datum) {
+              try {
+                int d = datum;
+                out.write(new byte[]{(byte) (d >>> 24), (byte) (d >>> 16),
+                    (byte) (d >>> 8), (byte) d});
+              } catch (IOException e) {
+                throw new IllegalStateException(e);
+              }
+            }
+
+            @Override
+            public void close() {
+              try {
+                out.flush();
+              } catch (IOException e) {
+                throw new IllegalStateException(e);
+              }
+            }
+          };
+        }
+      };
+    }
+  };
+  private final Deserializer<Integer, InputStream> deserializer = new Deserializer<Integer, InputStream>() {
+    @Override
+    public Iterable<Integer> create(final InputStream in) {
+      return new Iterable<Integer>() {
+        @Override
+        public Iterator<Integer> iterator() {
+          Iterator<Integer> it = new Iterator<Integer>() {
+            final byte[] inb = new byte[4];
+            Integer nextInt;
+
+            @Override
+            public boolean hasNext() {
+              return nextInt != null;
+            }
+
+            private void prime() {
+              int read;
+              try {
+                read = in.read(inb);
+              } catch (IOException e) {
+                throw new IllegalStateException(e);
+              }
+              if (read != 4) {
+                nextInt = null;
+              } else {
+                nextInt = ((inb[0] & 0xFF) << 24) + ((inb[1] & 0xFF) << 16)
+                    + ((inb[2] & 0xFF) << 8) + (inb[3] & 0xFF);
+              }
+
+            }
+
+            @Override
+            public Integer next() {
+              Integer ret = nextInt;
+              prime();
+              return ret;
+            }
+
+            @Override
+            public void remove() {
+              throw new UnsupportedOperationException();
+            }
+          };
+          it.next(); // calls prime
+          return it;
+        }
+      };
+    }
+  };
+
+  @Test
+  public void testRam() throws BindException, InjectionException, ServiceException, IOException {
+    final Tang t = Tang.Factory.getTang();
+    final ConfigurationBuilder configurationBuilderOne = t.newConfigurationBuilder(RamConf.CONF.build());
+
+    final AvroConfigurationSerializer serializer = new AvroConfigurationSerializer();
+    final String serializedConfiguration = serializer.toString(configurationBuilderOne.build());
+    final ConfigurationBuilder configurationBuilderTwo = t.newConfigurationBuilder(serializer.fromString(serializedConfiguration));
+
+    @SuppressWarnings("unchecked")
+    final Spool<Integer> f = (Spool<Integer>) t.newInjector(configurationBuilderTwo.build()).getInstance(
+        Spool.class);
+    test(f);
+  }
+
+  @Test
+  public void testFile() throws ServiceException {
+    LocalStorageService service = new LocalStorageService("spoolTest", "file");
+    Spool<Integer> f = new SerializerFileSpool<Integer>(service, serializer,
+        deserializer);
+    test(f);
+    service.getScratchSpace().delete();
+  }
+
+  @Test
+  public void testInterop() throws ServiceException {
+    LocalStorageService service = new LocalStorageService("spoolTest", "file");
+    Codec<Integer> c = new IntegerCodec();
+
+
+    CodecFileAccumulable<Integer, Codec<Integer>> f = new CodecFileAccumulable<Integer, Codec<Integer>>(
+        service, c);
+    CodecFileIterable<Integer, Codec<Integer>> g = new CodecFileIterable<Integer, Codec<Integer>>(
+        new File(f.getName()), c);
+    test(f, g);
+    service.getScratchSpace().delete();
+  }
+
+  protected void test(Spool<Integer> f) throws ServiceException {
+    test(f, f);
+  }
+
+  protected void test(Accumulable<Integer> f, Iterable<Integer> g) throws ServiceException {
+
+    try (Accumulator<Integer> acc = f.accumulator()) {
+      for (int i = 0; i < 1000; i++) {
+        acc.add(i);
+      }
+    }
+    int i = 0;
+    for (int j : g) {
+      Assert.assertEquals(i, j);
+      i++;
+    }
+    Iterator<Integer> itA = g.iterator();
+    Iterator<Integer> itB = g.iterator();
+
+    for (i = 0; i < 1000; i++) {
+      Assert.assertEquals((int) itA.next(), i);
+      Assert.assertEquals((int) itB.next(), i);
+    }
+    Assert.assertFalse(itA.hasNext());
+    Assert.assertFalse(itB.hasNext());
+  }
+
+  public static final class RamConf extends ConfigurationModuleBuilder {
+    public static final ConfigurationModule CONF = new RamConf()
+        .bindImplementation(RamStorageService.class, RamStorageService.class)
+        .bindImplementation(Spool.class, RamSpool.class)
+        .build();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/TupleSerializerTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/TupleSerializerTest.java b/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/TupleSerializerTest.java
new file mode 100644
index 0000000..5c6c301
--- /dev/null
+++ b/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/TupleSerializerTest.java
@@ -0,0 +1,105 @@
+/**
+ * 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.reef.services.storage;
+
+import org.apache.reef.exception.evaluator.ServiceException;
+import org.apache.reef.io.Accumulator;
+import org.apache.reef.io.Tuple;
+import org.apache.reef.io.serialization.Deserializer;
+import org.apache.reef.io.serialization.Serializer;
+import org.apache.reef.io.storage.FramingTupleDeserializer;
+import org.apache.reef.io.storage.FramingTupleSerializer;
+import org.apache.reef.io.storage.util.IntegerDeserializer;
+import org.apache.reef.io.storage.util.IntegerSerializer;
+import org.apache.reef.io.storage.util.StringDeserializer;
+import org.apache.reef.io.storage.util.StringSerializer;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.*;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+public class TupleSerializerTest {
+
+  private Serializer<Integer, OutputStream> keySerializer;
+  private Serializer<String, OutputStream> valSerializer;
+  private Deserializer<Integer, InputStream> keyDeserializer;
+  private Deserializer<String, InputStream> valDeserializer;
+  private FramingTupleSerializer<Integer, String> fts;
+  private ByteArrayOutputStream baos;
+  private FramingTupleDeserializer<Integer, String> ftd;
+  private Iterable<Tuple<Integer, String>> iterable;
+
+  @Before
+  public void setup() throws ServiceException {
+
+    keySerializer = new IntegerSerializer();
+    valSerializer = new StringSerializer();
+    keyDeserializer = new IntegerDeserializer();
+    valDeserializer = new StringDeserializer();
+
+    fts = new FramingTupleSerializer<Integer, String>(
+        keySerializer, valSerializer);
+
+    baos = new ByteArrayOutputStream();
+    Accumulator<Tuple<Integer, String>> acc = fts.create(baos).accumulator();
+    for (int i = 0; i < 100; i++) {
+      acc.add(new Tuple<>(i, i + ""));
+    }
+    acc.close();
+
+    ftd = new FramingTupleDeserializer<Integer, String>(
+        keyDeserializer, valDeserializer);
+    iterable = ftd.create(new ByteArrayInputStream(baos.toByteArray()));
+  }
+
+  @Test
+  public void testFramingSerializer() throws ServiceException, IOException {
+    int i = 0;
+    for (Tuple<Integer, String> t : iterable) {
+      Tuple<Integer, String> u = new Tuple<>(i, i + "");
+      Assert.assertEquals(u, t);
+      i++;
+    }
+    Assert.assertEquals(100, i);
+  }
+
+  @Test(expected = NoSuchElementException.class)
+  public void testReadOffEnd() {
+    Iterator<Tuple<Integer, String>> it = iterable.iterator();
+    try {
+      while (it.hasNext()) {
+        it.next();
+        it.hasNext();
+      }
+    } catch (NoSuchElementException e) {
+      throw new IllegalStateException("Errored out too early!", e);
+    }
+    it.next();
+  }
+
+  @Test(expected = UnsupportedOperationException.class)
+  public void testCantRemove() {
+    Iterator<Tuple<Integer, String>> it = iterable.iterator();
+    it.next();
+    it.remove();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-poison/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-poison/pom.xml b/lang/java/reef-poison/pom.xml
new file mode 100644
index 0000000..be12c30
--- /dev/null
+++ b/lang/java/reef-poison/pom.xml
@@ -0,0 +1,52 @@
+<?xml version="1.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.
+-->
+<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.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>reef-poison</artifactId>
+    <name>REEF Poison</name>
+    <description>Fault injection for REEF</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>tang</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>wake</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-math3</artifactId>
+        </dependency>
+    </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-poison/src/main/java/org/apache/reef/poison/PoisonException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-poison/src/main/java/org/apache/reef/poison/PoisonException.java b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/PoisonException.java
new file mode 100644
index 0000000..161a8ab
--- /dev/null
+++ b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/PoisonException.java
@@ -0,0 +1,28 @@
+/**
+ * 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.reef.poison;
+
+/**
+ * Exception thrown by REEF Poison.
+ */
+public final class PoisonException extends RuntimeException {
+  public PoisonException(final String s) {
+    super(s);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-poison/src/main/java/org/apache/reef/poison/PoisonedAlarmHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-poison/src/main/java/org/apache/reef/poison/PoisonedAlarmHandler.java b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/PoisonedAlarmHandler.java
new file mode 100644
index 0000000..d5933b1
--- /dev/null
+++ b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/PoisonedAlarmHandler.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.poison;
+
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.Alarm;
+
+
+/**
+ * To be registered on the Clock to handle Alarms.
+ */
+final public class PoisonedAlarmHandler implements EventHandler<Alarm> {
+  @Override
+  public void onNext(final Alarm alarm) {
+    throw new PoisonException("Crashed at: " + alarm.toString());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-poison/src/main/java/org/apache/reef/poison/PoisonedConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-poison/src/main/java/org/apache/reef/poison/PoisonedConfiguration.java b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/PoisonedConfiguration.java
new file mode 100644
index 0000000..0457964
--- /dev/null
+++ b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/PoisonedConfiguration.java
@@ -0,0 +1,57 @@
+/**
+ * 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.reef.poison;
+
+import org.apache.reef.driver.task.TaskConfigurationOptions;
+import org.apache.reef.evaluator.context.parameters.ContextStartHandlers;
+import org.apache.reef.poison.context.PoisonedContextStartHandler;
+import org.apache.reef.poison.params.CrashProbability;
+import org.apache.reef.poison.params.CrashTimeout;
+import org.apache.reef.poison.task.PoisonedTaskStartHandler;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.OptionalParameter;
+
+/**
+ * Configure a Context with a lethal injection.
+ */
+public final class PoisonedConfiguration extends ConfigurationModuleBuilder {
+
+  /**
+   * The time window in seconds beginning at ContextStart during which the crash is to occur.
+   */
+  public static final OptionalParameter<Integer> CRASH_TIMEOUT = new OptionalParameter<>();
+
+  /**
+   * The probability with which a crash is to occur.
+   */
+  public static final OptionalParameter<Double> CRASH_PROBABILITY = new OptionalParameter<>();
+
+  public static final ConfigurationModule CONTEXT_CONF = new PoisonedConfiguration()
+      .bindNamedParameter(CrashTimeout.class, CRASH_TIMEOUT)
+      .bindNamedParameter(CrashProbability.class, CRASH_PROBABILITY)
+      .bindSetEntry(ContextStartHandlers.class, PoisonedContextStartHandler.class)
+      .build();
+
+  public static final ConfigurationModule TASK_CONF = new PoisonedConfiguration()
+      .bindNamedParameter(CrashTimeout.class, CRASH_TIMEOUT)
+      .bindNamedParameter(CrashProbability.class, CRASH_PROBABILITY)
+      .bindSetEntry(TaskConfigurationOptions.StartHandlers.class, PoisonedTaskStartHandler.class)
+      .build();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-poison/src/main/java/org/apache/reef/poison/context/PoisonedContextStartHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-poison/src/main/java/org/apache/reef/poison/context/PoisonedContextStartHandler.java b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/context/PoisonedContextStartHandler.java
new file mode 100644
index 0000000..d22b3ae
--- /dev/null
+++ b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/context/PoisonedContextStartHandler.java
@@ -0,0 +1,77 @@
+/**
+ * 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.reef.poison.context;
+
+import org.apache.reef.evaluator.context.events.ContextStart;
+import org.apache.reef.poison.PoisonException;
+import org.apache.reef.poison.PoisonedAlarmHandler;
+import org.apache.reef.poison.params.CrashProbability;
+import org.apache.reef.poison.params.CrashTimeout;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.Clock;
+
+import javax.inject.Inject;
+import java.util.Random;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public final class PoisonedContextStartHandler implements EventHandler<ContextStart> {
+
+  private static final Logger LOG = Logger.getLogger(PoisonedContextStartHandler.class.getName());
+
+  private final Random random = new Random();
+
+  private final double crashProbability;
+  private final int timeOut;
+  private final Clock clock;
+
+  @Inject
+  public PoisonedContextStartHandler(
+      final @Parameter(CrashProbability.class) double crashProbability,
+      final @Parameter(CrashTimeout.class) int timeOut,
+      final Clock clock) {
+
+    this.crashProbability = crashProbability;
+    this.timeOut = timeOut;
+    this.clock = clock;
+  }
+
+  @Override
+  public void onNext(final ContextStart contextStart) {
+
+    LOG.log(Level.INFO, "Starting Context poison injector with prescribed dose: {0} units",
+        this.crashProbability);
+
+    if (this.random.nextDouble() <= this.crashProbability) {
+
+      final int timeToCrash = this.random.nextInt(this.timeOut) * 1000;
+      LOG.log(Level.INFO, "Dosage lethal! Crashing in {0} msec.", timeToCrash);
+
+      if (timeToCrash == 0) {
+        throw new PoisonException("Crashed at: " + System.currentTimeMillis());
+      } else {
+        this.clock.scheduleAlarm(timeToCrash, new PoisonedAlarmHandler());
+      }
+
+    } else {
+      LOG.info("Dosage not lethal");
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-poison/src/main/java/org/apache/reef/poison/context/PoissonPoisonedContextStartHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-poison/src/main/java/org/apache/reef/poison/context/PoissonPoisonedContextStartHandler.java b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/context/PoissonPoisonedContextStartHandler.java
new file mode 100644
index 0000000..b52bad1
--- /dev/null
+++ b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/context/PoissonPoisonedContextStartHandler.java
@@ -0,0 +1,57 @@
+/**
+ * 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.reef.poison.context;
+
+import org.apache.commons.math3.distribution.PoissonDistribution;
+import org.apache.reef.evaluator.context.events.ContextStart;
+import org.apache.reef.poison.PoisonedAlarmHandler;
+import org.apache.reef.poison.params.CrashProbability;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.Clock;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+final class PoissonPoisonedContextStartHandler implements EventHandler<ContextStart> {
+
+  private static final Logger LOG = Logger.getLogger(PoissonPoisonedContextStartHandler.class.getName());
+
+  private final Clock clock;
+  private final int timeToCrash;
+
+  @Inject
+  public PoissonPoisonedContextStartHandler(
+      final @Parameter(CrashProbability.class) double lambda, final Clock clock) {
+
+    this.clock = clock;
+    this.timeToCrash = new PoissonDistribution(lambda * 1000).sample();
+
+    LOG.log(Level.INFO,
+        "Created Poisson poison injector with prescribed dose: {0}. Crash in {1} msec.",
+        new Object[]{lambda, this.timeToCrash});
+  }
+
+  @Override
+  public void onNext(final ContextStart contextStart) {
+    LOG.log(Level.INFO, "Started Poisson poison injector. Crashing in {0} msec.", this.timeToCrash);
+    this.clock.scheduleAlarm(this.timeToCrash, new PoisonedAlarmHandler());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-poison/src/main/java/org/apache/reef/poison/context/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-poison/src/main/java/org/apache/reef/poison/context/package-info.java b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/context/package-info.java
new file mode 100644
index 0000000..ad64f43
--- /dev/null
+++ b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/context/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Fault Injection into REEF contexts.
+ */
+package org.apache.reef.poison.context;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-poison/src/main/java/org/apache/reef/poison/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-poison/src/main/java/org/apache/reef/poison/package-info.java b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/package-info.java
new file mode 100644
index 0000000..414c30e
--- /dev/null
+++ b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Fault injection for REEF.
+ */
+package org.apache.reef.poison;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-poison/src/main/java/org/apache/reef/poison/params/CrashProbability.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-poison/src/main/java/org/apache/reef/poison/params/CrashProbability.java b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/params/CrashProbability.java
new file mode 100644
index 0000000..d3e1db8
--- /dev/null
+++ b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/params/CrashProbability.java
@@ -0,0 +1,30 @@
+/**
+ * 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.reef.poison.params;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The probability with which a crash will occur.
+ */
+@NamedParameter(doc = "the probability with which a crash will occur.", default_value = "" + CrashProbability.DEFAULT_VALUE)
+public final class CrashProbability implements Name<Double> {
+  public static final double DEFAULT_VALUE = 0.1;
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-poison/src/main/java/org/apache/reef/poison/params/CrashTimeout.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-poison/src/main/java/org/apache/reef/poison/params/CrashTimeout.java b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/params/CrashTimeout.java
new file mode 100644
index 0000000..314ec49
--- /dev/null
+++ b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/params/CrashTimeout.java
@@ -0,0 +1,27 @@
+/**
+ * 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.reef.poison.params;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+@NamedParameter(doc = "The time window (in seconds) after ContextStart in which the crash will occur", default_value = "" + CrashTimeout.DEFAULT_VALUE)
+public final class CrashTimeout implements Name<Integer> {
+  public static final int DEFAULT_VALUE = 10;
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-poison/src/main/java/org/apache/reef/poison/task/PoisonedTaskStartHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-poison/src/main/java/org/apache/reef/poison/task/PoisonedTaskStartHandler.java b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/task/PoisonedTaskStartHandler.java
new file mode 100644
index 0000000..0a59891
--- /dev/null
+++ b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/task/PoisonedTaskStartHandler.java
@@ -0,0 +1,77 @@
+/**
+ * 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.reef.poison.task;
+
+import org.apache.reef.poison.PoisonException;
+import org.apache.reef.poison.PoisonedAlarmHandler;
+import org.apache.reef.poison.params.CrashProbability;
+import org.apache.reef.poison.params.CrashTimeout;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.task.events.TaskStart;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.Clock;
+
+import javax.inject.Inject;
+import java.util.Random;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public final class PoisonedTaskStartHandler implements EventHandler<TaskStart> {
+
+  private static final Logger LOG = Logger.getLogger(PoisonedTaskStartHandler.class.getName());
+
+  private final Random random = new Random();
+
+  private final double crashProbability;
+  private final int timeOut;
+  private final Clock clock;
+
+  @Inject
+  public PoisonedTaskStartHandler(
+      final @Parameter(CrashProbability.class) double crashProbability,
+      final @Parameter(CrashTimeout.class) int timeOut,
+      final Clock clock) {
+
+    this.crashProbability = crashProbability;
+    this.timeOut = timeOut;
+    this.clock = clock;
+  }
+
+  @Override
+  public void onNext(final TaskStart taskStart) {
+
+    LOG.log(Level.INFO, "Starting Task poison injector with prescribed dose: {0} units",
+        this.crashProbability);
+
+    if (this.random.nextDouble() <= this.crashProbability) {
+
+      final int timeToCrash = this.random.nextInt(this.timeOut) * 1000;
+      LOG.log(Level.INFO, "Dosage lethal! Crashing in {0} msec.", timeToCrash);
+
+      if (timeToCrash == 0) {
+        throw new PoisonException("Crashed at: " + System.currentTimeMillis());
+      } else {
+        this.clock.scheduleAlarm(timeToCrash, new PoisonedAlarmHandler());
+      }
+
+    } else {
+      LOG.info("Dosage not lethal");
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-poison/src/main/java/org/apache/reef/poison/task/PoissonPoisonedTaskStartHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-poison/src/main/java/org/apache/reef/poison/task/PoissonPoisonedTaskStartHandler.java b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/task/PoissonPoisonedTaskStartHandler.java
new file mode 100644
index 0000000..daed09c
--- /dev/null
+++ b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/task/PoissonPoisonedTaskStartHandler.java
@@ -0,0 +1,57 @@
+/**
+ * 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.reef.poison.task;
+
+import org.apache.commons.math3.distribution.PoissonDistribution;
+import org.apache.reef.poison.PoisonedAlarmHandler;
+import org.apache.reef.poison.params.CrashProbability;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.task.events.TaskStart;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.Clock;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+final class PoissonPoisonedTaskStartHandler implements EventHandler<TaskStart> {
+
+  private static final Logger LOG = Logger.getLogger(PoissonPoisonedTaskStartHandler.class.getName());
+
+  private final Clock clock;
+  private final int timeToCrash;
+
+  @Inject
+  public PoissonPoisonedTaskStartHandler(
+      final @Parameter(CrashProbability.class) double lambda, final Clock clock) {
+
+    this.clock = clock;
+    this.timeToCrash = new PoissonDistribution(lambda * 1000).sample();
+
+    LOG.log(Level.INFO,
+        "Created Poisson poison injector with prescribed dose: {0}. Crash in {1} msec.",
+        new Object[]{lambda, this.timeToCrash});
+  }
+
+  @Override
+  public void onNext(final TaskStart taskStart) {
+    LOG.log(Level.INFO, "Started Poisson poison injector. Crashing in {0} msec.", this.timeToCrash);
+    this.clock.scheduleAlarm(this.timeToCrash, new PoisonedAlarmHandler());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-poison/src/main/java/org/apache/reef/poison/task/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-poison/src/main/java/org/apache/reef/poison/task/package-info.java b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/task/package-info.java
new file mode 100644
index 0000000..d526983
--- /dev/null
+++ b/lang/java/reef-poison/src/main/java/org/apache/reef/poison/task/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Fault Injection into REEF tasks.
+ */
+package org.apache.reef.poison.task;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/pom.xml b/lang/java/reef-runtime-hdinsight/pom.xml
new file mode 100644
index 0000000..1504b89
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/pom.xml
@@ -0,0 +1,82 @@
+<?xml version="1.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.
+-->
+<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.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+    <name>REEF Runtime for HDInsight</name>
+    <artifactId>reef-runtime-hdinsight</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-yarn</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.microsoft.windowsazure.storage</groupId>
+            <artifactId>microsoft-windowsazure-storage-sdk</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.codehaus.jackson</groupId>
+            <artifactId>jackson-mapper-asl</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.codehaus.jackson</groupId>
+            <artifactId>jackson-core-asl</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-common</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-yarn-common</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-yarn-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-yarn-client</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+    </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/HDInsightClasspathProvider.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/HDInsightClasspathProvider.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/HDInsightClasspathProvider.java
new file mode 100644
index 0000000..afcc327
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/HDInsightClasspathProvider.java
@@ -0,0 +1,73 @@
+/**
+ * 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.reef.runtime.hdinsight;
+
+import net.jcip.annotations.Immutable;
+import org.apache.reef.runtime.common.files.RuntimeClasspathProvider;
+
+import javax.inject.Inject;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Access to the classpath according to the REEF file system standard.
+ */
+@Immutable
+public final class HDInsightClasspathProvider implements RuntimeClasspathProvider {
+
+  private static final List<String> CLASSPATH_PREFIX = Collections
+      .unmodifiableList(Arrays.asList("%HADOOP_HOME%/etc/hadoop"));
+
+  private static final List<String> CLASSPATH_SUFFIX = Collections.unmodifiableList(
+      Arrays.asList(
+          "%HADOOP_HOME%/share/hadoop/common/*",
+          "%HADOOP_HOME%/share/hadoop/common/lib/*",
+          "%HADOOP_HOME%/share/hadoop/yarn/*",
+          "%HADOOP_HOME%/share/hadoop/yarn/lib/*",
+          "%HADOOP_HOME%/share/hadoop/hdfs/*",
+          "%HADOOP_HOME%/share/hadoop/hdfs/lib/*",
+          "%HADOOP_HOME%/share/hadoop/mapreduce/*",
+          "%HADOOP_HOME%/share/hadoop/mapreduce/lib/*")
+  );
+
+  @Inject
+  HDInsightClasspathProvider() {
+  }
+
+  @Override
+  public List<String> getDriverClasspathPrefix() {
+    return CLASSPATH_PREFIX;
+  }
+
+  @Override
+  public List<String> getDriverClasspathSuffix() {
+    return CLASSPATH_SUFFIX;
+  }
+
+  @Override
+  public List<String> getEvaluatorClasspathPrefix() {
+    return CLASSPATH_PREFIX;
+  }
+
+  @Override
+  public List<String> getEvaluatorClasspathSuffix() {
+    return CLASSPATH_SUFFIX;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/HDICLI.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/HDICLI.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/HDICLI.java
new file mode 100644
index 0000000..93b3933
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/HDICLI.java
@@ -0,0 +1,173 @@
+/**
+ * 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.reef.runtime.hdinsight.cli;
+
+import org.apache.commons.cli.*;
+import org.apache.reef.runtime.hdinsight.client.UnsafeHDInsightRuntimeConfiguration;
+import org.apache.reef.runtime.hdinsight.client.yarnrest.ApplicationState;
+import org.apache.reef.runtime.hdinsight.client.yarnrest.HDInsightInstance;
+import org.apache.reef.tang.Tang;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Main class for the HDInsight REST commandline
+ */
+public final class HDICLI {
+  private static final Logger LOG = Logger.getLogger(HDICLI.class.getName());
+  private static final String KILL = "kill";
+  private static final String LOGS = "logs";
+  private static final String LIST = "list";
+  private static final String STATUS = "status";
+
+  private final HDInsightInstance hdInsightInstance;
+  private final Options options;
+  private final LogFetcher logFetcher;
+
+  @Inject
+  HDICLI(final HDInsightInstance hdInsightInstance,
+         final LogFetcher logFetcher) {
+    this.hdInsightInstance = hdInsightInstance;
+    this.logFetcher = logFetcher;
+    final OptionGroup commands = new OptionGroup()
+        .addOption(OptionBuilder.withArgName(KILL).hasArg().withDescription("Kills the given application.").create(KILL))
+        .addOption(OptionBuilder.withArgName(LOGS).hasArg().withDescription("Fetches the logs for the given application.").create(LOGS))
+        .addOption(OptionBuilder.withArgName(STATUS).hasArg().withDescription("Fetches the status for the given application.").create(STATUS))
+        .addOption(OptionBuilder.withArgName(LIST).withDescription("Lists the application on the cluster.").create(LIST));
+    this.options = new Options().addOptionGroup(commands);
+  }
+
+  /**
+   * Helper method to setup apache commons logging.
+   */
+  private static final void setupLogging() {
+    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger");
+    System.setProperty(".level", "INFO");
+  }
+
+  public static void main(final String[] args) throws Exception {
+    setupLogging();
+    Tang.Factory.getTang()
+        .newInjector(UnsafeHDInsightRuntimeConfiguration.fromEnvironment())
+        .getInstance(HDICLI.class).run(args);
+  }
+
+  public void run(final String[] args) throws Exception {
+    final CommandLineParser parser = new PosixParser();
+
+    final CommandLine line = parser.parse(options, args);
+    final List<String> positionalArguments = line.getArgList();
+    if (line.hasOption(KILL)) {
+      this.kill(line.getOptionValue(KILL));
+    } else if (line.hasOption(LOGS)) {
+      final String applicationId = line.getOptionValue(LOGS);
+      if (positionalArguments.isEmpty()) {
+        this.logs(applicationId);
+      } else {
+        this.logs(applicationId, new File(positionalArguments.get(0)));
+      }
+    } else if (line.hasOption(LIST)) {
+      this.list();
+    } else if (line.hasOption(STATUS)) {
+      this.status(line.getOptionValue(STATUS));
+    } else {
+      throw new Exception("Unable to parse command line");
+    }
+
+  }
+
+  /**
+   * Kills the application with the given id.
+   *
+   * @param applicationId
+   */
+  private void kill(final String applicationId) {
+    LOG.log(Level.INFO, "Killing application [{0}]", applicationId);
+    this.hdInsightInstance.killApplication(applicationId);
+  }
+
+  /**
+   * Fetches the logs for the application with the given id and prints them to System.out.
+   *
+   * @param applicationId
+   * @throws IOException
+   */
+  private void logs(final String applicationId) throws IOException {
+    LOG.log(Level.INFO, "Fetching logs for application [{0}]", applicationId);
+    this.logFetcher.fetch(applicationId, new OutputStreamWriter(System.out));
+  }
+
+  /**
+   * Fetches the logs for the application with the given id and stores them in the given folder. One file per container.
+   *
+   * @param applicationId
+   * @param folder
+   * @throws IOException
+   */
+  private void logs(final String applicationId, final File folder) throws IOException {
+    LOG.log(Level.FINE, "Fetching logs for application [{0}] and storing them in folder [{1}]",
+        new Object[]{applicationId, folder.getAbsolutePath()});
+    folder.mkdirs();
+    this.logFetcher.fetch(applicationId, folder);
+  }
+
+  /**
+   * Fetches a list of all running applications.
+   *
+   * @throws IOException
+   */
+  private void list() throws IOException {
+    LOG.log(Level.FINE, "Listing applications");
+    final List<ApplicationState> applications = this.hdInsightInstance.listApplications();
+    for (final ApplicationState appState : applications) {
+      if (appState.getState().equals("RUNNING")) {
+        System.out.println(appState.getId() + "\t" + appState.getName());
+      }
+    }
+  }
+
+  private void status(final String applicationId) throws IOException {
+    final List<ApplicationState> applications = this.hdInsightInstance.listApplications();
+    ApplicationState applicationState = null;
+    for (final ApplicationState appState : applications) {
+      if (appState.getId().equals(applicationId)) {
+        applicationState = appState;
+        break;
+      }
+    }
+
+    if (applicationState == null) {
+      throw new IOException("Unknown application: " + applicationId);
+    }
+    final ObjectMapper objectMapper = new ObjectMapper();
+    final String status = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(applicationState);
+
+    System.out.println(status);
+
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/LogFetcher.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/LogFetcher.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/LogFetcher.java
new file mode 100644
index 0000000..137e671
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/LogFetcher.java
@@ -0,0 +1,134 @@
+/**
+ * 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.reef.runtime.hdinsight.cli;
+
+import com.microsoft.windowsazure.storage.CloudStorageAccount;
+import com.microsoft.windowsazure.storage.StorageException;
+import com.microsoft.windowsazure.storage.blob.*;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.reef.runtime.hdinsight.parameters.AzureStorageAccountContainerName;
+import org.apache.reef.runtime.hdinsight.parameters.AzureStorageAccountKey;
+import org.apache.reef.runtime.hdinsight.parameters.AzureStorageAccountName;
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+import java.io.*;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.security.InvalidKeyException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Helper class to fetch logs from an HDInsight cluster.
+ */
+final class LogFetcher {
+  private static final String LOG_FOLDER_PREFIX = "app-logs/gopher/logs/";
+  private static final Logger LOG = Logger.getLogger(LogFetcher.class.getName());
+  private final CloudBlobContainer container;
+  private final FileSystem fileSystem;
+  private final Configuration hadoopConfiguration;
+  private final TFileParser tFileParser;
+
+
+  @Inject
+  LogFetcher(final @Parameter(AzureStorageAccountName.class) String accountName,
+             final @Parameter(AzureStorageAccountKey.class) String accountKey,
+             final @Parameter(AzureStorageAccountContainerName.class) String azureStorageContainerName)
+      throws URISyntaxException, InvalidKeyException, StorageException, IOException {
+    this.container = getContainer(accountName, accountKey, azureStorageContainerName);
+    this.hadoopConfiguration = new Configuration();
+    this.fileSystem = FileSystem.get(hadoopConfiguration);
+    this.tFileParser = new TFileParser(hadoopConfiguration, fileSystem);
+  }
+
+  private static CloudBlobContainer getContainer(final String accountName,
+                                                 final String accountKey,
+                                                 final String containerName)
+      throws URISyntaxException, InvalidKeyException, StorageException {
+    final CloudStorageAccount cloudStorageAccount = CloudStorageAccount.parse(getStorageConnectionString(accountName, accountKey));
+    final CloudBlobClient blobClient = cloudStorageAccount.createCloudBlobClient();
+    return blobClient.getContainerReference(containerName);
+  }
+
+  /**
+   * Assemble a connection string from account name and key.
+   */
+  private static String getStorageConnectionString(final String accountName, final String accountKey) {
+    // "DefaultEndpointsProtocol=http;AccountName=[ACCOUNT_NAME];AccountKey=[ACCOUNT_KEY]"
+    return "DefaultEndpointsProtocol=http;AccountName=" + accountName + ";AccountKey=" + accountKey;
+  }
+
+  void fetch(final String applicationId, final Writer outputWriter) throws IOException {
+    try {
+      for (final FileStatus fileStatus : downloadLogs(applicationId)) {
+        tFileParser.parseOneFile(fileStatus.getPath(), outputWriter);
+      }
+    } catch (final Exception e) {
+      throw new IOException(e);
+    }
+  }
+
+  void fetch(final String applicationId, final File folder) throws IOException {
+    try {
+      for (final FileStatus fileStatus : downloadLogs(applicationId)) {
+        tFileParser.parseOneFile(fileStatus.getPath(), folder);
+      }
+    } catch (final Exception e) {
+      throw new IOException(e);
+    }
+  }
+
+  private FileStatus[] downloadLogs(final String applicationId) throws StorageException, IOException, URISyntaxException {
+    final File localFolder = downloadToTempFolder(applicationId);
+    final Path localFolderPath = new Path(localFolder.getAbsolutePath());
+    return this.fileSystem.listStatus(localFolderPath);
+  }
+
+  /**
+   * Downloads the logs to a local temp folder.
+   *
+   * @param applicationId
+   * @return
+   * @throws URISyntaxException
+   * @throws StorageException
+   * @throws IOException
+   */
+  private File downloadToTempFolder(final String applicationId) throws URISyntaxException, StorageException, IOException {
+    final File outputFolder = Files.createTempDirectory("reeflogs-" + applicationId).toFile();
+    outputFolder.mkdirs();
+    final CloudBlobDirectory logFolder = this.container.getDirectoryReference(LOG_FOLDER_PREFIX + applicationId + "/");
+    int fileCounter = 0;
+    for (final ListBlobItem blobItem : logFolder.listBlobs()) {
+      if (blobItem instanceof CloudBlob) {
+        try (final OutputStream outputStream = new FileOutputStream(new File(outputFolder, "File-" + fileCounter))) {
+          ((CloudBlob) blobItem).download(outputStream);
+          ++fileCounter;
+        }
+      }
+    }
+    LOG.log(Level.FINE, "Downloadeded logs to: {0}", outputFolder.getAbsolutePath());
+    return outputFolder;
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/LogFileEntry.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/LogFileEntry.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/LogFileEntry.java
new file mode 100644
index 0000000..0b57b4c
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/LogFileEntry.java
@@ -0,0 +1,113 @@
+/**
+ * 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.reef.runtime.hdinsight.cli;
+
+import org.apache.hadoop.io.file.tfile.TFile;
+
+import java.io.*;
+import java.util.logging.Logger;
+
+/**
+ * A Helper class that wraps a TFile.Reader.Scanner.Entry, assuming that it contains YARN aggregated logs.
+ */
+final class LogFileEntry {
+  private static final Logger LOG = Logger.getLogger(LogFileEntry.class.getName());
+  private final TFile.Reader.Scanner.Entry entry;
+
+
+  LogFileEntry(final TFile.Reader.Scanner.Entry entry) {
+    this.entry = entry;
+  }
+
+  /**
+   * Writes the contents of the entry into the given outputWriter
+   *
+   * @param outputWriter
+   * @throws IOException
+   */
+  public void write(final Writer outputWriter) throws IOException {
+    try (final DataInputStream keyStream = entry.getKeyStream();
+         final DataInputStream valueStream = entry.getValueStream();) {
+      outputWriter.write("Container: ");
+      outputWriter.write(keyStream.readUTF());
+      outputWriter.write("\n");
+      this.writeFiles(valueStream, outputWriter);
+    }
+  }
+
+  /**
+   * Writes the logs stored in the entry as text files in folder, one per container.
+   *
+   * @param folder
+   * @throws IOException
+   */
+  public void write(final File folder) throws IOException {
+    try (final DataInputStream keyStream = entry.getKeyStream();
+         final DataInputStream valueStream = entry.getValueStream();) {
+      final String containerId = keyStream.readUTF();
+      try (final Writer outputWriter = new FileWriter(new File(folder, containerId + ".txt"))) {
+        this.writeFiles(valueStream, outputWriter);
+      }
+    }
+  }
+
+
+  /**
+   * Writes the logs of the next container to the given writer. Assumes that the valueStream is suitably positioned.
+   *
+   * @param valueStream
+   * @param outputWriter
+   * @throws IOException
+   */
+  private final void writeFiles(final DataInputStream valueStream, final Writer outputWriter) throws IOException {
+    while (valueStream.available() > 0) {
+      final String strFileName = valueStream.readUTF();
+      final int entryLength = Integer.parseInt(valueStream.readUTF());
+      outputWriter.write("=====================================================\n");
+      outputWriter.write("File Name: " + strFileName + "\n");
+      outputWriter.write("File Length: " + entryLength + "\n");
+      outputWriter.write("-----------------------------------------------------\n");
+      this.write(valueStream, outputWriter, entryLength);
+      outputWriter.write("\n");
+    }
+  }
+
+  /**
+   * Writes the next numberOfBytes bytes from the sream to the outputWriter, assuming that the bytes are UTF-8 encoded
+   * caharcters.
+   *
+   * @param stream
+   * @param outputWriter
+   * @param numberOfBytes
+   * @throws IOException
+   */
+  private void write(final DataInputStream stream, final Writer outputWriter, final int numberOfBytes) throws IOException {
+    final byte[] buf = new byte[65535];
+    int lenRemaining = numberOfBytes;
+    while (lenRemaining > 0) {
+      final int len = stream.read(buf, 0, lenRemaining > 65535 ? 65535 : lenRemaining);
+      if (len > 0) {
+        outputWriter.write(new String(buf, 0, len, "UTF-8"));
+        lenRemaining -= len;
+      } else {
+        break;
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/TFileParser.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/TFileParser.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/TFileParser.java
new file mode 100644
index 0000000..f343faf
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/TFileParser.java
@@ -0,0 +1,97 @@
+/**
+ * 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.reef.runtime.hdinsight.cli;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.io.file.tfile.TFile;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Parse TFile's content to key value pair
+ */
+final class TFileParser {
+  private static final Logger LOG = Logger.getLogger(TFileParser.class.getName());
+  private final FileSystem fileSystem;
+  private final Configuration configuration;
+
+  public TFileParser(final Configuration conf, final FileSystem fs) {
+    this.configuration = conf;
+    this.fileSystem = fs;
+  }
+
+  /**
+   * Parses the given file and writes its contents into the outputWriter for all logs in it.
+   *
+   * @param inputPath
+   * @param outputWriter
+   * @throws IOException
+   */
+  void parseOneFile(final Path inputPath, final Writer outputWriter) throws IOException {
+    try (final TFile.Reader.Scanner scanner = this.getScanner(inputPath)) {
+      while (!scanner.atEnd()) {
+        new LogFileEntry(scanner.entry()).write(outputWriter);
+        scanner.advance();
+      }
+    }
+  }
+
+  /**
+   * Parses the given file and stores the logs for each container in a file named after the container in the given
+   * outputFolder
+   *
+   * @param inputPath
+   * @param outputFolder
+   * @throws IOException
+   */
+  void parseOneFile(final Path inputPath, final File outputFolder) throws IOException {
+    try (final TFile.Reader.Scanner scanner = this.getScanner(inputPath)) {
+      while (!scanner.atEnd()) {
+        new LogFileEntry(scanner.entry()).write(outputFolder);
+        scanner.advance();
+      }
+    }
+  }
+
+  /**
+   * @param path
+   * @return
+   * @throws IOException
+   */
+  private TFile.Reader.Scanner getScanner(final Path path) throws IOException {
+    LOG.log(Level.FINE, "Creating Scanner for path {0}", path);
+    final TFile.Reader reader = new TFile.Reader(this.fileSystem.open(path),
+        this.fileSystem.getFileStatus(path).getLen(),
+        this.configuration);
+    final TFile.Reader.Scanner scanner = reader.createScanner();
+    for (int counter = 0;
+         counter < 3 && !scanner.atEnd();
+         counter += 1, scanner.advance()) {
+      //skip VERSION, APPLICATION_ACL, and APPLICATION_OWNER
+    }
+    LOG.log(Level.FINE, "Created Scanner for path {0}", path);
+    return scanner;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/package-info.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/package-info.java
new file mode 100644
index 0000000..9bbe75e
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/cli/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * A command line interface for HDInsight
+ */
+package org.apache.reef.runtime.hdinsight.cli;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/AzureUploader.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/AzureUploader.java b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/AzureUploader.java
new file mode 100644
index 0000000..055ea93
--- /dev/null
+++ b/lang/java/reef-runtime-hdinsight/src/main/java/org/apache/reef/runtime/hdinsight/client/AzureUploader.java
@@ -0,0 +1,151 @@
+/**
+ * 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.reef.runtime.hdinsight.client;
+
+import com.microsoft.windowsazure.storage.CloudStorageAccount;
+import com.microsoft.windowsazure.storage.StorageException;
+import com.microsoft.windowsazure.storage.blob.BlobProperties;
+import com.microsoft.windowsazure.storage.blob.CloudBlobClient;
+import com.microsoft.windowsazure.storage.blob.CloudBlobContainer;
+import com.microsoft.windowsazure.storage.blob.CloudBlockBlob;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.runtime.hdinsight.client.yarnrest.FileResource;
+import org.apache.reef.runtime.hdinsight.parameters.AzureStorageAccountContainerName;
+import org.apache.reef.runtime.hdinsight.parameters.AzureStorageAccountKey;
+import org.apache.reef.runtime.hdinsight.parameters.AzureStorageAccountName;
+import org.apache.reef.runtime.hdinsight.parameters.AzureStorageBaseFolder;
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.InvalidKeyException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Helper class to upload the job JAR to Azure block storage.
+ */
+@ClientSide
+@Private
+final class AzureUploader {
+
+  private static final Logger LOG = Logger.getLogger(AzureUploader.class.getName());
+
+  private final CloudStorageAccount storageAccount;
+  private final CloudBlobClient blobClient;
+  private final CloudBlobContainer container;
+  private final String azureStorageContainerName;
+  private final String baseFolder;
+  private String applicationID;
+  private String jobFolderName;
+
+  @Inject
+  AzureUploader(
+      final @Parameter(AzureStorageAccountName.class) String accountName,
+      final @Parameter(AzureStorageAccountKey.class) String accountKey,
+      final @Parameter(AzureStorageAccountContainerName.class) String azureStorageContainerName,
+      final @Parameter(AzureStorageBaseFolder.class) String baseFolder)
+      throws URISyntaxException, InvalidKeyException, StorageException {
+
+    this.storageAccount = CloudStorageAccount.parse(getStorageConnectionString(accountName, accountKey));
+    this.blobClient = this.storageAccount.createCloudBlobClient();
+    this.azureStorageContainerName = azureStorageContainerName;
+    this.container = this.blobClient.getContainerReference(azureStorageContainerName);
+    this.container.createIfNotExists();
+    this.baseFolder = baseFolder;
+
+    LOG.log(Level.FINE, "Instantiated AzureUploader connected to azure storage account: {0}", accountName);
+  }
+
+  /**
+   * Assemble a connection string from account name and key.
+   */
+  private static String getStorageConnectionString(final String accountName, final String accountKey) {
+    // "DefaultEndpointsProtocol=http;AccountName=[ACCOUNT_NAME];AccountKey=[ACCOUNT_KEY]"
+    return "DefaultEndpointsProtocol=http;AccountName=" + accountName + ";AccountKey=" + accountKey;
+  }
+
+  public String createJobFolder(final String applicationID) throws IOException {
+    try {
+      this.applicationID = applicationID;
+      this.jobFolderName = assembleJobFolderName(applicationID);
+      // Make the directory entry for the job
+      final CloudBlockBlob jobFolderBlob = this.container.getBlockBlobReference(this.jobFolderName);
+      final String jobFolderURL = getFileSystemURL(jobFolderBlob);
+      return jobFolderURL;
+    } catch (final StorageException | URISyntaxException e) {
+      throw new IOException("Unable to create job Folder", e);
+    }
+  }
+
+  public FileResource uploadFile(final File file) throws IOException {
+
+    final String destination = this.jobFolderName + "/" + file.getName();
+    LOG.log(Level.INFO, "Uploading [{0}] to [{1}]", new Object[]{file, destination});
+
+    try {
+
+      final CloudBlockBlob jobJarBlob = this.container.getBlockBlobReference(destination);
+
+      try (final BufferedInputStream in = new BufferedInputStream(new FileInputStream(file))) {
+        jobJarBlob.upload(in, file.length());
+      }
+
+      if (!jobJarBlob.exists()) {
+        // TODO: If I don't do this check, the getLength() call below returns 0. No idea why.
+        LOG.log(Level.WARNING, "Blob doesn't exist!");
+      }
+
+      LOG.log(Level.FINE, "Uploaded to: {0}",
+          jobJarBlob.getStorageUri().getPrimaryUri());
+
+      // Assemble the FileResource
+      final BlobProperties blobProperties = jobJarBlob.getProperties();
+      return new FileResource()
+          .setType(FileResource.TYPE_ARCHIVE)
+          .setVisibility(FileResource.VISIBILITY_APPLICATION)
+          .setSize(String.valueOf(blobProperties.getLength()))
+          .setTimestamp(String.valueOf(blobProperties.getLastModified().getTime()))
+          .setUrl(getFileSystemURL(jobJarBlob));
+
+    } catch (final URISyntaxException | StorageException e) {
+      throw new IOException(e);
+    }
+  }
+
+  /**
+   * @param blob
+   * @return a HDFS URL for the blob
+   */
+  private String getFileSystemURL(final CloudBlockBlob blob) {
+    final URI primaryURI = blob.getStorageUri().getPrimaryUri();
+    final String path = primaryURI.getPath().replace(this.azureStorageContainerName + "/", "");
+    return "wasb://" + this.azureStorageContainerName + "@" + primaryURI.getHost() + path;
+  }
+
+  private String assembleJobFolderName(final String applicationID) {
+    return this.baseFolder + (this.baseFolder.endsWith("/") ? "" : "/") + applicationID;
+  }
+}


[36/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/HeartBeatManager.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/HeartBeatManager.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/HeartBeatManager.java
new file mode 100644
index 0000000..5dc7b83
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/HeartBeatManager.java
@@ -0,0 +1,173 @@
+/**
+ * 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.reef.runtime.common.evaluator;
+
+import org.apache.reef.proto.EvaluatorRuntimeProtocol;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.evaluator.context.ContextManager;
+import org.apache.reef.runtime.common.evaluator.parameters.DriverRemoteIdentifier;
+import org.apache.reef.runtime.common.evaluator.parameters.HeartbeatPeriod;
+import org.apache.reef.runtime.common.utils.RemoteManager;
+import org.apache.reef.tang.InjectionFuture;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.event.Alarm;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+public class HeartBeatManager {
+
+  private static final Logger LOG = Logger.getLogger(HeartBeatManager.class.getName());
+
+  private final Clock clock;
+  private final int heartbeatPeriod;
+  private final EventHandler<EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto> evaluatorHeartbeatHandler;
+  private final InjectionFuture<EvaluatorRuntime> evaluatorRuntime;
+  private final InjectionFuture<ContextManager> contextManager;
+
+  @Inject
+  private HeartBeatManager(
+      final InjectionFuture<EvaluatorRuntime> evaluatorRuntime,
+      final InjectionFuture<ContextManager> contextManager,
+      final Clock clock,
+      final RemoteManager remoteManager,
+      final @Parameter(HeartbeatPeriod.class) int heartbeatPeriod,
+      final @Parameter(DriverRemoteIdentifier.class) String driverRID) {
+
+    this.evaluatorRuntime = evaluatorRuntime;
+    this.contextManager = contextManager;
+    this.clock = clock;
+    this.heartbeatPeriod = heartbeatPeriod;
+    this.evaluatorHeartbeatHandler = remoteManager.getHandler(
+        driverRID, EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto.class);
+  }
+
+  /**
+   * Assemble a complete new heartbeat and send it out.
+   */
+  public synchronized void sendHeartbeat() {
+    this.sendHeartBeat(this.getEvaluatorHeartbeatProto());
+  }
+
+  /**
+   * Called with a specific TaskStatus that must be delivered to the driver.
+   */
+  public synchronized void sendTaskStatus(final ReefServiceProtos.TaskStatusProto taskStatusProto) {
+    this.sendHeartBeat(this.getEvaluatorHeartbeatProto(
+        this.evaluatorRuntime.get().getEvaluatorStatus(),
+        this.contextManager.get().getContextStatusCollection(),
+        Optional.of(taskStatusProto)));
+  }
+
+  /**
+   * Called with a specific TaskStatus that must be delivered to the driver.
+   */
+  public synchronized void sendContextStatus(
+      final ReefServiceProtos.ContextStatusProto contextStatusProto) {
+
+    // TODO: Write a test that checks for the order.
+    final Collection<ReefServiceProtos.ContextStatusProto> contextStatusList = new ArrayList<>();
+    contextStatusList.add(contextStatusProto);
+    contextStatusList.addAll(this.contextManager.get().getContextStatusCollection());
+
+    final EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto heartbeatProto =
+        this.getEvaluatorHeartbeatProto(
+            this.evaluatorRuntime.get().getEvaluatorStatus(),
+            contextStatusList, Optional.<ReefServiceProtos.TaskStatusProto>empty());
+
+    this.sendHeartBeat(heartbeatProto);
+  }
+
+  /**
+   * Called with a specific EvaluatorStatus that must be delivered to the driver.
+   */
+  public synchronized void sendEvaluatorStatus(
+      final ReefServiceProtos.EvaluatorStatusProto evaluatorStatusProto) {
+    this.sendHeartBeat(EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto.newBuilder()
+        .setTimestamp(System.currentTimeMillis())
+        .setEvaluatorStatus(evaluatorStatusProto)
+        .build());
+  }
+
+  /**
+   * Sends the actual heartbeat out and logs it, so desired.
+   *
+   * @param heartbeatProto
+   */
+  private synchronized void sendHeartBeat(
+      final EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto heartbeatProto) {
+    if (LOG.isLoggable(Level.FINEST)) {
+      LOG.log(Level.FINEST, "Heartbeat message:\n" + heartbeatProto, new Exception("Stack trace"));
+    }
+    this.evaluatorHeartbeatHandler.onNext(heartbeatProto);
+  }
+
+
+  private EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto getEvaluatorHeartbeatProto() {
+    return this.getEvaluatorHeartbeatProto(
+        this.evaluatorRuntime.get().getEvaluatorStatus(),
+        this.contextManager.get().getContextStatusCollection(),
+        this.contextManager.get().getTaskStatus());
+  }
+
+  private final EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto getEvaluatorHeartbeatProto(
+      final ReefServiceProtos.EvaluatorStatusProto evaluatorStatusProto,
+      final Iterable<ReefServiceProtos.ContextStatusProto> contextStatusProtos,
+      final Optional<ReefServiceProtos.TaskStatusProto> taskStatusProto) {
+
+    final EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto.Builder builder =
+        EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto.newBuilder()
+            .setTimestamp(System.currentTimeMillis())
+            .setEvaluatorStatus(evaluatorStatusProto);
+
+    for (final ReefServiceProtos.ContextStatusProto contextStatusProto : contextStatusProtos) {
+      builder.addContextStatus(contextStatusProto);
+    }
+
+    if (taskStatusProto.isPresent()) {
+      builder.setTaskStatus(taskStatusProto.get());
+    }
+
+    return builder.build();
+  }
+
+  final class HeartbeatAlarmHandler implements EventHandler<Alarm> {
+    @Override
+    public void onNext(final Alarm alarm) {
+      synchronized (HeartBeatManager.this) {
+        if (evaluatorRuntime.get().isRunning()) {
+          HeartBeatManager.this.sendHeartbeat();
+          HeartBeatManager.this.clock.scheduleAlarm(HeartBeatManager.this.heartbeatPeriod, this);
+        } else {
+          LOG.log(Level.FINEST,
+              "Not triggering a heartbeat, because state is: {0}",
+              evaluatorRuntime.get().getState());
+        }
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/PIDStoreStartHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/PIDStoreStartHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/PIDStoreStartHandler.java
new file mode 100644
index 0000000..ea3d76a
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/PIDStoreStartHandler.java
@@ -0,0 +1,56 @@
+/**
+ * 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.reef.runtime.common.evaluator;
+
+import org.apache.reef.util.OSUtils;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.PrintWriter;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This Handler writes the Process ID (PID) to a file with a name given in PID_FILE_NAME to the local working directory.
+ */
+public class PIDStoreStartHandler implements EventHandler<StartTime> {
+  public static final String PID_FILE_NAME = "PID.txt";
+  private static final Logger LOG = Logger.getLogger(PIDStoreStartHandler.class.getName());
+
+  @Inject
+  public PIDStoreStartHandler() {
+  }
+
+  @Override
+  public void onNext(final StartTime startTime) {
+    final long pid = OSUtils.getPID();
+    final File outfile = new File(PID_FILE_NAME);
+    LOG.log(Level.FINEST, "Storing pid `" + pid + "` in file " + outfile.getAbsolutePath());
+    try (final PrintWriter p = new PrintWriter((new FileOutputStream(PID_FILE_NAME)))) {
+      p.write(String.valueOf(pid));
+      p.write("\n");
+    } catch (final FileNotFoundException e) {
+      LOG.log(Level.WARNING, "Unable to create PID file.", e);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextClientCodeException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextClientCodeException.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextClientCodeException.java
new file mode 100644
index 0000000..8755f39
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextClientCodeException.java
@@ -0,0 +1,78 @@
+/**
+ * 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.reef.runtime.common.evaluator.context;
+
+import org.apache.reef.evaluator.context.parameters.ContextIdentifier;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.util.Optional;
+
+/**
+ * Thrown when we encounter a problem with client code in a context.
+ */
+public final class ContextClientCodeException extends Exception {
+  private final String contextID;
+  private final Optional<String> parentID;
+
+  /**
+   * @param contextID the ID of the failed context.
+   * @param parentID  the ID of the failed context's parent, if any.
+   * @param message   the error message.
+   * @param cause     the exception that caused the error.
+   */
+  public ContextClientCodeException(final String contextID,
+                                    final Optional<String> parentID,
+                                    final String message,
+                                    final Throwable cause) {
+    super("Failure in context '" + contextID + "': " + message, cause);
+    this.contextID = contextID;
+    this.parentID = parentID;
+  }
+
+  /**
+   * Extracts a context id from the given configuration.
+   *
+   * @param c
+   * @return the context id in the given configuration.
+   * @throws RuntimeException if the configuration can't be parsed.
+   */
+  public static String getIdentifier(final Configuration c) {
+    try {
+      return Tang.Factory.getTang().newInjector(c).getNamedInstance(
+          ContextIdentifier.class);
+    } catch (final InjectionException e) {
+      throw new RuntimeException("Unable to determine context identifier. Giving up.", e);
+    }
+  }
+
+  /**
+   * @return the ID of the failed context
+   */
+  public String getContextID() {
+    return this.contextID;
+  }
+
+  /**
+   * @return the ID of the failed context's parent, if any
+   */
+  public Optional<String> getParentID() {
+    return this.parentID;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextLifeCycle.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextLifeCycle.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextLifeCycle.java
new file mode 100644
index 0000000..586ef89
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextLifeCycle.java
@@ -0,0 +1,97 @@
+/**
+ * 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.reef.runtime.common.evaluator.context;
+
+import org.apache.reef.evaluator.context.ContextMessageSource;
+import org.apache.reef.evaluator.context.events.ContextStart;
+import org.apache.reef.evaluator.context.events.ContextStop;
+import org.apache.reef.evaluator.context.parameters.*;
+import org.apache.reef.runtime.common.utils.BroadCastEventHandler;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+/**
+ * This class is used to trigger all the context life-cycle dependent events.
+ */
+final class ContextLifeCycle {
+
+  private final String identifier;
+  private final Set<EventHandler<ContextStart>> contextStartHandlers;
+  private final Set<EventHandler<ContextStop>> contextStopHandlers;
+  private final Set<ContextMessageSource> contextMessageSources;
+  private final EventHandler<byte[]> contextMessageHandler;
+
+  @Inject
+  ContextLifeCycle(final @Parameter(ContextIdentifier.class) String identifier,
+                   final @Parameter(ContextMessageHandlers.class) Set<EventHandler<byte[]>> contextMessageHandlers,
+                   final @Parameter(ContextStartHandlers.class) Set<EventHandler<ContextStart>> contextStartHandlers,
+                   final @Parameter(ContextStopHandlers.class) Set<EventHandler<ContextStop>> contextStopHandlers,
+                   final @Parameter(ContextMessageSources.class) Set<ContextMessageSource> contextMessageSources) {
+    this.identifier = identifier;
+    this.contextStartHandlers = contextStartHandlers;
+    this.contextStopHandlers = contextStopHandlers;
+    this.contextMessageSources = contextMessageSources;
+    this.contextMessageHandler = new BroadCastEventHandler<>(contextMessageHandlers);
+  }
+
+  /**
+   * Fires ContextStart to all registered event handlers.
+   */
+  final void start() {
+    final ContextStart contextStart = new ContextStartImpl(this.identifier);
+    for (final EventHandler<ContextStart> startHandler : this.contextStartHandlers) {
+      startHandler.onNext(contextStart);
+    }
+  }
+
+  /**
+   * Fires ContextStop to all registered event handlers.
+   */
+  final void close() {
+    final ContextStop contextStop = new ContextStopImpl(this.identifier);
+    for (final EventHandler<ContextStop> stopHandler : this.contextStopHandlers) {
+      stopHandler.onNext(contextStop);
+    }
+  }
+
+  /**
+   * Deliver the driver message to the context message handler
+   *
+   * @param message sent by the driver
+   */
+  final void handleContextMessage(final byte[] message) {
+    this.contextMessageHandler.onNext(message);
+  }
+
+  /**
+   * @return (a shallow copy of) the set of ContextMessageSources configured.
+   */
+  final Set<ContextMessageSource> getContextMessageSources() {
+    return Collections.unmodifiableSet(new LinkedHashSet<>(this.contextMessageSources));
+  }
+
+  final String getIdentifier() {
+    return this.identifier;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextManager.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextManager.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextManager.java
new file mode 100644
index 0000000..e15e1f8
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextManager.java
@@ -0,0 +1,374 @@
+/**
+ * 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.reef.runtime.common.evaluator.context;
+
+import com.google.protobuf.ByteString;
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.EvaluatorRuntimeProtocol;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.evaluator.HeartBeatManager;
+import org.apache.reef.runtime.common.evaluator.task.TaskClientCodeException;
+import org.apache.reef.runtime.common.utils.ExceptionCodec;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.InjectionFuture;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.formats.ConfigurationSerializer;
+import org.apache.reef.util.Optional;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Stack;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Manages the stack of context in the Evaluator.
+ */
+@Private
+@EvaluatorSide
+@Provided
+public final class ContextManager implements AutoCloseable {
+
+  private static final Logger LOG = Logger.getLogger(ContextManager.class.getName());
+
+  /**
+   * The stack of context.
+   */
+  private final Stack<ContextRuntime> contextStack = new Stack<>();
+
+  /**
+   * Used to instantiate the root context.
+   */
+  private final InjectionFuture<RootContextLauncher> launchContext;
+
+  /**
+   * Used for status reporting to the Driver.
+   */
+  private final HeartBeatManager heartBeatManager;
+
+  /**
+   * To serialize Configurations.
+   */
+  private final ConfigurationSerializer configurationSerializer;
+
+  private final ExceptionCodec exceptionCodec;
+
+  /**
+   * @param launchContext           to instantiate the root context.
+   * @param heartBeatManager        for status reporting to the Driver.
+   * @param configurationSerializer
+   * @param exceptionCodec
+   */
+  @Inject
+  ContextManager(final InjectionFuture<RootContextLauncher> launchContext,
+                 final HeartBeatManager heartBeatManager,
+                 final ConfigurationSerializer configurationSerializer,
+                 final ExceptionCodec exceptionCodec) {
+    this.launchContext = launchContext;
+    this.heartBeatManager = heartBeatManager;
+    this.configurationSerializer = configurationSerializer;
+    this.exceptionCodec = exceptionCodec;
+  }
+
+  /**
+   * Start the context manager. This initiates the root context.
+   *
+   * @throws ContextClientCodeException if the root context can't be instantiated.
+   */
+  public void start() throws ContextClientCodeException {
+    synchronized (this.contextStack) {
+      LOG.log(Level.FINEST, "Instantiating root context.");
+      this.contextStack.push(this.launchContext.get().getRootContext());
+
+      if (this.launchContext.get().getInitialTaskConfiguration().isPresent()) {
+        LOG.log(Level.FINEST, "Launching the initial Task");
+        try {
+          this.contextStack.peek().startTask(this.launchContext.get().getInitialTaskConfiguration().get());
+        } catch (final TaskClientCodeException e) {
+          this.handleTaskException(e);
+        }
+      }
+    }
+  }
+
+  /**
+   * Shuts down. This forecefully kills the Task if there is one and then shuts down all Contexts on the stack,
+   * starting at the top.
+   */
+  @Override
+  public void close() {
+    synchronized (this.contextStack) {
+      if (!this.contextStackIsEmpty()) {
+        this.contextStack.lastElement().close();
+      }
+    }
+  }
+
+  /**
+   * @return true if there is no context.
+   */
+  public boolean contextStackIsEmpty() {
+    synchronized (this.contextStack) {
+      return this.contextStack.isEmpty();
+    }
+  }
+
+  /**
+   * Processes the given ContextControlProto to launch / close / suspend Tasks and Contexts.
+   * <p/>
+   * This also triggers the HeartBeatManager to send a heartbeat with the result of this operation.
+   *
+   * @param controlMessage the message to process
+   */
+  public void handleContextControlProtocol(
+      final EvaluatorRuntimeProtocol.ContextControlProto controlMessage) {
+
+    synchronized (this.heartBeatManager) {
+      try {
+        if (controlMessage.hasAddContext() && controlMessage.hasRemoveContext()) {
+          throw new IllegalArgumentException(
+              "Received a message with both add and remove context. This is unsupported.");
+        }
+
+        final byte[] message = controlMessage.hasTaskMessage() ?
+            controlMessage.getTaskMessage().toByteArray() : null;
+
+        if (controlMessage.hasAddContext()) {
+          this.addContext(controlMessage.getAddContext());
+          if (controlMessage.hasStartTask()) {
+            // We support submitContextAndTask()
+            this.startTask(controlMessage.getStartTask());
+          } else {
+            // We need to trigger a heartbeat here.
+            // In other cases, the heartbeat will be triggered by the TaskRuntime
+            // Therefore this call can not go into addContext.
+            this.heartBeatManager.sendHeartbeat();
+          }
+        } else if (controlMessage.hasRemoveContext()) {
+          this.removeContext(controlMessage.getRemoveContext().getContextId());
+        } else if (controlMessage.hasStartTask()) {
+          this.startTask(controlMessage.getStartTask());
+        } else if (controlMessage.hasStopTask()) {
+          this.contextStack.peek().closeTask(message);
+        } else if (controlMessage.hasSuspendTask()) {
+          this.contextStack.peek().suspendTask(message);
+        } else if (controlMessage.hasTaskMessage()) {
+          this.contextStack.peek().deliverTaskMessage(message);
+        } else if (controlMessage.hasContextMessage()) {
+          final EvaluatorRuntimeProtocol.ContextMessageProto contextMessageProto = controlMessage.getContextMessage();
+          boolean deliveredMessage = false;
+          for (final ContextRuntime context : this.contextStack) {
+            if (context.getIdentifier().equals(contextMessageProto.getContextId())) {
+              context.handleContextMessage(contextMessageProto.getMessage().toByteArray());
+              deliveredMessage = true;
+              break;
+            }
+          }
+          if (!deliveredMessage) {
+            throw new IllegalStateException(
+                "Sent message to unknown context " + contextMessageProto.getContextId());
+          }
+        } else {
+          throw new RuntimeException("Unknown task control message: " + controlMessage);
+        }
+      } catch (final TaskClientCodeException e) {
+        this.handleTaskException(e);
+      } catch (final ContextClientCodeException e) {
+        this.handleContextException(e);
+      }
+    }
+
+  }
+
+  /**
+   * @return the TaskStatusProto of the currently running task, if there is any
+   */
+  public Optional<ReefServiceProtos.TaskStatusProto> getTaskStatus() {
+    synchronized (this.contextStack) {
+      if (this.contextStack.isEmpty()) {
+        throw new RuntimeException(
+            "Asked for a Task status while there isn't even a context running.");
+      }
+      return this.contextStack.peek().getTaskStatus();
+    }
+  }
+
+  /**
+   * @return the status of all context in the stack.
+   */
+  public Collection<ReefServiceProtos.ContextStatusProto> getContextStatusCollection() {
+    synchronized (this.contextStack) {
+      final List<ReefServiceProtos.ContextStatusProto> result = new ArrayList<>(this.contextStack.size());
+      for (final ContextRuntime contextRuntime : this.contextStack) {
+        final ReefServiceProtos.ContextStatusProto contextStatusProto = contextRuntime.getContextStatus();
+        LOG.log(Level.FINEST, "Add context status: {0}", contextStatusProto);
+        result.add(contextStatusProto);
+      }
+      return result;
+    }
+  }
+
+  /**
+   * Add a context to the stack.
+   *
+   * @param addContextProto
+   * @throws ContextClientCodeException if there is a client code related issue.
+   */
+  private void addContext(
+      final EvaluatorRuntimeProtocol.AddContextProto addContextProto)
+      throws ContextClientCodeException {
+
+    synchronized (this.contextStack) {
+      try {
+
+        final ContextRuntime currentTopContext = this.contextStack.peek();
+
+        if (!currentTopContext.getIdentifier().equals(addContextProto.getParentContextId())) {
+          throw new IllegalStateException("Trying to instantiate a child context on context with id `" +
+              addContextProto.getParentContextId() + "` while the current top context id is `" +
+              currentTopContext.getIdentifier() + "`");
+        }
+
+        final Configuration contextConfiguration =
+            this.configurationSerializer.fromString(addContextProto.getContextConfiguration());
+
+        final ContextRuntime newTopContext;
+        if (addContextProto.hasServiceConfiguration()) {
+          newTopContext = currentTopContext.spawnChildContext(contextConfiguration,
+              this.configurationSerializer.fromString(addContextProto.getServiceConfiguration()));
+        } else {
+          newTopContext = currentTopContext.spawnChildContext(contextConfiguration);
+        }
+
+        this.contextStack.push(newTopContext);
+
+      } catch (final IOException | BindException e) {
+        throw new RuntimeException("Unable to read configuration.", e);
+      }
+
+    }
+  }
+
+  /**
+   * Remove the context with the given ID from the stack.
+   *
+   * @throws IllegalStateException if the given ID does not refer to the top of stack.
+   */
+  private void removeContext(final String contextID) {
+
+    synchronized (this.contextStack) {
+
+      if (!contextID.equals(this.contextStack.peek().getIdentifier())) {
+        throw new IllegalStateException("Trying to close context with id `" + contextID +
+            "`. But the top context has id `" +
+            this.contextStack.peek().getIdentifier() + "`");
+      }
+
+      this.contextStack.peek().close();
+      if (this.contextStack.size() > 1) {
+        /* We did not close the root context. Therefore, we need to inform the
+         * driver explicitly that this context is closed. The root context notification
+         * is implicit in the Evaluator close/done notification.
+         */
+        this.heartBeatManager.sendHeartbeat(); // Ensure Driver gets notified of context DONE state
+      }
+      this.contextStack.pop();
+      System.gc(); // TODO sure??
+    }
+  }
+
+  /**
+   * Launch a Task.
+   */
+  private void startTask(
+      final EvaluatorRuntimeProtocol.StartTaskProto startTaskProto) throws TaskClientCodeException {
+
+    synchronized (this.contextStack) {
+
+      final ContextRuntime currentActiveContext = this.contextStack.peek();
+
+      final String expectedContextId = startTaskProto.getContextId();
+      if (!expectedContextId.equals(currentActiveContext.getIdentifier())) {
+        throw new IllegalStateException("Task expected context `" + expectedContextId +
+            "` but the active context has ID `" + currentActiveContext.getIdentifier() + "`");
+      }
+
+      try {
+        final Configuration taskConfig =
+            this.configurationSerializer.fromString(startTaskProto.getConfiguration());
+        currentActiveContext.startTask(taskConfig);
+      } catch (IOException | BindException e) {
+        throw new RuntimeException("Unable to read configuration.", e);
+      }
+    }
+  }
+
+  /**
+   * THIS ASSUMES THAT IT IS CALLED ON A THREAD HOLDING THE LOCK ON THE HeartBeatManager
+   */
+  private void handleTaskException(final TaskClientCodeException e) {
+
+    LOG.log(Level.SEVERE, "TaskClientCodeException", e);
+
+    final ByteString exception = ByteString.copyFrom(this.exceptionCodec.toBytes(e.getCause()));
+
+    final ReefServiceProtos.TaskStatusProto taskStatus =
+        ReefServiceProtos.TaskStatusProto.newBuilder()
+            .setContextId(e.getContextId())
+            .setTaskId(e.getTaskId())
+            .setResult(exception)
+            .setState(ReefServiceProtos.State.FAILED)
+            .build();
+
+    LOG.log(Level.SEVERE, "Sending heartbeat: {0}", taskStatus);
+
+    this.heartBeatManager.sendTaskStatus(taskStatus);
+  }
+
+  /**
+   * THIS ASSUMES THAT IT IS CALLED ON A THREAD HOLDING THE LOCK ON THE HeartBeatManager
+   */
+  private void handleContextException(final ContextClientCodeException e) {
+
+    LOG.log(Level.SEVERE, "ContextClientCodeException", e);
+
+    final ByteString exception = ByteString.copyFrom(this.exceptionCodec.toBytes(e.getCause()));
+
+    final ReefServiceProtos.ContextStatusProto.Builder contextStatusBuilder =
+        ReefServiceProtos.ContextStatusProto.newBuilder()
+            .setContextId(e.getContextID())
+            .setContextState(ReefServiceProtos.ContextStatusProto.State.FAIL)
+            .setError(exception);
+
+    if (e.getParentID().isPresent()) {
+      contextStatusBuilder.setParentId(e.getParentID().get());
+    }
+
+    final ReefServiceProtos.ContextStatusProto contextStatus = contextStatusBuilder.build();
+
+    LOG.log(Level.SEVERE, "Sending heartbeat: {0}", contextStatus);
+
+    this.heartBeatManager.sendContextStatus(contextStatus);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextRuntime.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextRuntime.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextRuntime.java
new file mode 100644
index 0000000..044f5c4
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextRuntime.java
@@ -0,0 +1,436 @@
+/**
+ * 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.reef.runtime.common.evaluator.context;
+
+import com.google.protobuf.ByteString;
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.evaluator.context.ContextMessage;
+import org.apache.reef.evaluator.context.ContextMessageSource;
+import org.apache.reef.evaluator.context.parameters.Services;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.evaluator.task.TaskClientCodeException;
+import org.apache.reef.runtime.common.evaluator.task.TaskRuntime;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.util.Optional;
+
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The evaluator side resourcemanager for Contexts.
+ */
+@Provided
+@Private
+@EvaluatorSide
+public final class ContextRuntime {
+
+  private static final Logger LOG = Logger.getLogger(ContextRuntime.class.getName());
+
+  /**
+   * Context-local injector. This contains information that will not be available in child injectors.
+   */
+  private final Injector contextInjector;
+
+  /**
+   * Service injector. State in this injector moves to child injectors.
+   */
+  private final Injector serviceInjector;
+
+  /**
+   * Convenience class to hold all the event handlers for the context as well as the service instances.
+   */
+  private final ContextLifeCycle contextLifeCycle;
+  /**
+   * The parent context, if there is any.
+   */
+  private final Optional<ContextRuntime> parentContext; // guarded by this
+  /**
+   * The child context, if there is any.
+   */
+  private Optional<ContextRuntime> childContext = Optional.empty(); // guarded by this
+  /**
+   * The currently running task, if there is any.
+   */
+  private Optional<TaskRuntime> task = Optional.empty(); // guarded by this
+
+  private Thread taskRuntimeThread = null;
+
+  // TODO: Which lock guards this?
+  private ReefServiceProtos.ContextStatusProto.State contextState =
+      ReefServiceProtos.ContextStatusProto.State.READY;
+
+  /**
+   * Create a new ContextRuntime.
+   *
+   * @param serviceInjector      the serviceInjector to be used.
+   * @param contextConfiguration the Configuration for this context.
+   * @throws ContextClientCodeException if the context cannot be instantiated.
+   */
+  ContextRuntime(final Injector serviceInjector, final Configuration contextConfiguration,
+                 final Optional<ContextRuntime> parentContext) throws ContextClientCodeException {
+
+    this.serviceInjector = serviceInjector;
+    this.parentContext = parentContext;
+
+    // Trigger the instantiation of the services
+    try {
+
+      final Set<Object> services = serviceInjector.getNamedInstance(Services.class);
+      this.contextInjector = serviceInjector.forkInjector(contextConfiguration);
+
+      this.contextLifeCycle = this.contextInjector.getInstance(ContextLifeCycle.class);
+
+    } catch (BindException | InjectionException e) {
+
+      final Optional<String> parentID = this.getParentContext().isPresent() ?
+          Optional.of(this.getParentContext().get().getIdentifier()) :
+          Optional.<String>empty();
+
+      throw new ContextClientCodeException(
+          ContextClientCodeException.getIdentifier(contextConfiguration),
+          parentID, "Unable to spawn context", e);
+    }
+
+    // Trigger the context start events on contextInjector.
+    this.contextLifeCycle.start();
+  }
+
+  /**
+   * Create a new ContextRuntime for the root context.
+   *
+   * @param serviceInjector      the serviceInjector to be used.
+   * @param contextConfiguration the Configuration for this context.
+   * @throws ContextClientCodeException if the context cannot be instantiated.
+   */
+  ContextRuntime(final Injector serviceInjector,
+                 final Configuration contextConfiguration) throws ContextClientCodeException {
+    this(serviceInjector, contextConfiguration, Optional.<ContextRuntime>empty());
+    LOG.log(Level.FINEST, "Instantiating root context");
+  }
+
+
+  /**
+   * Spawns a new context.
+   * <p/>
+   * The new context will have a serviceInjector that is created by forking the one in this object with the given
+   * serviceConfiguration. The contextConfiguration is used to fork the contextInjector from that new serviceInjector.
+   *
+   * @param contextConfiguration the new context's context (local) Configuration.
+   * @param serviceConfiguration the new context's service Configuration.
+   * @return a child context.
+   * @throws ContextClientCodeException If the context can't be instantiate due to user code / configuration issues
+   * @throws IllegalStateException      If this method is called when there is either a task or child context already
+   *                                    present.
+   */
+  ContextRuntime spawnChildContext(
+      final Configuration contextConfiguration,
+      final Configuration serviceConfiguration) throws ContextClientCodeException {
+
+    synchronized (this.contextLifeCycle) {
+
+      if (this.task.isPresent()) {
+        throw new IllegalStateException(
+            "Attempting to spawn a child context when a Task with id '" +
+                this.task.get().getId() + "' is running.");
+      }
+
+      if (this.childContext.isPresent()) {
+        throw new IllegalStateException(
+            "Attempting to instantiate a child context on a context that is not the topmost active context");
+      }
+
+      try {
+
+        final Injector childServiceInjector =
+            this.serviceInjector.forkInjector(serviceConfiguration);
+
+        final ContextRuntime childContext =
+            new ContextRuntime(childServiceInjector, contextConfiguration, Optional.of(this));
+
+        this.childContext = Optional.of(childContext);
+        return childContext;
+
+      } catch (final BindException e) {
+
+        final Optional<String> parentID = this.getParentContext().isPresent() ?
+            Optional.of(this.getParentContext().get().getIdentifier()) :
+            Optional.<String>empty();
+
+        throw new ContextClientCodeException(
+            ContextClientCodeException.getIdentifier(contextConfiguration),
+            parentID, "Unable to spawn context", e);
+      }
+    }
+  }
+
+  /**
+   * Spawns a new context without services of its own.
+   * <p/>
+   * The new context will have a serviceInjector that is created by forking the one in this object. The
+   * contextConfiguration is used to fork the contextInjector from that new serviceInjector.
+   *
+   * @param contextConfiguration the new context's context (local) Configuration.
+   * @return a child context.
+   * @throws ContextClientCodeException If the context can't be instantiate due to user code / configuration issues.
+   * @throws IllegalStateException      If this method is called when there is either a task or child context already
+   *                                    present.
+   */
+  ContextRuntime spawnChildContext(
+      final Configuration contextConfiguration) throws ContextClientCodeException {
+
+    synchronized (this.contextLifeCycle) {
+
+      if (this.task.isPresent()) {
+        throw new IllegalStateException(
+            "Attempting to to spawn a child context while a Task with id '" +
+                this.task.get().getId() + "' is running.");
+      }
+
+      if (this.childContext.isPresent()) {
+        throw new IllegalStateException(
+            "Attempting to spawn a child context on a context that is not the topmost active context");
+      }
+
+      final Injector childServiceInjector = this.serviceInjector.forkInjector();
+      final ContextRuntime childContext =
+          new ContextRuntime(childServiceInjector, contextConfiguration, Optional.of(this));
+
+      this.childContext = Optional.of(childContext);
+      return childContext;
+    }
+  }
+
+  /**
+   * Launches a Task on this context.
+   *
+   * @param taskConfig the configuration to be used for the task.
+   * @throws org.apache.reef.runtime.common.evaluator.task.TaskClientCodeException If the Task cannot be instantiated due to user code / configuration issues.
+   * @throws IllegalStateException                                                 If this method is called when there is either a task or child context already present.
+   */
+  void startTask(final Configuration taskConfig) throws TaskClientCodeException {
+
+    synchronized (this.contextLifeCycle) {
+
+      if (this.task.isPresent() && this.task.get().hasEnded()) {
+        // clean up state
+        this.task = Optional.empty();
+      }
+
+      if (this.task.isPresent()) {
+        throw new IllegalStateException("Attempting to start a Task when a Task with id '" +
+            this.task.get().getId() + "' is running.");
+      }
+
+      if (this.childContext.isPresent()) {
+        throw new IllegalStateException(
+            "Attempting to start a Task on a context that is not the topmost active context");
+      }
+
+      try {
+        final Injector taskInjector = this.contextInjector.forkInjector(taskConfig);
+        final TaskRuntime taskRuntime = taskInjector.getInstance(TaskRuntime.class);
+        taskRuntime.initialize();
+        this.taskRuntimeThread = new Thread(taskRuntime, taskRuntime.getId());
+        this.taskRuntimeThread.start();
+        this.task = Optional.of(taskRuntime);
+        LOG.log(Level.FINEST, "Started task: {0}", taskRuntime.getTaskId());
+      } catch (final BindException | InjectionException e) {
+        throw new TaskClientCodeException(TaskClientCodeException.getTaskId(taskConfig),
+            this.getIdentifier(),
+            "Unable to instantiate the new task", e);
+      } catch (final Throwable t) {
+        throw new TaskClientCodeException(TaskClientCodeException.getTaskId(taskConfig),
+            this.getIdentifier(),
+            "Unable to start the new task", t);
+      }
+    }
+  }
+
+  /**
+   * Close this context. If there is a child context, this recursively closes it before closing this context. If
+   * there is a Task currently running, that will be closed.
+   */
+  final void close() {
+
+    synchronized (this.contextLifeCycle) {
+
+      this.contextState = ReefServiceProtos.ContextStatusProto.State.DONE;
+
+      if (this.task.isPresent()) {
+        LOG.log(Level.WARNING, "Shutting down a task because the underlying context is being closed.");
+        this.task.get().close(null);
+      }
+
+      if (this.childContext.isPresent()) {
+        LOG.log(Level.WARNING, "Closing a context because its parent context is being closed.");
+        this.childContext.get().close();
+      }
+
+      this.contextLifeCycle.close();
+
+      if (this.parentContext.isPresent()) {
+        this.parentContext.get().resetChildContext();
+      }
+    }
+  }
+
+  /**
+   * @return the parent context, if there is one.
+   */
+  Optional<ContextRuntime> getParentContext() {
+    return this.parentContext;
+  }
+
+  /**
+   * Deliver the given message to the Task.
+   * <p/>
+   * Note that due to races, the task might have already ended. In that case, we drop this call and leave a WARNING
+   * in the log.
+   *
+   * @param message the suspend message to deliver or null if there is none.
+   */
+  void suspendTask(final byte[] message) {
+    synchronized (this.contextLifeCycle) {
+      if (!this.task.isPresent()) {
+        LOG.log(Level.WARNING, "Received a suspend task while there was no task running. Ignoring.");
+      } else {
+        this.task.get().suspend(message);
+      }
+    }
+  }
+
+  /**
+   * Issue a close call to the Task
+   * <p/>
+   * Note that due to races, the task might have already ended. In that case, we drop this call and leave a WARNING
+   * in the log.
+   *
+   * @param message the close  message to deliver or null if there is none.
+   */
+  void closeTask(final byte[] message) {
+    synchronized (this.contextLifeCycle) {
+      if (!this.task.isPresent()) {
+        LOG.log(Level.WARNING, "Received a close task while there was no task running. Ignoring.");
+      } else {
+        this.task.get().close(message);
+      }
+    }
+  }
+
+  /**
+   * Deliver a message to the Task
+   * <p/>
+   * Note that due to races, the task might have already ended. In that case, we drop this call and leave a WARNING
+   * in the log.
+   *
+   * @param message the close  message to deliver or null if there is none.
+   */
+  void deliverTaskMessage(final byte[] message) {
+    synchronized (this.contextLifeCycle) {
+      if (!this.task.isPresent()) {
+        LOG.log(Level.WARNING, "Received a task message while there was no task running. Ignoring.");
+      } else {
+        this.task.get().deliver(message);
+      }
+    }
+  }
+
+  /**
+   * @return the identifier of this context.
+   */
+  String getIdentifier() {
+    return this.contextLifeCycle.getIdentifier();
+  }
+
+  /**
+   * Handle the context message.
+   *
+   * @param message sent by the driver
+   */
+  final void handleContextMessage(final byte[] message) {
+    this.contextLifeCycle.handleContextMessage(message);
+  }
+
+  /**
+   * @return the state of the running Task, if one is running.
+   */
+  Optional<ReefServiceProtos.TaskStatusProto> getTaskStatus() {
+    synchronized (this.contextLifeCycle) {
+      if (this.task.isPresent()) {
+        if (this.task.get().hasEnded()) {
+          this.task = Optional.empty();
+          return Optional.empty();
+        } else {
+          return Optional.of(this.task.get().getStatusProto());
+        }
+      } else {
+        return Optional.empty();
+      }
+    }
+  }
+
+  /**
+   * Called by the child context when it has been closed.
+   */
+  private void resetChildContext() {
+    synchronized (this.contextLifeCycle) {
+      if (this.childContext.isPresent()) {
+        this.childContext = Optional.empty();
+      } else {
+        throw new IllegalStateException("no child context set");
+      }
+    }
+  }
+
+  /**
+   * @return this context's status in protocol buffer form.
+   */
+  ReefServiceProtos.ContextStatusProto getContextStatus() {
+
+    synchronized (this.contextLifeCycle) {
+
+      final ReefServiceProtos.ContextStatusProto.Builder builder =
+          ReefServiceProtos.ContextStatusProto.newBuilder()
+              .setContextId(this.getIdentifier())
+              .setContextState(this.contextState);
+
+      if (this.parentContext.isPresent()) {
+        builder.setParentId(this.parentContext.get().getIdentifier());
+      }
+
+      for (final ContextMessageSource contextMessageSource : this.contextLifeCycle.getContextMessageSources()) {
+        final Optional<ContextMessage> contextMessageOptional = contextMessageSource.getMessage();
+        if (contextMessageOptional.isPresent()) {
+          builder.addContextMessage(ReefServiceProtos.ContextStatusProto.ContextMessageProto.newBuilder()
+              .setSourceId(contextMessageOptional.get().getMessageSourceID())
+              .setMessage(ByteString.copyFrom(contextMessageOptional.get().get()))
+              .build());
+        }
+      }
+
+      return builder.build();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextStartImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextStartImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextStartImpl.java
new file mode 100644
index 0000000..8ca4349
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextStartImpl.java
@@ -0,0 +1,37 @@
+/**
+ * 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.reef.runtime.common.evaluator.context;
+
+
+import org.apache.reef.evaluator.context.events.ContextStart;
+
+final class ContextStartImpl implements ContextStart {
+
+  private final String identifier;
+
+
+  ContextStartImpl(final String identifier) {
+    this.identifier = identifier;
+  }
+
+  @Override
+  public String getId() {
+    return this.identifier;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextStopImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextStopImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextStopImpl.java
new file mode 100644
index 0000000..74e1b10
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/ContextStopImpl.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.runtime.common.evaluator.context;
+
+import org.apache.reef.evaluator.context.events.ContextStop;
+
+final class ContextStopImpl implements ContextStop {
+
+  private final String identifier;
+
+  ContextStopImpl(final String identifier) {
+    this.identifier = identifier;
+  }
+
+  @Override
+  public String getId() {
+    return this.identifier;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/RootContextLauncher.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/RootContextLauncher.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/RootContextLauncher.java
new file mode 100644
index 0000000..448949c
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/RootContextLauncher.java
@@ -0,0 +1,134 @@
+/**
+ * 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.reef.runtime.common.evaluator.context;
+
+import org.apache.reef.runtime.common.evaluator.parameters.InitialTaskConfiguration;
+import org.apache.reef.runtime.common.evaluator.parameters.RootContextConfiguration;
+import org.apache.reef.runtime.common.evaluator.parameters.RootServiceConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.formats.ConfigurationSerializer;
+import org.apache.reef.util.Optional;
+
+import javax.inject.Inject;
+import java.io.IOException;
+
+/**
+ * Helper class that encapsulates the root context configuration: With or without services and an initial task.
+ */
+final class RootContextLauncher {
+
+  private final Injector injector;
+  private final Configuration rootContextConfiguration;
+  private final Optional<Configuration> rootServiceConfiguration;
+  private final Optional<Configuration> initialTaskConfiguration;
+  private final ConfigurationSerializer configurationSerializer;
+  private ContextRuntime rootContext = null;
+
+  @Inject
+  RootContextLauncher(final @Parameter(RootContextConfiguration.class) String rootContextConfiguration,
+                      final @Parameter(RootServiceConfiguration.class) String rootServiceConfiguration,
+                      final @Parameter(InitialTaskConfiguration.class) String initialTaskConfiguration,
+                      final Injector injector, final ConfigurationSerializer configurationSerializer) throws IOException, BindException {
+    this.injector = injector;
+    this.configurationSerializer = configurationSerializer;
+    this.rootContextConfiguration = this.configurationSerializer.fromString(rootContextConfiguration);
+    this.rootServiceConfiguration = Optional.of(this.configurationSerializer.fromString(rootServiceConfiguration));
+    this.initialTaskConfiguration = Optional.of(this.configurationSerializer.fromString(initialTaskConfiguration));
+  }
+
+  @Inject
+  RootContextLauncher(final @Parameter(RootContextConfiguration.class) String rootContextConfiguration,
+                      final Injector injector,
+                      final @Parameter(RootServiceConfiguration.class) String rootServiceConfiguration, final ConfigurationSerializer configurationSerializer) throws IOException, BindException {
+    this.injector = injector;
+    this.configurationSerializer = configurationSerializer;
+    this.rootContextConfiguration = this.configurationSerializer.fromString(rootContextConfiguration);
+    this.rootServiceConfiguration = Optional.of(this.configurationSerializer.fromString(rootServiceConfiguration));
+    this.initialTaskConfiguration = Optional.empty();
+  }
+
+  @Inject
+  RootContextLauncher(final Injector injector,
+                      final @Parameter(RootContextConfiguration.class) String rootContextConfiguration,
+                      final @Parameter(InitialTaskConfiguration.class) String initialTaskConfiguration, final ConfigurationSerializer configurationSerializer) throws IOException, BindException {
+    this.injector = injector;
+    this.configurationSerializer = configurationSerializer;
+    this.rootContextConfiguration = this.configurationSerializer.fromString(rootContextConfiguration);
+    this.rootServiceConfiguration = Optional.empty();
+    this.initialTaskConfiguration = Optional.of(this.configurationSerializer.fromString(initialTaskConfiguration));
+  }
+
+  @Inject
+  RootContextLauncher(final @Parameter(RootContextConfiguration.class) String rootContextConfiguration,
+                      final Injector injector, final ConfigurationSerializer configurationSerializer) throws IOException, BindException {
+    this.injector = injector;
+    this.configurationSerializer = configurationSerializer;
+    this.rootContextConfiguration = this.configurationSerializer.fromString(rootContextConfiguration);
+    this.rootServiceConfiguration = Optional.empty();
+    this.initialTaskConfiguration = Optional.empty();
+  }
+
+  /**
+   * Instantiates the root context.
+   * <p/>
+   * This also launches the initial task if there is any.
+   *
+   * @param injector
+   * @param rootContextConfiguration
+   * @param rootServiceConfiguration
+   * @return ContextRuntime
+   * @throws ContextClientCodeException
+   */
+  private static ContextRuntime getRootContext(final Injector injector,
+                                               final Configuration rootContextConfiguration,
+                                               final Optional<Configuration> rootServiceConfiguration)
+      throws ContextClientCodeException {
+    final ContextRuntime result;
+    if (rootServiceConfiguration.isPresent()) {
+      final Injector rootServiceInjector;
+      try {
+        rootServiceInjector = injector.forkInjector(rootServiceConfiguration.get());
+      } catch (final BindException e) {
+        throw new ContextClientCodeException(ContextClientCodeException.getIdentifier(rootContextConfiguration),
+            Optional.<String>empty(), "Unable to instatiate the root context", e);
+      }
+      result = new ContextRuntime(rootServiceInjector, rootContextConfiguration);
+    } else {
+      result = new ContextRuntime(injector.forkInjector(), rootContextConfiguration);
+    }
+    return result;
+  }
+
+  /**
+   * @return the root context for this evaluator.
+   */
+  final ContextRuntime getRootContext() throws ContextClientCodeException {
+    if (null == this.rootContext) {
+      this.rootContext = getRootContext(this.injector, this.rootContextConfiguration, this.rootServiceConfiguration);
+    }
+    return this.rootContext;
+  }
+
+  final Optional<Configuration> getInitialTaskConfiguration() {
+    return this.initialTaskConfiguration;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/DefaultContextMessageHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/DefaultContextMessageHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/DefaultContextMessageHandler.java
new file mode 100644
index 0000000..0007c00
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/DefaultContextMessageHandler.java
@@ -0,0 +1,45 @@
+/**
+ * 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.reef.runtime.common.evaluator.context.defaults;
+
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.evaluator.context.ContextMessageHandler;
+import org.apache.reef.evaluator.context.parameters.ContextIdentifier;
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+
+/**
+ * Default handler for messages sent by the driver: Crash the context.
+ */
+@EvaluatorSide
+public final class DefaultContextMessageHandler implements ContextMessageHandler {
+
+  private final String contextID;
+
+  @Inject
+  DefaultContextMessageHandler(final @Parameter(ContextIdentifier.class) String contextID) {
+    this.contextID = contextID;
+  }
+
+  @Override
+  public void onNext(final byte[] message) {
+    throw new IllegalStateException("No message handlers given for context " + this.contextID);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/DefaultContextMessageSource.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/DefaultContextMessageSource.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/DefaultContextMessageSource.java
new file mode 100644
index 0000000..ed7a7af
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/DefaultContextMessageSource.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.runtime.common.evaluator.context.defaults;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.evaluator.context.ContextMessage;
+import org.apache.reef.evaluator.context.ContextMessageSource;
+import org.apache.reef.util.Optional;
+
+import javax.inject.Inject;
+
+/**
+ * Default ContextMessageSource: return nothing.
+ */
+@EvaluatorSide
+@Provided
+public final class DefaultContextMessageSource implements ContextMessageSource {
+
+  @Inject
+  public DefaultContextMessageSource() {
+  }
+
+  @Override
+  public Optional<ContextMessage> getMessage() {
+    return Optional.empty();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/DefaultContextStartHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/DefaultContextStartHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/DefaultContextStartHandler.java
new file mode 100644
index 0000000..a3fbce5
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/DefaultContextStartHandler.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.runtime.common.evaluator.context.defaults;
+
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.evaluator.context.events.ContextStart;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default handler for ContextStart
+ */
+@EvaluatorSide
+public final class DefaultContextStartHandler implements EventHandler<ContextStart> {
+
+  @Inject
+  DefaultContextStartHandler() {
+  }
+
+  @Override
+  public void onNext(final ContextStart contextStart) {
+    Logger.getLogger(this.getClass().toString()).log(Level.INFO, "DefaultContextStartHandler received: " + contextStart);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/DefaultContextStopHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/DefaultContextStopHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/DefaultContextStopHandler.java
new file mode 100644
index 0000000..4031a4b
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/DefaultContextStopHandler.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.runtime.common.evaluator.context.defaults;
+
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.evaluator.context.events.ContextStop;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default event handler for ContextStop
+ */
+@EvaluatorSide
+public final class DefaultContextStopHandler implements EventHandler<ContextStop> {
+
+  @Inject
+  DefaultContextStopHandler() {
+  }
+
+  @Override
+  public void onNext(final ContextStop contextStop) {
+    Logger.getLogger(this.getClass().toString()).log(Level.INFO, "DefaultContextStopHandler received: " + contextStop);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/package-info.java
new file mode 100644
index 0000000..5e572c7
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/defaults/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Default implementations for the optional context interfaces.
+ */
+package org.apache.reef.runtime.common.evaluator.context.defaults;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/package-info.java
new file mode 100644
index 0000000..f7d4390
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/context/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Context implementation of the Evaluator resourcemanager.
+ */
+package org.apache.reef.runtime.common.evaluator.context;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/package-info.java
new file mode 100644
index 0000000..78acce3
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Evaluator-side implementation of the REEF API.
+ */
+package org.apache.reef.runtime.common.evaluator;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/ApplicationIdentifier.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/ApplicationIdentifier.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/ApplicationIdentifier.java
new file mode 100644
index 0000000..6d405f8
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/ApplicationIdentifier.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.runtime.common.evaluator.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The RM application/job identifier.
+ * <p/>
+ * In YARN, this is the applicationID assigned by the resource manager.
+ */
+@NamedParameter(doc = "The RM application/job identifier.")
+public final class ApplicationIdentifier implements Name<String> {
+  private ApplicationIdentifier() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/DriverRemoteIdentifier.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/DriverRemoteIdentifier.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/DriverRemoteIdentifier.java
new file mode 100644
index 0000000..b9e803e
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/DriverRemoteIdentifier.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.runtime.common.evaluator.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The identifier used by the Evaluator to connect back to the Driver.
+ */
+@NamedParameter(doc = "The identifier used by the Evaluator to connect back to the Driver.")
+public final class DriverRemoteIdentifier implements Name<String> {
+  private DriverRemoteIdentifier() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/EvaluatorIdentifier.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/EvaluatorIdentifier.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/EvaluatorIdentifier.java
new file mode 100644
index 0000000..d0fa894
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/EvaluatorIdentifier.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.runtime.common.evaluator.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The evaluator identifier.
+ */
+@NamedParameter(doc = "The evaluator identifier.")
+public final class EvaluatorIdentifier implements Name<String> {
+  private EvaluatorIdentifier() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/HeartbeatPeriod.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/HeartbeatPeriod.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/HeartbeatPeriod.java
new file mode 100644
index 0000000..20804c6
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/HeartbeatPeriod.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.runtime.common.evaluator.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The evaluator heartbeat period in ms.
+ */
+@NamedParameter(doc = "The evaluator heartbeat period in ms.", default_value = "5000")
+public final class HeartbeatPeriod implements Name<Integer> {
+  private HeartbeatPeriod() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/InitialTaskConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/InitialTaskConfiguration.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/InitialTaskConfiguration.java
new file mode 100644
index 0000000..b9d80cd
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/InitialTaskConfiguration.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.runtime.common.evaluator.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * An initial task to launch on startup.
+ */
+@NamedParameter(doc = "An initial task to launch on startup.")
+public final class InitialTaskConfiguration implements Name<String> {
+  private InitialTaskConfiguration() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/RootContextConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/RootContextConfiguration.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/RootContextConfiguration.java
new file mode 100644
index 0000000..d4bc566
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/RootContextConfiguration.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.runtime.common.evaluator.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The evaluator root context configuration.
+ */
+@NamedParameter(doc = "The evaluator root context configuration.")
+public final class RootContextConfiguration implements Name<String> {
+  private RootContextConfiguration() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/RootServiceConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/RootServiceConfiguration.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/RootServiceConfiguration.java
new file mode 100644
index 0000000..aabc326
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/parameters/RootServiceConfiguration.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.runtime.common.evaluator.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The service configuration for the root context
+ */
+@NamedParameter(doc = "The service configuration for the root context")
+public final class RootServiceConfiguration implements Name<String> {
+  private RootServiceConfiguration() {
+  }
+}


[41/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/Naming.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/Naming.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/Naming.java
new file mode 100644
index 0000000..8779b95
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/Naming.java
@@ -0,0 +1,26 @@
+/**
+ * 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.reef.io.naming;
+
+/**
+ * Implementations of this interface facilitate address lookups based on
+ * Identifiers and allow to register and unregister addresses for Identifiers.
+ */
+public interface Naming extends NamingLookup, NamingRegistry {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/NamingLookup.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/NamingLookup.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/NamingLookup.java
new file mode 100644
index 0000000..4fb7d15
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/NamingLookup.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.io.naming;
+
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.wake.Identifier;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+
+/**
+ * Implementations of this interface facilitate address lookups based on
+ * Identifiers.
+ */
+@Public
+public interface NamingLookup {
+
+  /**
+   * Lookup an Address for a given Identifier.
+   *
+   * @param id
+   * @return
+   * @throws IOException
+   */
+  public InetSocketAddress lookup(final Identifier id) throws Exception;
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/NamingRegistry.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/NamingRegistry.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/NamingRegistry.java
new file mode 100644
index 0000000..0d4f6c5
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/NamingRegistry.java
@@ -0,0 +1,46 @@
+/**
+ * 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.reef.io.naming;
+
+import org.apache.reef.wake.Identifier;
+
+import java.net.InetSocketAddress;
+
+/**
+ * Allows to register and unregister addresses for Identifiers.
+ */
+public interface NamingRegistry {
+
+  /**
+   * Register the given Address for the given Identifier
+   *
+   * @param id
+   * @param addr
+   * @throws Exception
+   */
+  public void register(final Identifier id, final InetSocketAddress addr) throws Exception;
+
+  /**
+   * Unregister the given Identifier from the registry
+   *
+   * @param id
+   * @throws Exception
+   */
+  public void unregister(final Identifier id) throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/package-info.java
new file mode 100644
index 0000000..702f401
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/package-info.java
@@ -0,0 +1,24 @@
+/**
+ * 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.
+ */
+/**
+ * APIs for I/O in REEF: {@link org.apache.reef.io.Codec}s and {@link org.apache.reef.io.Serializer}s
+ */
+@Unstable package org.apache.reef.io;
+
+import org.apache.reef.annotations.Unstable;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/serialization/Codec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/serialization/Codec.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/serialization/Codec.java
new file mode 100644
index 0000000..5e69d4f
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/serialization/Codec.java
@@ -0,0 +1,45 @@
+/**
+ * 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.reef.io.serialization;
+
+/**
+ * Interface for serialization routines that translate back and forth between
+ * byte arrays with low latency. (Contrast to Serializer, Deserializer, which
+ * optimize for file size and throughput.)
+ *
+ * @param <T> The type of the objects (de-)serialized
+ */
+public interface Codec<T> {
+
+  /**
+   * Encodes the given object into a Byte Array
+   *
+   * @param obj
+   * @return a byte[] representation of the object
+   */
+  public byte[] encode(T obj);
+
+  /**
+   * Decodes the given byte array into an object
+   *
+   * @param buf
+   * @return the decoded object
+   */
+  public T decode(byte[] buf);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/serialization/Deserializer.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/serialization/Deserializer.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/serialization/Deserializer.java
new file mode 100644
index 0000000..25ffe0a
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/serialization/Deserializer.java
@@ -0,0 +1,37 @@
+/**
+ * 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.reef.io.serialization;
+
+/**
+ * Stream-based multi-object deserialization interface. This class wraps an
+ * instance of InType in an iterator that deserializes its contents, and returns
+ * it as a stream of objects.
+ *
+ * @param <ObjectType>
+ * @param <InType>
+ */
+public interface Deserializer<ObjectType, InType> {
+  /**
+   * Deserialize a stream of input.
+   *
+   * @param arg
+   * @return
+   */
+  public Iterable<ObjectType> create(InType arg);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/serialization/SerializableCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/serialization/SerializableCodec.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/serialization/SerializableCodec.java
new file mode 100644
index 0000000..dbfd1dd
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/serialization/SerializableCodec.java
@@ -0,0 +1,67 @@
+/**
+ * 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.reef.io.serialization;
+
+import javax.inject.Inject;
+import java.io.*;
+import java.util.logging.Logger;
+
+/**
+ * A {@link Codec} for {@link Serializable} objects.
+ * <p/>
+ * It uses java serialization, use with caution.
+ *
+ * @param <T> The type of objects Serialized
+ */
+public class SerializableCodec<T extends Serializable> implements Codec<T> {
+
+  private static final Logger LOG = Logger.getLogger(SerializableCodec.class.getName());
+
+  /**
+   * Default constructor for TANG use.
+   */
+  @Inject
+  public SerializableCodec() {
+  }
+
+  @Override
+  public byte[] encode(final T obj) {
+    try (final ByteArrayOutputStream bout = new ByteArrayOutputStream()) {
+      try (final ObjectOutputStream out = new ObjectOutputStream(bout)) {
+        out.writeObject(obj);
+      }
+      return bout.toByteArray();
+    } catch (final IOException ex) {
+      throw new RuntimeException("Unable to encode: " + obj, ex);
+    }
+  }
+
+  @Override
+  public T decode(final byte[] buf) {
+    try {
+      try (final ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(buf))) {
+        final T result = (T) oin.readObject();
+        return result;
+      }
+    } catch (final IOException | ClassNotFoundException ex) {
+      throw new RuntimeException("Unable to decode.", ex);
+    }
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/serialization/Serializer.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/serialization/Serializer.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/serialization/Serializer.java
new file mode 100644
index 0000000..08f3c94
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/serialization/Serializer.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.io.serialization;
+
+import org.apache.reef.io.Accumulable;
+
+/**
+ * Stream-based multi-object serialization interface. Implementations of this
+ * interface should take an OutType as a constructor parameter.
+ *
+ * @param <ObjectType>
+ * @param <OutType>
+ */
+public interface Serializer<ObjectType, OutType> {
+  /**
+   * Serialize a stream of objects.
+   *
+   * @param arg
+   * @return
+   */
+  public Accumulable<ObjectType> create(OutType arg);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/DriverRestartCompleted.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/DriverRestartCompleted.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/DriverRestartCompleted.java
new file mode 100644
index 0000000..843c85e
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/DriverRestartCompleted.java
@@ -0,0 +1,28 @@
+/**
+ * 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.reef.runtime.common;
+
+import org.apache.reef.wake.time.Time;
+
+public final class DriverRestartCompleted extends Time {
+
+  public DriverRestartCompleted(final long timestamp) {
+    super(timestamp);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/Launcher.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/Launcher.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/Launcher.java
new file mode 100644
index 0000000..451648b
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/Launcher.java
@@ -0,0 +1,156 @@
+/**
+ * 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.reef.runtime.common;
+
+import org.apache.reef.runtime.common.launch.LaunchClass;
+import org.apache.reef.runtime.common.launch.REEFErrorHandler;
+import org.apache.reef.runtime.common.launch.REEFMessageCodec;
+import org.apache.reef.runtime.common.launch.parameters.ClockConfigurationPath;
+import org.apache.reef.runtime.common.launch.parameters.ErrorHandlerRID;
+import org.apache.reef.runtime.common.launch.parameters.LaunchID;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.CommandLine;
+import org.apache.reef.util.EnvironmentUtils;
+import org.apache.reef.util.ThreadLogger;
+import org.apache.reef.util.logging.LoggingSetup;
+import org.apache.reef.wake.remote.RemoteConfiguration;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The main entrance point into any REEF process. It is mostly instantiating LaunchClass and calling .run() on it.
+ */
+public final class Launcher {
+
+  private final static Logger LOG = Logger.getLogger(Launcher.class.getName());
+
+  static {
+    LoggingSetup.setupCommonsLogging();
+  }
+
+  private Launcher() {
+  }
+
+  /**
+   * Parse command line options of the launcher.
+   *
+   * @param args Command line as passed into main().
+   * @return TANG configuration object.
+   */
+  private static Configuration processCommandLine(
+      final String[] args) throws BindException, IOException, InjectionException {
+
+    final JavaConfigurationBuilder commandLineBuilder =
+        Tang.Factory.getTang().newConfigurationBuilder();
+
+    new CommandLine(commandLineBuilder)
+        .registerShortNameOfClass(ClockConfigurationPath.class)
+        .registerShortNameOfClass(ErrorHandlerRID.class)
+        .registerShortNameOfClass(LaunchID.class)
+        .processCommandLine(args);
+
+    return commandLineBuilder
+        // Bind the wake error handler
+        .bindNamedParameter(RemoteConfiguration.ErrorHandler.class, REEFErrorHandler.class)
+        .bindNamedParameter(RemoteConfiguration.ManagerName.class, "REEF_LAUNCHER")
+            // Bind the wake codec
+        .bindNamedParameter(RemoteConfiguration.MessageCodec.class, REEFMessageCodec.class)
+        .build();
+  }
+
+  private static void fail(final String msg, final Throwable t) {
+    LOG.log(Level.SEVERE, msg, t);
+    throw new RuntimeException(msg, t);
+  }
+
+
+  /**
+   * Launches a REEF client process (Driver or Evaluator).
+   *
+   * @param args
+   * @throws Exception
+   */
+  public static void main(final String[] args) {
+    LOG.log(Level.FINE, "Launcher started with user name [{0}]", System.getProperty("user.name"));
+
+    LOG.log(Level.FINE, "Launcher started. Assertions are {0} in this process.",
+        EnvironmentUtils.areAssertionsEnabled() ? "ENABLED" : "DISABLED");
+    Injector injector = null;
+    try {
+      injector = Tang.Factory.getTang().newInjector(processCommandLine(args));
+    } catch (final BindException | IOException | InjectionException e) {
+      fail("Error in parsing the command line", e);
+    }
+
+    try (final LaunchClass lc = injector.getInstance(LaunchClass.class)) {
+      LOG.log(Level.FINE, "Launcher starting");
+      lc.run();
+      LOG.log(Level.FINE, "Launcher exiting");
+    } catch (final Throwable throwable) {
+      fail("Unable to run LaunchClass", throwable);
+    }
+
+    LOG.log(Level.INFO, "Exiting Launcher.main()");
+    if (LOG.isLoggable(Level.FINEST)) {
+      LOG.log(Level.FINEST, ThreadLogger.getFormattedThreadList("Threads running after Launcher.close():"));
+    }
+    System.exit(0);
+    if (LOG.isLoggable(Level.FINEST)) {
+      LOG.log(Level.FINEST, ThreadLogger.getFormattedThreadList("Threads running after System.exit():"));
+    }
+  }
+
+  /**
+   * Pass values of the properties specified in the propNames array as <code>-D...</code>
+   * command line parameters. Currently used only to pass logging configuration to child JVMs processes.
+   *
+   * @param vargs     List of command line parameters to append to.
+   * @param copyNull  create an empty parameter if the property is missing in current process.
+   * @param propNames property names.
+   */
+  public static void propagateProperties(
+      final Collection<String> vargs, final boolean copyNull, final String... propNames) {
+    for (final String propName : propNames) {
+      final String propValue = System.getProperty(propName);
+      if (propValue == null || propValue.isEmpty()) {
+        if (copyNull) {
+          vargs.add("-D" + propName);
+        }
+      } else {
+        vargs.add(String.format("-D%s=%s", propName, propValue));
+      }
+    }
+  }
+
+  /**
+   * Same as above, but with copyNull == false by default.
+   */
+  public static void propagateProperties(
+      final Collection<String> vargs, final String... propNames) {
+    propagateProperties(vargs, false, propNames);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/ClientWireUp.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/ClientWireUp.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/ClientWireUp.java
new file mode 100644
index 0000000..b6506ca
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/ClientWireUp.java
@@ -0,0 +1,104 @@
+/**
+ * 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.reef.runtime.common.client;
+
+
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.client.parameters.ClientPresent;
+import org.apache.reef.runtime.common.utils.RemoteManager;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.util.Optional;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Used on the Client side to setup event handlers and such.
+ */
+@ClientSide
+@Private
+final class ClientWireUp {
+  private static final Logger LOG = Logger.getLogger(ClientWireUp.class.getName());
+  private final RuntimeErrorProtoHandler runtimeErrorProtoHandler;
+  private final JobStatusMessageHandler jobStatusMessageHandler;
+  private final Optional<RemoteManager> remoteManager;
+  private final boolean isClientPresent;
+  private boolean isWired = false;
+
+  @Inject
+  ClientWireUp(final RemoteManager remoteManager,
+               final @Parameter(ClientPresent.class) String clientPresent,
+               final RuntimeErrorProtoHandler runtimeErrorProtoHandler,
+               final JobStatusMessageHandler jobStatusMessageHandler) {
+    this.remoteManager = Optional.ofNullable(remoteManager);
+    this.runtimeErrorProtoHandler = runtimeErrorProtoHandler;
+    this.jobStatusMessageHandler = jobStatusMessageHandler;
+    this.isClientPresent = clientPresent.equals(ClientPresent.YES);
+    LOG.log(Level.FINE, "Instantiated 'ClientWireUp'. Client present: " + this.isClientPresent());
+  }
+
+  @Inject
+  ClientWireUp(final @Parameter(ClientPresent.class) String clientPresent,
+               final RuntimeErrorProtoHandler runtimeErrorProtoHandler,
+               final JobStatusMessageHandler jobStatusMessageHandler) {
+    this(null, clientPresent, runtimeErrorProtoHandler, jobStatusMessageHandler);
+  }
+
+  synchronized void performWireUp() {
+    if (this.isWired) {
+      throw new IllegalStateException("performWireUp is only to be called once.");
+    }
+    if (this.remoteManager.isPresent()) {
+      LOG.log(Level.FINEST, "Wiring up communications channels to the Driver.");
+      final RemoteManager rm = this.remoteManager.get();
+      rm.registerHandler(ReefServiceProtos.RuntimeErrorProto.class, this.runtimeErrorProtoHandler);
+      rm.registerHandler(ReefServiceProtos.JobStatusProto.class, this.jobStatusMessageHandler);
+      LOG.log(Level.FINE, "Wired up communications channels to the Driver.");
+    }
+    this.isWired = true;
+  }
+
+  synchronized boolean isClientPresent() {
+    return this.isClientPresent;
+  }
+
+  synchronized String getRemoteManagerIdentifier() {
+    if (!this.isClientPresent() || !this.remoteManager.isPresent()) {
+      throw new RuntimeException("No need to setup the remote manager.");
+    } else {
+      return this.remoteManager.get().getMyIdentifier();
+    }
+  }
+
+  /**
+   * Closes the remote manager, if there was one.
+   */
+  synchronized void close() {
+    if (this.remoteManager.isPresent()) {
+      try {
+        this.remoteManager.get().close();
+      } catch (final Exception e) {
+        LOG.log(Level.WARNING, "Exception while shutting down the RemoteManager.", e);
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/CommonClientConfigurationModule.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/CommonClientConfigurationModule.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/CommonClientConfigurationModule.java
new file mode 100644
index 0000000..59892e9
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/CommonClientConfigurationModule.java
@@ -0,0 +1,28 @@
+/**
+ * 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.reef.runtime.common.client;
+
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+
+
+public class CommonClientConfigurationModule extends ConfigurationModuleBuilder {
+  public final static ConfigurationModule CONF = new CommonClientConfigurationModule()
+      .build();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/CompletedJobImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/CompletedJobImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/CompletedJobImpl.java
new file mode 100644
index 0000000..908ea54
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/CompletedJobImpl.java
@@ -0,0 +1,46 @@
+/**
+ * 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.reef.runtime.common.client;
+
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.client.CompletedJob;
+
+/**
+ * An implementation of CompletedJob
+ */
+@ClientSide
+@Private
+final class CompletedJobImpl implements CompletedJob {
+  private final String jobId;
+
+  CompletedJobImpl(final String jobId) {
+    this.jobId = jobId;
+  }
+
+  @Override
+  public String getId() {
+    return this.jobId;
+  }
+
+  @Override
+  public String toString() {
+    return "CompletedJob{'" + jobId + "'}";
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/JobStatusMessageHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/JobStatusMessageHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/JobStatusMessageHandler.java
new file mode 100644
index 0000000..2ef9706
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/JobStatusMessageHandler.java
@@ -0,0 +1,50 @@
+/**
+ * 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.reef.runtime.common.client;
+
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.RemoteMessage;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A Handler for JobStatus messages from running jobs
+ */
+@ClientSide
+@Private
+final class JobStatusMessageHandler implements EventHandler<RemoteMessage<ReefServiceProtos.JobStatusProto>> {
+  private final Logger LOG = Logger.getLogger(JobStatusMessageHandler.class.getName());
+  private final RunningJobs runningJobs;
+
+  @Inject
+  JobStatusMessageHandler(final RunningJobs runningJobs) {
+    this.runningJobs = runningJobs;
+    LOG.log(Level.FINE, "Instantiated 'JobStatusMessageHandler'");
+  }
+
+  @Override
+  public void onNext(RemoteMessage<ReefServiceProtos.JobStatusProto> jobStatusProtoRemoteMessage) {
+    this.runningJobs.onJobStatusMessage(jobStatusProtoRemoteMessage);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/JobSubmissionHelper.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/JobSubmissionHelper.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/JobSubmissionHelper.java
new file mode 100644
index 0000000..6b89c09
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/JobSubmissionHelper.java
@@ -0,0 +1,180 @@
+/**
+ * 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.reef.runtime.common.client;
+
+import org.apache.reef.driver.parameters.*;
+import org.apache.reef.proto.ClientRuntimeProtocol;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.ConfigurationSerializer;
+import org.apache.reef.util.JARFileMaker;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Shared code between job submission with and without client
+ */
+final class JobSubmissionHelper {
+
+  static {
+    System.out.println(
+        "\nPowered by\n" +
+            "     ___________  ______  ______  _______\n" +
+            "    /  ______  / /  ___/ /  ___/ /  ____/\n" +
+            "   /     _____/ /  /__  /  /__  /  /___\n" +
+            "  /  /\\  \\     /  ___/ /  ___/ /  ____/\n" +
+            " /  /  \\  \\   /  /__  /  /__  /  /\n" +
+            "/__/    \\__\\ /_____/ /_____/ /__/\n"
+    );
+  }
+
+  private static final Logger LOG = Logger.getLogger(JobSubmissionHelper.class.getName());
+
+  private final ConfigurationSerializer configurationSerializer;
+
+  @Inject
+  JobSubmissionHelper(final ConfigurationSerializer configurationSerializer) {
+    this.configurationSerializer = configurationSerializer;
+  }
+
+  /**
+   * Fils out a JobSubmissionProto based on the driver configuration given.
+   *
+   * @param driverConfiguration
+   * @return
+   * @throws InjectionException
+   * @throws IOException
+   */
+  final ClientRuntimeProtocol.JobSubmissionProto.Builder getJobsubmissionProto(final Configuration driverConfiguration) throws InjectionException, IOException {
+    final Injector injector = Tang.Factory.getTang().newInjector(driverConfiguration);
+
+    final ClientRuntimeProtocol.JobSubmissionProto.Builder jbuilder = ClientRuntimeProtocol.JobSubmissionProto.newBuilder()
+        .setIdentifier(returnOrGenerateDriverId(injector.getNamedInstance(DriverIdentifier.class)))
+        .setDriverMemory(injector.getNamedInstance(DriverMemory.class))
+        .setUserName(System.getProperty("user.name"))
+        .setConfiguration(configurationSerializer.toString(driverConfiguration));
+
+
+    for (final String globalFileName : injector.getNamedInstance(JobGlobalFiles.class)) {
+      LOG.log(Level.FINEST, "Adding global file: {0}", globalFileName);
+      jbuilder.addGlobalFile(getFileResourceProto(globalFileName, ReefServiceProtos.FileType.PLAIN));
+    }
+
+    for (final String globalLibraryName : injector.getNamedInstance(JobGlobalLibraries.class)) {
+      LOG.log(Level.FINEST, "Adding global library: {0}", globalLibraryName);
+      jbuilder.addGlobalFile(getFileResourceProto(globalLibraryName, ReefServiceProtos.FileType.LIB));
+    }
+
+    for (final String localFileName : injector.getNamedInstance(DriverLocalFiles.class)) {
+      LOG.log(Level.FINEST, "Adding local file: {0}", localFileName);
+      jbuilder.addLocalFile(getFileResourceProto(localFileName, ReefServiceProtos.FileType.PLAIN));
+    }
+
+    for (final String localLibraryName : injector.getNamedInstance(DriverLocalLibraries.class)) {
+      LOG.log(Level.FINEST, "Adding local library: {0}", localLibraryName);
+      jbuilder.addLocalFile(getFileResourceProto(localLibraryName, ReefServiceProtos.FileType.LIB));
+    }
+
+    return jbuilder;
+  }
+
+
+  /**
+   * @param configuredId
+   * @return the given driver ID (if it is not the default) or generates a new unique one if it is.
+   */
+  private static String returnOrGenerateDriverId(final String configuredId) {
+    final String result;
+    if (configuredId.equals(DriverIdentifier.DEFAULT_VALUE)) {
+      // Generate a uniqe driver ID
+      LOG.log(Level.FINE, "No Job Identifier given. Generating a unique one.");
+      result = "REEF-" + System.getProperty("user.name", "UNKNOWN_USER") + "-" + System.currentTimeMillis();
+    } else {
+      result = configuredId;
+    }
+    return result;
+  }
+
+
+  /**
+   * Turns a pathname into the right protocol for job submission.
+   *
+   * @param fileName
+   * @param type
+   * @return
+   * @throws IOException
+   */
+  private static ReefServiceProtos.FileResourceProto getFileResourceProto(final String fileName, final ReefServiceProtos.FileType type) throws IOException {
+    File file = new File(fileName);
+    if (file.exists()) {
+      // It is a local file and can be added.
+      if (file.isDirectory()) {
+        // If it is a directory, create a JAR file of it and add that instead.
+        file = toJar(file);
+      }
+      return ReefServiceProtos.FileResourceProto.newBuilder()
+          .setName(file.getName())
+          .setPath(file.getPath())
+          .setType(type)
+          .build();
+    } else {
+      // The file isn't in the local filesytem. Assume that the file is actually a URI.
+      // We then assume that the underlying resource manager knows how to deal with it.
+      try {
+        final URI uri = new URI(fileName);
+        final String path = uri.getPath();
+        final String name = path.substring(path.lastIndexOf('/') + 1);
+        return ReefServiceProtos.FileResourceProto.newBuilder()
+            .setName(name)
+            .setPath(uri.toString())
+            .setType(type)
+            .build();
+      } catch (final URISyntaxException e) {
+        throw new IOException("Unable to parse URI.", e);
+      }
+    }
+  }
+
+  /**
+   * Turns temporary folder "foo" into a jar file "foo.jar"
+   *
+   * @param file
+   * @return
+   * @throws IOException
+   */
+  private static File toJar(final File file) throws IOException {
+    final File tempFolder = Files.createTempDirectory("reef-tmp-tempFolder").toFile();
+    final File jarFile = File.createTempFile(file.getCanonicalFile().getName(), ".jar", tempFolder);
+    LOG.log(Level.FINEST, "Adding contents of folder {0} to {1}", new Object[]{file, jarFile});
+    try (final JARFileMaker jarMaker = new JARFileMaker(jarFile)) {
+      jarMaker.addChildren(file);
+    }
+    return jarFile;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/REEFImplementation.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/REEFImplementation.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/REEFImplementation.java
new file mode 100644
index 0000000..f0074f9
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/REEFImplementation.java
@@ -0,0 +1,110 @@
+/**
+ * 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.reef.runtime.common.client;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.client.REEF;
+import org.apache.reef.proto.ClientRuntimeProtocol.JobSubmissionProto;
+import org.apache.reef.runtime.common.client.api.JobSubmissionHandler;
+import org.apache.reef.runtime.common.launch.parameters.ErrorHandlerRID;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.util.REEFVersion;
+import org.apache.reef.util.logging.LoggingScope;
+import org.apache.reef.util.logging.LoggingScopeFactory;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@ClientSide
+@Provided
+@Private
+public final class REEFImplementation implements REEF {
+
+  private final static Logger LOG = Logger.getLogger(REEFImplementation.class.getName());
+
+  private final JobSubmissionHandler jobSubmissionHandler;
+  private final RunningJobs runningJobs;
+  private final JobSubmissionHelper jobSubmissionHelper;
+  private final ClientWireUp clientWireUp;
+  private final LoggingScopeFactory loggingScopeFactory;
+
+  /**
+   * @param jobSubmissionHandler
+   * @param runningJobs
+   * @param jobSubmissionHelper
+   * @param jobStatusMessageHandler is passed only to make sure it is instantiated
+   * @param clientWireUp
+   * @param reefVersion             provides the current version of REEF.
+   */
+  @Inject
+  REEFImplementation(final JobSubmissionHandler jobSubmissionHandler,
+                     final RunningJobs runningJobs,
+                     final JobSubmissionHelper jobSubmissionHelper,
+                     final JobStatusMessageHandler jobStatusMessageHandler,
+                     final ClientWireUp clientWireUp,
+                     final LoggingScopeFactory loggingScopeFactory,
+                     final REEFVersion reefVersion) {
+    this.jobSubmissionHandler = jobSubmissionHandler;
+    this.runningJobs = runningJobs;
+    this.jobSubmissionHelper = jobSubmissionHelper;
+    this.clientWireUp = clientWireUp;
+    clientWireUp.performWireUp();
+    this.loggingScopeFactory = loggingScopeFactory;
+    reefVersion.logVersion();
+  }
+
+  @Override
+  public final void close() {
+    this.runningJobs.closeAllJobs();
+    this.clientWireUp.close();
+  }
+
+  @Override
+  public void submit(final Configuration driverConf) {
+    try (LoggingScope ls = this.loggingScopeFactory.reefSubmit()) {
+      final JobSubmissionProto submissionMessage;
+      try {
+        if (this.clientWireUp.isClientPresent()) {
+          submissionMessage = this.jobSubmissionHelper.getJobsubmissionProto(driverConf)
+              .setRemoteId(this.clientWireUp.getRemoteManagerIdentifier())
+              .build();
+        } else {
+          submissionMessage = this.jobSubmissionHelper.getJobsubmissionProto(driverConf)
+              .setRemoteId(ErrorHandlerRID.NONE)
+              .build();
+        }
+      } catch (final Exception e) {
+        throw new RuntimeException("Exception while processing driver configuration.", e);
+      }
+
+      this.jobSubmissionHandler.onNext(submissionMessage);
+    }
+  }
+
+  @NamedParameter(doc = "The driver remote identifier.")
+  public final static class DriverRemoteIdentifier implements Name<String> {
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/RunningJobImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/RunningJobImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/RunningJobImpl.java
new file mode 100644
index 0000000..c41597a
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/RunningJobImpl.java
@@ -0,0 +1,168 @@
+/**
+ * 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.reef.runtime.common.client;
+
+import com.google.protobuf.ByteString;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.client.CompletedJob;
+import org.apache.reef.client.FailedJob;
+import org.apache.reef.client.JobMessage;
+import org.apache.reef.client.RunningJob;
+import org.apache.reef.client.parameters.JobCompletedHandler;
+import org.apache.reef.client.parameters.JobFailedHandler;
+import org.apache.reef.client.parameters.JobMessageHandler;
+import org.apache.reef.client.parameters.JobRunningHandler;
+import org.apache.reef.driver.parameters.DriverIdentifier;
+import org.apache.reef.proto.ClientRuntimeProtocol.JobControlProto;
+import org.apache.reef.proto.ClientRuntimeProtocol.Signal;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.proto.ReefServiceProtos.JobStatusProto;
+import org.apache.reef.runtime.common.utils.ExceptionCodec;
+import org.apache.reef.runtime.common.utils.RemoteManager;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Implementation of RunningJob.
+ */
+@ClientSide
+@Private
+public final class RunningJobImpl implements RunningJob, EventHandler<JobStatusProto> {
+
+  private static final Logger LOG = Logger.getLogger(RunningJob.class.getName());
+
+  private final String jobId;
+
+  private final EventHandler<JobControlProto> jobControlHandler;
+  private final EventHandler<RunningJob> runningJobEventHandler;
+  private final EventHandler<CompletedJob> completedJobEventHandler;
+  private final EventHandler<FailedJob> failedJobEventHandler;
+  private final EventHandler<JobMessage> jobMessageEventHandler;
+  private final ExceptionCodec exceptionCodec;
+
+  @Inject
+  RunningJobImpl(final RemoteManager remoteManager,
+                 final @Parameter(DriverIdentifier.class) String driverIdentifier,
+                 final @Parameter(REEFImplementation.DriverRemoteIdentifier.class) String driverRID,
+                 final @Parameter(JobRunningHandler.class) EventHandler<RunningJob> runningJobEventHandler,
+                 final @Parameter(JobCompletedHandler.class) EventHandler<CompletedJob> completedJobEventHandler,
+                 final @Parameter(JobFailedHandler.class) EventHandler<FailedJob> failedJobEventHandler,
+                 final @Parameter(JobMessageHandler.class) EventHandler<JobMessage> jobMessageEventHandler,
+                 final ExceptionCodec exceptionCodec) {
+
+    this.jobId = driverIdentifier;
+    this.runningJobEventHandler = runningJobEventHandler;
+    this.completedJobEventHandler = completedJobEventHandler;
+    this.failedJobEventHandler = failedJobEventHandler;
+    this.jobMessageEventHandler = jobMessageEventHandler;
+    this.exceptionCodec = exceptionCodec;
+    this.jobControlHandler = remoteManager.getHandler(driverRID, JobControlProto.class);
+
+    this.runningJobEventHandler.onNext(this);
+    LOG.log(Level.FINE, "Instantiated 'RunningJobImpl'");
+  }
+
+  @Override
+  public synchronized void close() {
+    this.jobControlHandler.onNext(
+        JobControlProto.newBuilder()
+            .setIdentifier(this.jobId)
+            .setSignal(Signal.SIG_TERMINATE)
+            .build()
+    );
+  }
+
+  @Override
+  public synchronized void close(final byte[] message) {
+    this.jobControlHandler.onNext(
+        JobControlProto.newBuilder()
+            .setIdentifier(this.jobId)
+            .setSignal(Signal.SIG_TERMINATE)
+            .setMessage(ByteString.copyFrom(message))
+            .build()
+    );
+  }
+
+  @Override
+  public String getId() {
+    return this.jobId;
+  }
+
+  @Override
+  public synchronized void send(final byte[] message) {
+    this.jobControlHandler.onNext(
+        JobControlProto.newBuilder()
+            .setIdentifier(this.jobId)
+            .setMessage(ByteString.copyFrom(message))
+            .build()
+    );
+  }
+
+  @Override
+  public synchronized void onNext(final JobStatusProto value) {
+
+    final ReefServiceProtos.State state = value.getState();
+    LOG.log(Level.FINEST, "Received job status: {0} from {1}",
+        new Object[]{state, value.getIdentifier()});
+
+    if (value.hasMessage()) {
+      this.jobMessageEventHandler.onNext(
+          new JobMessage(getId(), value.getMessage().toByteArray()));
+    }
+    if (state == ReefServiceProtos.State.DONE) {
+      this.completedJobEventHandler.onNext(new CompletedJobImpl(this.getId()));
+    } else if (state == ReefServiceProtos.State.FAILED) {
+      this.onJobFailure(value);
+    }
+  }
+
+  /**
+   * Inform the client of a failed job.
+   *
+   * @param jobStatusProto
+   */
+  private synchronized void onJobFailure(final JobStatusProto jobStatusProto) {
+    assert (jobStatusProto.getState() == ReefServiceProtos.State.FAILED);
+
+    final String id = this.jobId;
+    final Optional<byte[]> data = jobStatusProto.hasException() ?
+        Optional.of(jobStatusProto.getException().toByteArray()) :
+        Optional.<byte[]>empty();
+    final Optional<Throwable> cause = this.exceptionCodec.fromBytes(data);
+
+    final String message = cause.isPresent() ?
+        cause.get().getMessage() :
+        "No Message sent by the Job";
+    final Optional<String> description = Optional.of(message);
+
+    final FailedJob failedJob = new FailedJob(id, message, description, cause, data);
+    this.failedJobEventHandler.onNext(failedJob);
+  }
+
+  @Override
+  public String toString() {
+    return "RunningJob{'" + this.jobId + "'}";
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/RunningJobs.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/RunningJobs.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/RunningJobs.java
new file mode 100644
index 0000000..7c9bbb7
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/RunningJobs.java
@@ -0,0 +1,55 @@
+/**
+ * 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.reef.runtime.common.client;
+
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.tang.annotations.DefaultImplementation;
+import org.apache.reef.wake.remote.RemoteMessage;
+
+/**
+ * Manages the RunningJobs a client knows about
+ */
+@Private
+@ClientSide
+@DefaultImplementation(RunningJobsImpl.class)
+interface RunningJobs {
+
+  /**
+   * Closes all registered jobs forcefully.
+   */
+  public void closeAllJobs();
+
+  /**
+   * Processes a status message from a Job. If the Job is already known, the message will be passed on. If it is a
+   * first message, a new RunningJob instance will be created for it.
+   *
+   * @param message
+   */
+  public void onJobStatusMessage(final RemoteMessage<ReefServiceProtos.JobStatusProto> message);
+
+  /**
+   * Processes a error message from the resource manager.
+   *
+   * @param runtimeFailure
+   */
+  public void onRuntimeErrorMessage(final RemoteMessage<ReefServiceProtos.RuntimeErrorProto> runtimeFailure);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/RunningJobsImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/RunningJobsImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/RunningJobsImpl.java
new file mode 100644
index 0000000..7a9ed05
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/RunningJobsImpl.java
@@ -0,0 +1,148 @@
+/**
+ * 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.reef.runtime.common.client;
+
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.client.FailedRuntime;
+import org.apache.reef.client.parameters.ResourceManagerErrorHandler;
+import org.apache.reef.driver.parameters.DriverIdentifier;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.tang.InjectionFuture;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.RemoteMessage;
+
+import javax.inject.Inject;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@ClientSide
+@Private
+final class RunningJobsImpl implements RunningJobs {
+  private static final Logger LOG = Logger.getLogger(RunningJobsImpl.class.getName());
+  private final Map<String, RunningJobImpl> jobs = new HashMap<>();
+  private final Injector injector;
+  private final InjectionFuture<EventHandler<FailedRuntime>> failedRuntimeEventHandler;
+
+  @Inject
+  RunningJobsImpl(final Injector injector,
+                  final @Parameter(ResourceManagerErrorHandler.class) InjectionFuture<EventHandler<FailedRuntime>> failedRuntimeEventHandler) {
+    this.injector = injector;
+    this.failedRuntimeEventHandler = failedRuntimeEventHandler;
+    LOG.log(Level.FINE, "Instantiated 'RunningJobImpl'");
+  }
+
+
+  @Override
+  public synchronized void closeAllJobs() {
+    for (final RunningJobImpl runningJob : this.jobs.values()) {
+      LOG.log(Level.WARNING, "Force close job {0}", runningJob.getId());
+      runningJob.close();
+    }
+  }
+
+  @Override
+  public synchronized void onJobStatusMessage(final RemoteMessage<ReefServiceProtos.JobStatusProto> message) {
+    final ReefServiceProtos.JobStatusProto status = message.getMessage();
+    final String jobIdentifier = status.getIdentifier();
+    LOG.log(Level.FINE, "Processing message from Job: " + jobIdentifier);
+
+    if (status.getState() == ReefServiceProtos.State.INIT) {
+      try {
+        final RunningJobImpl runningJob = this.newRunningJob(status.getIdentifier(), message.getIdentifier().toString());
+        this.put(runningJob);
+      } catch (final BindException | InjectionException configError) {
+        throw new RuntimeException("Configuration error for: " + status, configError);
+      }
+    }
+
+    this.get(jobIdentifier).onNext(status);
+    if ((status.getState() != ReefServiceProtos.State.RUNNING) &&
+        (status.getState() != ReefServiceProtos.State.INIT)) {
+      this.remove(status.getIdentifier());
+    }
+    LOG.log(Level.FINE, "Done processing message from Job " + jobIdentifier);
+  }
+
+  @Override
+  public synchronized void onRuntimeErrorMessage(RemoteMessage<ReefServiceProtos.RuntimeErrorProto> runtimeFailure) {
+    try {
+      this.remove(runtimeFailure.getMessage().getIdentifier());
+    } finally {
+      this.failedRuntimeEventHandler.get().onNext(new FailedRuntime(runtimeFailure.getMessage()));
+    }
+  }
+
+
+  /**
+   * A guarded get() that throws an exception if the RunningJob isn't known
+   *
+   * @param jobIdentifier
+   * @return
+   */
+  private synchronized RunningJobImpl get(final String jobIdentifier) {
+    final RunningJobImpl result = this.jobs.get(jobIdentifier);
+    if (null == result) {
+      throw new RuntimeException("Trying to get a RunningJob that is unknown: " + jobIdentifier);
+    }
+    return result;
+  }
+
+  /**
+   * A guarded remove() that throws an exception if no RunningJob is known for this id.
+   *
+   * @param jobIdentifier
+   */
+  private synchronized void remove(final String jobIdentifier) {
+    final RunningJobImpl result = this.jobs.remove(jobIdentifier);
+    if (null == result) {
+      throw new RuntimeException("Trying to remove a RunningJob that is unknown: " + jobIdentifier);
+    }
+  }
+
+
+  private synchronized void put(final RunningJobImpl runningJob) {
+    final String jobIdentifier = runningJob.getId();
+    if (this.jobs.containsKey(jobIdentifier)) {
+      throw new IllegalStateException("Trying to re-add a job that is already known: " + jobIdentifier);
+    }
+    LOG.log(Level.FINE, "Adding Job with ID: " + jobIdentifier);
+    this.jobs.put(jobIdentifier, runningJob);
+  }
+
+  /**
+   * @param jobIdentifier
+   * @param remoteIdentifier
+   * @return
+   * @throws BindException
+   * @throws InjectionException
+   */
+  private synchronized RunningJobImpl newRunningJob(final String jobIdentifier, final String remoteIdentifier) throws BindException, InjectionException {
+    final Injector child = this.injector.forkInjector();
+    child.bindVolatileParameter(REEFImplementation.DriverRemoteIdentifier.class, remoteIdentifier);
+    child.bindVolatileParameter(DriverIdentifier.class, jobIdentifier);
+    return child.getInstance(RunningJobImpl.class);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/RuntimeErrorProtoHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/RuntimeErrorProtoHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/RuntimeErrorProtoHandler.java
new file mode 100644
index 0000000..71d7895
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/RuntimeErrorProtoHandler.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.reef.runtime.common.client;
+
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.tang.InjectionFuture;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.RemoteMessage;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Used in REEFImplementation.
+ */
+final class RuntimeErrorProtoHandler implements EventHandler<RemoteMessage<ReefServiceProtos.RuntimeErrorProto>> {
+
+  private final static Logger LOG = Logger.getLogger(RuntimeErrorProtoHandler.class.getName());
+
+  private final InjectionFuture<RunningJobs> runningJobs;
+
+  @Inject
+  RuntimeErrorProtoHandler(final InjectionFuture<RunningJobs> runningJobs) {
+    this.runningJobs = runningJobs;
+  }
+
+
+  @Override
+  public void onNext(final RemoteMessage<ReefServiceProtos.RuntimeErrorProto> error) {
+    LOG.log(Level.WARNING, "{0} Runtime Error: {1}", new Object[]{
+        error.getIdentifier(), error.getMessage().getMessage()});
+    this.runningJobs.get().onRuntimeErrorMessage(error);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/api/ClientRuntimeParameters.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/api/ClientRuntimeParameters.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/api/ClientRuntimeParameters.java
new file mode 100644
index 0000000..cdc418b
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/api/ClientRuntimeParameters.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.runtime.common.client.api;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+public final class ClientRuntimeParameters {
+
+  @NamedParameter(doc = "The runtime error handler RID.")
+  public final static class RuntimeErrorHandlerRID implements Name<String> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/api/JobSubmissionHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/api/JobSubmissionHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/api/JobSubmissionHandler.java
new file mode 100644
index 0000000..af2d064
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/api/JobSubmissionHandler.java
@@ -0,0 +1,30 @@
+/**
+ * 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.reef.runtime.common.client.api;
+
+import org.apache.reef.annotations.audience.RuntimeAuthor;
+import org.apache.reef.proto.ClientRuntimeProtocol.JobSubmissionProto;
+import org.apache.reef.wake.EventHandler;
+
+@RuntimeAuthor
+public interface JobSubmissionHandler extends EventHandler<JobSubmissionProto>, AutoCloseable {
+
+  @Override
+  public void close();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/api/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/api/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/api/package-info.java
new file mode 100644
index 0000000..7480e61
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/api/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Client-Side Event Handlers to be implemented by a specific resourcemanager
+ */
+package org.apache.reef.runtime.common.client.api;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultCompletedJobHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultCompletedJobHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultCompletedJobHandler.java
new file mode 100644
index 0000000..2f4d7d4
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultCompletedJobHandler.java
@@ -0,0 +1,47 @@
+/**
+ * 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.reef.runtime.common.client.defaults;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.client.CompletedJob;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default event handler for CompletedJob: Logging it.
+ */
+@Provided
+@ClientSide
+public final class DefaultCompletedJobHandler implements EventHandler<CompletedJob> {
+
+  private static final Logger LOG = Logger.getLogger(DefaultCompletedJobHandler.class.getName());
+
+  @Inject
+  private DefaultCompletedJobHandler() {
+  }
+
+  @Override
+  public void onNext(final CompletedJob job) {
+    LOG.log(Level.INFO, "Job Completed: {0}", job);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultFailedJobHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultFailedJobHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultFailedJobHandler.java
new file mode 100644
index 0000000..076a316
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultFailedJobHandler.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.runtime.common.client.defaults;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.client.FailedJob;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+
+/**
+ * Default event handler for FailedJob: rethrow the exception.
+ */
+@Provided
+@ClientSide
+public final class DefaultFailedJobHandler implements EventHandler<FailedJob> {
+
+  @Inject
+  private DefaultFailedJobHandler() {
+  }
+
+  @Override
+  public void onNext(final FailedJob job) {
+    throw new RuntimeException("REEF job failed: " + job.getId(), job.getReason().orElse(null));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultJobMessageHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultJobMessageHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultJobMessageHandler.java
new file mode 100644
index 0000000..59a6115
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultJobMessageHandler.java
@@ -0,0 +1,48 @@
+/**
+ * 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.reef.runtime.common.client.defaults;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.client.JobMessage;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+
+/**
+ * Default event handler for job message: Logging it.
+ */
+@Provided
+@ClientSide
+public final class DefaultJobMessageHandler implements EventHandler<JobMessage> {
+
+  private static final Logger LOG = Logger.getLogger(DefaultJobMessageHandler.class.getName());
+
+  @Inject
+  private DefaultJobMessageHandler() {
+  }
+
+  @Override
+  public void onNext(final JobMessage message) {
+    LOG.log(Level.FINE, "Received message: {0}", message);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultRunningJobHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultRunningJobHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultRunningJobHandler.java
new file mode 100644
index 0000000..4b94c53
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultRunningJobHandler.java
@@ -0,0 +1,47 @@
+/**
+ * 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.reef.runtime.common.client.defaults;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.client.RunningJob;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default event handler for RunningJob: Logging it.
+ */
+@Provided
+@ClientSide
+public final class DefaultRunningJobHandler implements EventHandler<RunningJob> {
+
+  private static final Logger LOG = Logger.getLogger(DefaultRunningJobHandler.class.getName());
+
+  @Inject
+  private DefaultRunningJobHandler() {
+  }
+
+  @Override
+  public void onNext(final RunningJob job) {
+    LOG.log(Level.INFO, "Job is running: {0}", job);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultRuntimeErrorHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultRuntimeErrorHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultRuntimeErrorHandler.java
new file mode 100644
index 0000000..e72706b
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/DefaultRuntimeErrorHandler.java
@@ -0,0 +1,52 @@
+/**
+ * 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.reef.runtime.common.client.defaults;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.client.FailedRuntime;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default event handler for REEF FailedRuntime: rethrow the exception.
+ */
+@Provided
+@ClientSide
+public final class DefaultRuntimeErrorHandler implements EventHandler<FailedRuntime> {
+
+  private static final Logger LOG = Logger.getLogger(DefaultRuntimeErrorHandler.class.getName());
+
+  @Inject
+  private DefaultRuntimeErrorHandler() {
+  }
+
+  @Override
+  public void onNext(final FailedRuntime error) {
+    if (error.getReason().isPresent()) {
+      LOG.log(Level.SEVERE, "Runtime error: " + error, error.getReason().get());
+    } else {
+      LOG.log(Level.SEVERE, "Runtime error: " + error);
+    }
+    throw new RuntimeException("REEF runtime error: " + error, error.asError());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/package-info.java
new file mode 100644
index 0000000..6263ab1
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/defaults/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Default implementations for the optional client-side event handlers.
+ */
+package org.apache.reef.runtime.common.client.defaults;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/package-info.java
new file mode 100644
index 0000000..9af9dfe
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Implementation of the client-side REEF API.
+ */
+package org.apache.reef.runtime.common.client;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/parameters/ClientPresent.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/parameters/ClientPresent.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/parameters/ClientPresent.java
new file mode 100644
index 0000000..0d0e361
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/client/parameters/ClientPresent.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.runtime.common.client.parameters;
+
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * A Tang named parameter that indicates whether or not a client (handler for the various Job events) is present.
+ */
+@ClientSide
+@NamedParameter(doc = "Indicates whether or not a client is present", default_value = ClientPresent.NO)
+public final class ClientPresent implements Name<String> {
+  public static final String YES = "YES";
+  public static final String NO = "NO";
+}


[15/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/NameResolutionException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/NameResolutionException.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/NameResolutionException.java
new file mode 100644
index 0000000..e40ab94
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/NameResolutionException.java
@@ -0,0 +1,40 @@
+/**
+ * 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.reef.tang.exceptions;
+
+/**
+ * Thrown when Tang encounters an unknown (to the current classloader) class
+ * or configuration option.  NameResolutionExceptions can only be encountered
+ * if:
+ * <ol>
+ * <li> Tang is processing a configuration file from an external source </li>
+ * <li> Classes / NamedParameters are passed to Tang in String form </li>
+ * <li> Class objects are passed directly to Tang, but it is using a different
+ * classloader than the calling code.</li>
+ * <li> Tang is processing Configurations using a ClassHierarchy produced by
+ * another process </li>
+ * </ol>
+ */
+public class NameResolutionException extends BindException {
+  private static final long serialVersionUID = 1L;
+
+  public NameResolutionException(String name, String longestPrefix) {
+    super("Could not resolve " + name + ".  Search ended at prefix " + longestPrefix + " This can happen due to typos in class names that are passed as strings, or because Tang is configured to use a classloader other than the one that generated the class reference (check your classpath and the code that instantiated Tang)");
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/ParseException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/ParseException.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/ParseException.java
new file mode 100644
index 0000000..8c22e81
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/ParseException.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.tang.exceptions;
+
+/**
+ * Thrown when a string fails to parse as the requested type.
+ *
+ * @see ParameterParser for more information about string parsing.
+ */
+public class ParseException extends BindException {
+  private static final long serialVersionUID = 1L;
+
+  public ParseException(String msg, Throwable cause) {
+    super(msg, cause);
+  }
+
+  public ParseException(String msg) {
+    super(msg);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/package-info.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/package-info.java
new file mode 100644
index 0000000..0fca070
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/package-info.java
@@ -0,0 +1,28 @@
+/**
+ * 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.
+ */
+/**
+ * Exceptions thrown by Tang, including runtime exceptions that reflect
+ * compile-time inconsistencies and other problems that can't be
+ * meaningfully handled by application code.  The non-runtime exceptions
+ * in this package are thrown when an incorrect configuration file, or
+ * other post-compilation problems are detected.
+ *
+ */
+package org.apache.reef.tang.exceptions;
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/AvroConfigurationSerializer.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/AvroConfigurationSerializer.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/AvroConfigurationSerializer.java
new file mode 100644
index 0000000..98f455a
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/AvroConfigurationSerializer.java
@@ -0,0 +1,313 @@
+/**
+ * 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.reef.tang.formats;
+
+import org.apache.avro.file.DataFileReader;
+import org.apache.avro.file.DataFileWriter;
+import org.apache.avro.io.*;
+import org.apache.avro.specific.SpecificDatumReader;
+import org.apache.avro.specific.SpecificDatumWriter;
+import org.apache.commons.lang.StringUtils;
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.ConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.ClassHierarchyException;
+import org.apache.reef.tang.formats.avro.AvroConfiguration;
+import org.apache.reef.tang.formats.avro.ConfigurationEntry;
+import org.apache.reef.tang.implementation.ConfigurationBuilderImpl;
+import org.apache.reef.tang.types.ClassNode;
+import org.apache.reef.tang.types.NamedParameterNode;
+import org.apache.reef.tang.types.Node;
+import org.apache.reef.tang.util.ReflectionUtilities;
+
+import javax.inject.Inject;
+import java.io.*;
+import java.util.*;
+
+/**
+ * (De-)Serializing Configuration to and from AvroConfiguration.
+ * <p/>
+ * This class is stateless and is therefore safe to reuse.
+ */
+public final class AvroConfigurationSerializer implements ConfigurationSerializer {
+
+  /**
+   * The Charset used for the JSON encoding.
+   * <p/>
+   * Copied from <code>org.apache.avro.io.JsonDecoder.CHARSET</code>
+   */
+  private static final String JSON_CHARSET = "ISO-8859-1";
+
+  @Inject
+  public AvroConfigurationSerializer() {
+  }
+
+  private static void fromAvro(final AvroConfiguration avroConfiguration, final ConfigurationBuilder configurationBuilder) throws BindException {
+    // Note: This code is an adapted version of ConfigurationFile.processConfigFile();
+    // TODO: This method should implement list deserialization. Implement it when C# side is ready.
+    final Map<String, String> importedNames = new HashMap<>();
+
+    for (final ConfigurationEntry entry : avroConfiguration.getBindings()) {
+
+      final String longName = importedNames.get(entry.getKey().toString());
+      final String key;
+      if (null == longName) {
+        key = entry.getKey().toString();
+      } else {
+        key = longName;
+      }
+
+      // entry.getValue()'s type can be either string or array of string
+      final Object rawValue = entry.getValue();
+
+      try {
+        // TODO: Implement list deserialization
+        // rawValue is String.
+        String value = rawValue.toString();
+        if (key.equals(ConfigurationBuilderImpl.IMPORT)) {
+          configurationBuilder.getClassHierarchy().getNode(value);
+          final String[] tok = value.split(ReflectionUtilities.regexp);
+          final String lastTok = tok[tok.length - 1];
+          try {
+            configurationBuilder.getClassHierarchy().getNode(lastTok);
+            throw new IllegalArgumentException("Conflict on short name: " + lastTok);
+          } catch (final BindException e) {
+            final String oldValue = importedNames.put(lastTok, value);
+            if (oldValue != null) {
+              throw new IllegalArgumentException("Name conflict: "
+                  + lastTok + " maps to " + oldValue + " and " + value);
+            }
+          }
+        } else if (value.startsWith(ConfigurationBuilderImpl.INIT)) {
+          final String[] classes = value.substring(ConfigurationBuilderImpl.INIT.length(), value.length())
+              .replaceAll("^[\\s\\(]+", "")
+              .replaceAll("[\\s\\)]+$", "")
+              .split("[\\s\\-]+");
+          configurationBuilder.registerLegacyConstructor(key, classes);
+        } else {
+          configurationBuilder.bind(key, value);
+        }
+      } catch (final BindException | ClassHierarchyException e) {
+        throw new BindException("Failed to process configuration tuple: [" + key + "=" + rawValue + "]", e);
+      }
+    }
+  }
+
+  private static AvroConfiguration avroFromFile(final File file) throws IOException {
+    final AvroConfiguration avroConfiguration;
+    try (final DataFileReader<AvroConfiguration> dataFileReader =
+             new DataFileReader<>(file, new SpecificDatumReader<>(AvroConfiguration.class))) {
+      avroConfiguration = dataFileReader.next();
+    }
+    return avroConfiguration;
+  }
+
+  private static AvroConfiguration avroFromBytes(final byte[] theBytes) throws IOException {
+    final BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(theBytes, null);
+    final SpecificDatumReader<AvroConfiguration> reader = new SpecificDatumReader<>(AvroConfiguration.class);
+    return reader.read(null, decoder);
+  }
+
+  private static AvroConfiguration avroFromString(final String theString) throws IOException {
+    final JsonDecoder decoder = DecoderFactory.get().jsonDecoder(AvroConfiguration.getClassSchema(), theString);
+    final SpecificDatumReader<AvroConfiguration> reader = new SpecificDatumReader<>(AvroConfiguration.class);
+    return reader.read(null, decoder);
+  }
+
+  public AvroConfiguration toAvro(final Configuration configuration) {
+    // Note: This code is an adapted version of ConfiurationFile.toConfigurationStringList();
+    // TODO: This method should implement list serialization. Implement it when C# side is ready.
+
+    final List<ConfigurationEntry> configurationEntries = new ArrayList<>();
+
+    for (final ClassNode<?> opt : configuration.getBoundImplementations()) {
+      configurationEntries.add(new ConfigurationEntry().newBuilder()
+          .setKey(opt.getFullName())
+          .setValue(configuration.getBoundImplementation(opt).getFullName())
+          .build());
+    }
+
+    for (final ClassNode<?> opt : configuration.getBoundConstructors()) {
+      configurationEntries.add(new ConfigurationEntry().newBuilder()
+          .setKey(opt.getFullName())
+          .setValue(configuration.getBoundConstructor(opt).getFullName())
+          .build());
+    }
+    for (final NamedParameterNode<?> opt : configuration.getNamedParameters()) {
+      configurationEntries.add(new ConfigurationEntry().newBuilder()
+          .setKey(opt.getFullName())
+          .setValue(configuration.getNamedParameter(opt))
+          .build());
+    }
+    for (final ClassNode<?> cn : configuration.getLegacyConstructors()) {
+      final String legacyConstructors = StringUtils.join(configuration.getLegacyConstructor(cn).getArgs(), "-");
+      configurationEntries.add(new ConfigurationEntry().newBuilder()
+          .setKey(cn.getFullName())
+          .setValue("" + ConfigurationBuilderImpl.INIT + "(" + legacyConstructors + ")")
+          .build());
+    }
+    for (final Map.Entry<NamedParameterNode<Set<?>>, Object> e : configuration.getBoundSets()) {
+      final String val;
+      if (e.getValue() instanceof String) {
+        val = (String) e.getValue();
+      } else if (e.getValue() instanceof Node) {
+        val = ((Node) e.getValue()).getFullName();
+      } else {
+        throw new IllegalStateException();
+      }
+      configurationEntries.add(new ConfigurationEntry().newBuilder()
+          .setKey(e.getKey().getFullName())
+          .setValue(val)
+          .build());
+    }
+    // TODO: Implement list serialization
+
+    return AvroConfiguration.newBuilder().setBindings(configurationEntries).build();
+  }
+
+  @Override
+  public void toFile(final Configuration conf, final File file) throws IOException {
+    final AvroConfiguration avroConfiguration = toAvro(conf);
+    final DatumWriter<AvroConfiguration> configurationWriter = new SpecificDatumWriter<>(AvroConfiguration.class);
+    try (DataFileWriter<AvroConfiguration> dataFileWriter = new DataFileWriter<>(configurationWriter)) {
+      dataFileWriter.create(avroConfiguration.getSchema(), file);
+      dataFileWriter.append(avroConfiguration);
+    }
+  }
+
+  @Override
+  public void toTextFile(final Configuration conf, final File file) throws IOException {
+    try (final Writer w = new FileWriter(file)) {
+      w.write(this.toString(conf));
+    }
+  }
+
+  @Override
+  public byte[] toByteArray(final Configuration conf) throws IOException {
+    final DatumWriter<AvroConfiguration> configurationWriter = new SpecificDatumWriter<>(AvroConfiguration.class);
+    final byte[] theBytes;
+    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+      final BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(out, null);
+      configurationWriter.write(toAvro(conf), encoder);
+      encoder.flush();
+      out.flush();
+      theBytes = out.toByteArray();
+    }
+    return theBytes;
+  }
+
+  @Override
+  public String toString(final Configuration configuration) {
+    final DatumWriter<AvroConfiguration> configurationWriter = new SpecificDatumWriter<>(AvroConfiguration.class);
+    final String result;
+    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+      final JsonEncoder encoder = EncoderFactory.get().jsonEncoder(AvroConfiguration.SCHEMA$, out);
+      configurationWriter.write(toAvro(configuration), encoder);
+      encoder.flush();
+      out.flush();
+      result = out.toString(JSON_CHARSET);
+    } catch (final IOException e) {
+      throw new RuntimeException(e);
+    }
+    return result;
+  }
+
+  /**
+   * Converts a given AvroConfiguration to Configuration
+   *
+   * @param avroConfiguration
+   * @return a Configuration version of the given AvroConfiguration
+   */
+  public Configuration fromAvro(final AvroConfiguration avroConfiguration) throws BindException {
+    final ConfigurationBuilder configurationBuilder = Tang.Factory.getTang().newConfigurationBuilder();
+    fromAvro(avroConfiguration, configurationBuilder);
+    return configurationBuilder.build();
+  }
+
+  /**
+   * Converts a given AvroConfiguration to Configuration
+   *
+   * @param avroConfiguration
+   * @param classHierarchy    the class hierarchy used for validation.
+   * @return a Configuration version of the given AvroConfiguration
+   */
+  public Configuration fromAvro(final AvroConfiguration avroConfiguration, final ClassHierarchy classHierarchy)
+      throws BindException {
+    final ConfigurationBuilder configurationBuilder = Tang.Factory.getTang().newConfigurationBuilder(classHierarchy);
+    fromAvro(avroConfiguration, configurationBuilder);
+    return configurationBuilder.build();
+  }
+
+  @Override
+  public Configuration fromFile(final File file) throws IOException, BindException {
+    return fromAvro(avroFromFile(file));
+  }
+
+  @Override
+  public Configuration fromFile(final File file, final ClassHierarchy classHierarchy) throws IOException, BindException {
+    return fromAvro(avroFromFile(file), classHierarchy);
+  }
+
+  @Override
+  public Configuration fromTextFile(final File file) throws IOException, BindException {
+    final StringBuilder result = readFromTextFile(file);
+    return this.fromString(result.toString());
+  }
+
+  @Override
+  public Configuration fromTextFile(final File file, final ClassHierarchy classHierarchy) throws IOException, BindException {
+    final StringBuilder result = readFromTextFile(file);
+    return this.fromString(result.toString(), classHierarchy);
+  }
+
+  private StringBuilder readFromTextFile(final File file) throws IOException {
+    final StringBuilder result = new StringBuilder();
+    try (final BufferedReader reader = new BufferedReader(new FileReader(file))) {
+      String line = reader.readLine();
+      while (line != null) {
+        result.append(line);
+        line = reader.readLine();
+      }
+    }
+    return result;
+  }
+
+  @Override
+  public Configuration fromByteArray(final byte[] theBytes) throws IOException, BindException {
+    return fromAvro(avroFromBytes(theBytes));
+  }
+
+  @Override
+  public Configuration fromByteArray(final byte[] theBytes, final ClassHierarchy classHierarchy) throws IOException, BindException {
+    return fromAvro(avroFromBytes(theBytes), classHierarchy);
+  }
+
+  @Override
+  public Configuration fromString(final String theString) throws IOException, BindException {
+    return fromAvro(avroFromString(theString));
+  }
+
+  @Override
+  public Configuration fromString(final String theString, final ClassHierarchy classHierarchy) throws IOException, BindException {
+    return fromAvro(avroFromString(theString), classHierarchy);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/CommandLine.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/CommandLine.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/CommandLine.java
new file mode 100644
index 0000000..a299958
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/CommandLine.java
@@ -0,0 +1,218 @@
+/**
+ * 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.reef.tang.formats;
+
+import org.apache.commons.cli.*;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.ConfigurationBuilder;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.NameResolutionException;
+import org.apache.reef.tang.types.NamedParameterNode;
+import org.apache.reef.tang.types.Node;
+import org.apache.reef.tang.util.MonotonicTreeMap;
+import org.apache.reef.tang.util.ReflectionUtilities;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+public final class CommandLine {
+
+  final Map<Option, CommandLineCallback> applicationOptions = new HashMap<>();
+  private final ConfigurationBuilder conf;
+  private final Map<String, String> shortNames = new MonotonicTreeMap<>();
+
+  public CommandLine() {
+    this.conf = Tang.Factory.getTang().newConfigurationBuilder();
+  }
+
+  public CommandLine(final ConfigurationBuilder conf) {
+    this.conf = conf;
+  }
+
+  public ConfigurationBuilder getBuilder() {
+    return this.conf;
+  }
+
+  public CommandLine registerShortNameOfClass(final String s) throws BindException {
+
+    final Node n;
+    try {
+      n = conf.getClassHierarchy().getNode(s);
+    } catch (final NameResolutionException e) {
+      throw new BindException("Problem loading class " + s, e);
+    }
+
+    if (n instanceof NamedParameterNode) {
+      final NamedParameterNode<?> np = (NamedParameterNode<?>) n;
+      final String shortName = np.getShortName();
+      final String longName = np.getFullName();
+      if (shortName == null) {
+        throw new BindException(
+            "Can't register non-existent short name of named parameter: " + longName);
+      }
+      shortNames.put(shortName, longName);
+    } else {
+      throw new BindException("Can't register short name for non-NamedParameterNode: " + n);
+    }
+
+    return this;
+  }
+
+  public CommandLine registerShortNameOfClass(
+      final Class<? extends Name<?>> c) throws BindException {
+    return registerShortNameOfClass(ReflectionUtilities.getFullName(c));
+  }
+
+  @SuppressWarnings("static-access")
+  private Options getCommandLineOptions() {
+
+    final Options opts = new Options();
+    for (final String shortName : shortNames.keySet()) {
+      final String longName = shortNames.get(shortName);
+      try {
+        opts.addOption(OptionBuilder
+            .withArgName(conf.classPrettyDefaultString(longName)).hasArg()
+            .withDescription(conf.classPrettyDescriptionString(longName))
+            .create(shortName));
+      } catch (final BindException e) {
+        throw new IllegalStateException(
+            "Could not process " + shortName + " which is the short name of " + longName, e);
+      }
+    }
+
+    for (final Option o : applicationOptions.keySet()) {
+      opts.addOption(o);
+    }
+
+    return opts;
+  }
+
+  public CommandLine addCommandLineOption(final Option option, final CommandLineCallback cb) {
+    // TODO: Check for conflicting options.
+    applicationOptions.put(option, cb);
+    return this;
+  }
+
+  /**
+   * @param args
+   * @return Selfie if the command line parsing succeeded, null (or exception) otherwise.
+   * @throws IOException
+   * @throws NumberFormatException
+   * @throws ParseException
+   */
+  @SafeVarargs
+  final public <T> CommandLine processCommandLine(
+      final String[] args, Class<? extends Name<?>>... argClasses)
+      throws IOException, BindException {
+
+    for (final Class<? extends Name<?>> c : argClasses) {
+      registerShortNameOfClass(c);
+    }
+
+    final Options o = getCommandLineOptions();
+    o.addOption(new Option("?", "help"));
+    final Parser g = new GnuParser();
+
+    final org.apache.commons.cli.CommandLine cl;
+    try {
+      cl = g.parse(o, args);
+    } catch (final ParseException e) {
+      throw new IOException("Could not parse config file", e);
+    }
+
+    if (cl.hasOption("?")) {
+      new HelpFormatter().printHelp("reef", o);
+      return null;
+    }
+
+    for (final Option option : cl.getOptions()) {
+
+      final String shortName = option.getOpt();
+      final String value = option.getValue();
+
+      if (applicationOptions.containsKey(option)) {
+        applicationOptions.get(option).process(option);
+      } else {
+        try {
+          conf.bind(shortNames.get(shortName), value);
+        } catch (final BindException e) {
+          throw new BindException("Could not bind shortName " + shortName + " to value " + value, e);
+        }
+      }
+    }
+
+    return this;
+  }
+
+  /**
+   * Utility method to quickly parse a command line to a Configuration.
+   * <p/>
+   * This is equivalent to
+   * <code>parseToConfigurationBuilder(args, argClasses).build()</code>
+   *
+   * @param args       the command line parameters to parse.
+   * @param argClasses the named parameters to look for.
+   * @return a Configuration with the parsed parameters
+   * @throws ParseException if the parsing  of the commandline fails.
+   */
+  public static Configuration parseToConfiguration(final String[] args,
+                                                   final Class<? extends Name<?>>... argClasses)
+      throws ParseException {
+    return parseToConfigurationBuilder(args, argClasses).build();
+  }
+
+  /**
+   * Utility method to quickly parse a command line to a ConfigurationBuilder.
+   * <p/>
+   * This is equivalent to
+   * <code>new CommandLine().processCommandLine(args, argClasses).getBuilder()</code>, but with additional checks.
+   *
+   * @param args       the command line parameters to parse.
+   * @param argClasses the named parameters to look for.
+   * @return a ConfigurationBuilder with the parsed parameters
+   * @throws ParseException if the parsing  of the commandline fails.
+   */
+  public static ConfigurationBuilder parseToConfigurationBuilder(final String[] args,
+                                                                 final Class<? extends Name<?>>... argClasses)
+      throws ParseException {
+    final CommandLine commandLine;
+    try {
+      commandLine = new CommandLine().processCommandLine(args, argClasses);
+    } catch (final IOException e) {
+      // processCommandLine() converts ParseException into IOException. This reverts that to make exception handling
+      // more straight forward.
+      throw new ParseException(e.getMessage());
+    }
+
+    // processCommandLine() indicates that it might return null. We need to guard users of this one from that
+    if (commandLine == null) {
+      throw new ParseException("Unable to parse the command line and the parser returned null.");
+    } else {
+      return commandLine.getBuilder();
+    }
+  }
+
+  public interface CommandLineCallback {
+    public void process(final Option option);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ConfigurationFile.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ConfigurationFile.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ConfigurationFile.java
new file mode 100644
index 0000000..91568d1
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ConfigurationFile.java
@@ -0,0 +1,253 @@
+/**
+ * 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.reef.tang.formats;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.ConfigurationBuilder;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.ClassHierarchyException;
+import org.apache.reef.tang.implementation.ConfigurationBuilderImpl;
+import org.apache.reef.tang.implementation.ConfigurationImpl;
+import org.apache.reef.tang.types.ClassNode;
+import org.apache.reef.tang.types.ConstructorArg;
+import org.apache.reef.tang.types.NamedParameterNode;
+import org.apache.reef.tang.types.Node;
+import org.apache.reef.tang.util.ReflectionUtilities;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.*;
+import java.util.Map.Entry;
+
+/**
+ * @deprecated in Tang 0.2 Use AvroConfigurationSerializer instead.
+ */
+@Deprecated
+public class ConfigurationFile {
+
+  /**
+   * Write Configuration to the given File.
+   *
+   * @throws IOException
+   * @deprecated in Tang 0.2 Use AvroConfigurationSerializer instead.
+   */
+  @Deprecated
+  public static void writeConfigurationFile(
+      final Configuration conf, final File confFile) throws IOException {
+    try (final PrintStream printStream = new PrintStream(new FileOutputStream(confFile))) {
+      printStream.print(toConfigurationString(conf));
+    }
+  }
+
+  /**
+   * @deprecated in Tang 0.2 Use AvroConfigurationSerializer instead.
+   */
+  @Deprecated
+  public static void addConfiguration(final ConfigurationBuilder conf,
+                                      final File tmpConfFile) throws IOException, BindException {
+    final PropertiesConfiguration confFile;
+    try {
+      confFile = new PropertiesConfiguration(tmpConfFile);
+    } catch (final ConfigurationException e) {
+      throw new BindException("Problem parsing config file: " + tmpConfFile, e);
+    }
+    processConfigFile(conf, confFile);
+  }
+
+  /**
+   * @param conf     This configuration builder will be modified to incorporate the
+   *                 contents of the configuration file.
+   * @param contents A string containing the contents of the configuration file.
+   * @throws BindException
+   * @deprecated in Tang 0.2 Use AvroConfigurationSerializer instead.
+   */
+  @Deprecated
+  public static void addConfiguration(final ConfigurationBuilder conf,
+                                      final String contents) throws BindException {
+    File tmpConfFile = null;
+    try {
+      tmpConfFile = File.createTempFile("tang", "tmp");
+      try (final FileOutputStream outStream = new FileOutputStream(tmpConfFile)) {
+        outStream.write(contents.getBytes());
+      }
+      addConfiguration(conf, tmpConfFile);
+    } catch (final IOException ex) {
+      throw new BindException("Error writing config file: " + tmpConfFile, ex);
+    } finally {
+      if (tmpConfFile != null) {
+        tmpConfFile.delete();
+      }
+    }
+  }
+
+  private static void processConfigFile(ConfigurationBuilder conf,
+                                        PropertiesConfiguration confFile) throws IOException, BindException {
+    ConfigurationBuilderImpl ci = (ConfigurationBuilderImpl) conf;
+    Iterator<String> it = confFile.getKeys();
+    Map<String, String> importedNames = new HashMap<>();
+
+    while (it.hasNext()) {
+      String key = it.next();
+      String longName = importedNames.get(key);
+      String[] values = confFile.getStringArray(key);
+      if (longName != null) {
+        // System.err.println("Mapped " + key + " to " + longName);
+        key = longName;
+      }
+      for (String value : values) {
+        try {
+          if (key.equals(ConfigurationBuilderImpl.IMPORT)) {
+            ci.getClassHierarchy().getNode(value);
+            final String[] tok = value.split(ReflectionUtilities.regexp);
+            final String lastTok = tok[tok.length - 1];
+            try {
+              // ci.namespace.getNode(lastTok);
+              ci.getClassHierarchy().getNode(lastTok);
+              throw new IllegalArgumentException("Conflict on short name: " + lastTok);
+            } catch (BindException e) {
+              String oldValue = importedNames.put(lastTok, value);
+              if (oldValue != null) {
+                throw new IllegalArgumentException("Name conflict: "
+                    + lastTok + " maps to " + oldValue + " and " + value);
+              }
+            }
+          } else if (value.startsWith(ConfigurationBuilderImpl.INIT)) {
+            String parseValue = value.substring(
+                ConfigurationBuilderImpl.INIT.length(), value.length());
+            parseValue = parseValue.replaceAll("^[\\s\\(]+", "");
+            parseValue = parseValue.replaceAll("[\\s\\)]+$", "");
+            String[] classes = parseValue.split("[\\s\\-]+");
+            ci.registerLegacyConstructor(key, classes);
+          } else {
+            ci.bind(key, value);
+          }
+        } catch (BindException e) {
+          throw new BindException("Failed to process configuration tuple: [" + key + "=" + value + "]", e);
+        } catch (ClassHierarchyException e) {
+          throw new ClassHierarchyException("Failed to process configuration tuple: [" + key + "=" + value + "]", e);
+        }
+      }
+    }
+  }
+
+  /**
+   * Replace any \'s in the input string with \\. and any "'s with \".
+   *
+   * @param in
+   * @return
+   */
+  private static String escape(String in) {
+    // After regexp escaping \\\\ = 1 slash, \\\\\\\\ = 2 slashes.
+
+    // Also, the second args of replaceAll are neither strings nor regexps, and
+    // are instead a special DSL used by Matcher. Therefore, we need to double
+    // escape slashes (4 slashes) and quotes (3 slashes + ") in those strings.
+    // Since we need to write \\ and \", we end up with 8 and 7 slashes,
+    // respectively.
+    return in.replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "\\\\\\\"");
+  }
+
+  /**
+   * Obtain the effective configuration of this ConfigurationBuilderImpl
+   * instance. This consists of string-string pairs that could be written
+   * directly to a Properties file, for example. Currently, this method does not
+   * return information about default parameter values that were specified by
+   * parameter annotations, or about the auto-discovered stuff in TypeHierarchy.
+   * All of that should be automatically imported as these keys are parsed on
+   * the other end.
+   *
+   * @return A string containing enough information to rebuild this
+   * configuration object (assuming the same classes / jars are
+   * available when the string is parsed by Tang).
+   * @deprecated in Tang 0.2 Use AvroConfigurationSerializer instead.
+   */
+  @Deprecated
+  public static String toConfigurationString(final Configuration c) {
+    StringBuilder sb = new StringBuilder();
+    for (String s : toConfigurationStringList(c)) {
+      sb.append(s);
+      sb.append('\n');
+    }
+    return sb.toString();
+  }
+
+  /**
+   * @deprecated in Tang 0.2 Use AvroConfigurationSerializer instead.
+   */
+  @Deprecated
+  static List<String> toConfigurationStringList(final Configuration c) {
+    ConfigurationImpl conf = (ConfigurationImpl) c;
+    List<String> l = new ArrayList<>();
+    for (ClassNode<?> opt : conf.getBoundImplementations()) {
+      l.add(opt.getFullName()
+          + '='
+          + escape(conf.getBoundImplementation(opt).getFullName()));
+    }
+    for (ClassNode<?> opt : conf.getBoundConstructors()) {
+      l.add(opt.getFullName()
+          + '='
+          + escape(conf.getBoundConstructor(opt).getFullName()));
+    }
+    for (NamedParameterNode<?> opt : conf.getNamedParameters()) {
+      l.add(opt.getFullName()
+          + '='
+          + escape(conf.getNamedParameter(opt)));
+    }
+    for (ClassNode<?> cn : conf.getLegacyConstructors()) {
+      StringBuilder sb = new StringBuilder();
+      join(sb, "-", conf.getLegacyConstructor(cn).getArgs());
+      l.add(cn.getFullName()
+          + escape('='
+              + ConfigurationBuilderImpl.INIT
+              + '('
+              + sb.toString()
+              + ')'
+      ));
+      //s.append(cn.getFullName()).append('=').append(ConfigurationBuilderImpl.INIT).append('(');
+//      .append(")\n");
+    }
+    for (Entry<NamedParameterNode<Set<?>>, Object> e : conf.getBoundSets()) {
+      final String val;
+      if (e.getValue() instanceof String) {
+        val = (String) e.getValue();
+      } else if (e.getValue() instanceof Node) {
+        val = ((Node) e.getValue()).getFullName();
+      } else {
+        throw new IllegalStateException();
+      }
+      l.add(e.getKey().getFullName() + '=' + escape(val));
+//      s.append(e.getKey().getFullName()).append('=').append(val).append("\n");
+    }
+    return l;//s.toString();
+  }
+
+  private static StringBuilder join(final StringBuilder sb, final String sep, final ConstructorArg[] types) {
+    if (types.length > 0) {
+      sb.append(types[0].getType());
+      for (int i = 1; i < types.length; i++) {
+        sb.append(sep).append(types[i].getType());
+      }
+    }
+    return sb;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ConfigurationModule.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ConfigurationModule.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ConfigurationModule.java
new file mode 100644
index 0000000..5b749ce
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ConfigurationModule.java
@@ -0,0 +1,299 @@
+/**
+ * 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.reef.tang.formats;
+
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.ClassHierarchyException;
+import org.apache.reef.tang.exceptions.NameResolutionException;
+import org.apache.reef.tang.types.NamedParameterNode;
+import org.apache.reef.tang.util.*;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+/**
+ * Allows applications to bundle sets of configuration options together into
+ * discrete packages.  Unlike more conventional approaches,
+ * ConfigurationModules store such information in static data structures that
+ * can be statically discovered and sanity-checked.
+ *
+ * @see org.apache.reef.tang.formats.TestConfigurationModule for more information and examples.
+ */
+public class ConfigurationModule {
+  final ConfigurationModuleBuilder builder;
+  // Set of required unset parameters. Must be empty before build.
+  private final Set<Field> reqSet = new MonotonicHashSet<>();
+  private final Map<Impl<?>, Class<?>> setImpls = new MonotonicHashMap<>();
+  private final MonotonicMultiHashMap<Impl<?>, Class<?>> setImplSets = new MonotonicMultiHashMap<>();
+  private final MonotonicMultiHashMap<Impl<?>, String> setLateImplSets = new MonotonicMultiHashMap<>();
+  private final MonotonicMultiHashMap<Param<?>, String> setParamSets = new MonotonicMultiHashMap<>();
+  private final Map<Impl<?>, String> setLateImpls = new MonotonicHashMap<>();
+  private final Map<Param<?>, String> setParams = new MonotonicHashMap<>();
+  private final Map<Impl<List>, List<?>> setImplLists = new MonotonicHashMap<>();
+  private final Map<Param<List>, List<?>> setParamLists = new MonotonicHashMap<>();
+
+  protected ConfigurationModule(ConfigurationModuleBuilder builder) {
+    this.builder = builder.deepCopy();
+  }
+
+  private ConfigurationModule deepCopy() {
+    ConfigurationModule cm = new ConfigurationModule(builder.deepCopy());
+    cm.setImpls.putAll(setImpls);
+    cm.setImplSets.addAll(setImplSets);
+    cm.setLateImplSets.addAll(setLateImplSets);
+    cm.setParamSets.addAll(setParamSets);
+    cm.setLateImpls.putAll(setLateImpls);
+    cm.setParams.putAll(setParams);
+    cm.reqSet.addAll(reqSet);
+    cm.setImplLists.putAll(setImplLists);
+    cm.setParamLists.putAll(setParamLists);
+    return cm;
+  }
+
+  private final <T> void processSet(Object impl) {
+    Field f = builder.map.get(impl);
+    if (f == null) { /* throw */
+      throw new ClassHierarchyException("Unknown Impl/Param when setting " + ReflectionUtilities.getSimpleName(impl.getClass()) + ".  Did you pass in a field from some other module?");
+    }
+    if (!reqSet.contains(f)) {
+      reqSet.add(f);
+    }
+  }
+
+  public final <T> ConfigurationModule set(Impl<T> opt, Class<? extends T> impl) {
+    ConfigurationModule c = deepCopy();
+    c.processSet(opt);
+    if (c.builder.setOpts.contains(opt)) {
+      c.setImplSets.put(opt, impl);
+    } else {
+      c.setImpls.put(opt, impl);
+    }
+    return c;
+  }
+
+  public final <T> ConfigurationModule set(Impl<T> opt, String impl) {
+    ConfigurationModule c = deepCopy();
+    c.processSet(opt);
+    if (c.builder.setOpts.contains(opt)) {
+      c.setLateImplSets.put(opt, impl);
+    } else {
+      c.setLateImpls.put(opt, impl);
+    }
+    return c;
+  }
+
+  /**
+   * Binds a list to a specific optional/required Impl using ConfigurationModule.
+   *
+   * @param opt      Target optional/required Impl
+   * @param implList List object to be injected
+   * @param <T>
+   * @return
+   */
+  public final <T> ConfigurationModule set(Impl<List> opt, List implList) {
+    ConfigurationModule c = deepCopy();
+    c.processSet(opt);
+    c.setImplLists.put(opt, implList);
+    return c;
+  }
+
+  public final <T> ConfigurationModule set(Param<T> opt, Class<? extends T> val) {
+    return set(opt, ReflectionUtilities.getFullName(val));
+  }
+
+  public final ConfigurationModule set(Param<Boolean> opt, boolean val) {
+    return set(opt, "" + val);
+  }
+
+  public final ConfigurationModule set(Param<? extends Number> opt, Number val) {
+    return set(opt, "" + val);
+  }
+
+  public final <T> ConfigurationModule set(Param<T> opt, String val) {
+    ConfigurationModule c = deepCopy();
+    c.processSet(opt);
+    if (c.builder.setOpts.contains(opt)) {
+      c.setParamSets.put(opt, val);
+    } else {
+      c.setParams.put(opt, val);
+    }
+    return c;
+  }
+
+  /**
+   * Binds a list to a specfici optional/required Param using ConfigurationModule.
+   *
+   * @param opt      target optional/required Param
+   * @param implList List object to be injected
+   * @param <T>
+   * @return
+   */
+  public final <T> ConfigurationModule set(Param<List> opt, List implList) {
+    ConfigurationModule c = deepCopy();
+    c.processSet(opt);
+    c.setParamLists.put(opt, implList);
+    return c;
+  }
+
+  @SuppressWarnings({"unchecked", "rawtypes"})
+  public Configuration build() throws BindException {
+    ConfigurationModule c = deepCopy();
+
+    if (!c.reqSet.containsAll(c.builder.reqDecl)) {
+      Set<Field> missingSet = new MonotonicHashSet<>();
+      for (Field f : c.builder.reqDecl) {
+        if (!c.reqSet.contains(f)) {
+          missingSet.add(f);
+        }
+      }
+      throw new BindException(
+          "Attempt to build configuration before setting required option(s): "
+              + builder.toString(missingSet));
+    }
+
+    for (Class<?> clazz : c.builder.freeImpls.keySet()) {
+      Impl<?> i = c.builder.freeImpls.get(clazz);
+      if (c.setImpls.containsKey(i)) {
+        c.builder.b.bind(clazz, c.setImpls.get(i));
+      } else if (c.setLateImpls.containsKey(i)) {
+        c.builder.b.bind(ReflectionUtilities.getFullName(clazz), c.setLateImpls.get(i));
+      } else if (c.setImplSets.containsKey(i) || c.setLateImplSets.containsKey(i)) {
+        for (Class<?> clz : c.setImplSets.getValuesForKey(i)) {
+          c.builder.b.bindSetEntry((Class) clazz, (Class) clz);
+        }
+        for (String s : c.setLateImplSets.getValuesForKey(i)) {
+          c.builder.b.bindSetEntry((Class) clazz, s);
+        }
+      } else if (c.setImplLists.containsKey(i)) {
+        c.builder.b.bindList((Class) clazz, c.setImplLists.get(i));
+      }
+    }
+    for (Class<? extends Name<?>> clazz : c.builder.freeParams.keySet()) {
+      Param<?> p = c.builder.freeParams.get(clazz);
+      String s = c.setParams.get(p);
+      boolean foundOne = false;
+      if (s != null) {
+        c.builder.b.bindNamedParameter(clazz, s);
+        foundOne = true;
+      }
+      // Find the bound list for the NamedParameter
+      List list = c.setParamLists.get(p);
+      if (list != null) {
+        c.builder.b.bindList((Class) clazz, list);
+        foundOne = true;
+      }
+      for (String paramStr : c.setParamSets.getValuesForKey(p)) {
+        c.builder.b.bindSetEntry((Class) clazz, paramStr);
+        foundOne = true;
+      }
+      if (!foundOne) {
+        if (!(p instanceof OptionalParameter)) {
+          throw new IllegalStateException();
+        }
+      }
+    }
+    return c.builder.b.build();
+
+  }
+
+  public Set<NamedParameterNode<?>> getBoundNamedParameters() {
+    Configuration c = this.builder.b.build();
+    Set<NamedParameterNode<?>> nps = new MonotonicSet<>();
+    nps.addAll(c.getNamedParameters());
+    for (Class<?> np : this.builder.freeParams.keySet()) {
+      try {
+        nps.add((NamedParameterNode<?>) builder.b.getClassHierarchy().getNode(ReflectionUtilities.getFullName(np)));
+      } catch (NameResolutionException e) {
+        throw new IllegalStateException(e);
+      }
+    }
+    return nps;
+  }
+
+  public List<Entry<String, String>> toStringPairs() {
+    List<Entry<String, String>> ret = new ArrayList<>();
+    class MyEntry implements Entry<String, String> {
+      final String k;
+      final String v;
+
+      public MyEntry(String k, String v) {
+        this.k = k;
+        this.v = v;
+      }
+
+      @Override
+      public String getKey() {
+        return k;
+      }
+
+      @Override
+      public String getValue() {
+        return v;
+      }
+
+      @Override
+      public String setValue(String value) {
+        throw new UnsupportedOperationException();
+      }
+
+    }
+    for (Class<?> c : this.builder.freeParams.keySet()) {
+      ret.add(new MyEntry(ReflectionUtilities.getFullName(c), this.builder.map.get(this.builder.freeParams.get(c)).getName()));
+    }
+    for (Class<?> c : this.builder.freeImpls.keySet()) {
+      ret.add(new MyEntry(ReflectionUtilities.getFullName(c), this.builder.map.get(this.builder.freeImpls.get(c)).getName()));
+    }
+    for (String s : ConfigurationFile.toConfigurationStringList(builder.b.build())) {
+      String[] tok = s.split("=", 2);
+      ret.add(new MyEntry(tok[0], tok[1]));
+    }
+
+    return ret;
+  }
+
+  public String toPrettyString() {
+    StringBuilder sb = new StringBuilder();
+
+    for (Entry<String, String> l : toStringPairs()) {
+      sb.append(l.getKey() + "=" + l.getValue() + "\n");
+    }
+    return sb.toString();
+  }
+
+  public void assertStaticClean() throws ClassHierarchyException {
+    if (!(
+        setImpls.isEmpty() &&
+            setImplSets.isEmpty() &&
+            setLateImplSets.isEmpty() &&
+            setParamSets.isEmpty() &&
+            setLateImpls.isEmpty() &&
+            setParams.isEmpty() &&
+            setImplLists.isEmpty() &&
+            setParamLists.isEmpty()
+    )) {
+      throw new ClassHierarchyException("Detected statically set ConfigurationModule Parameter / Implementation.  set() should only be used dynamically.  Use bind...() instead.");
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ConfigurationModuleBuilder.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ConfigurationModuleBuilder.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ConfigurationModuleBuilder.java
new file mode 100644
index 0000000..38359c0
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ConfigurationModuleBuilder.java
@@ -0,0 +1,385 @@
+/**
+ * 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.reef.tang.formats;
+
+import org.apache.reef.tang.ExternalConstructor;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.ClassHierarchyException;
+import org.apache.reef.tang.exceptions.NameResolutionException;
+import org.apache.reef.tang.util.MonotonicHashMap;
+import org.apache.reef.tang.util.MonotonicHashSet;
+import org.apache.reef.tang.util.ReflectionUtilities;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public abstract class ConfigurationModuleBuilder {
+
+  private final static Set<Class<?>> paramBlacklist = new MonotonicHashSet<Class<?>>(
+      Param.class, Impl.class);
+  private final static Set<Class<?>> paramTypes = new MonotonicHashSet<Class<?>>(
+      RequiredImpl.class, OptionalImpl.class, RequiredParameter.class,
+      OptionalParameter.class);
+  final JavaConfigurationBuilder b = Tang.Factory.getTang()
+      .newConfigurationBuilder();
+  // Sets of things that have been declared
+  final Set<Field> reqDecl = new MonotonicHashSet<>();
+  final Set<Object> setOpts = new MonotonicHashSet<>();
+  // Maps from field instance variables to the fields that they
+  // are assigned to. These better be unique!
+  final Map<Object, Field> map = new MonotonicHashMap<>();
+  final Map<Class<?>, Impl<?>> freeImpls = new MonotonicHashMap<>();
+  final Map<Class<? extends Name<?>>, Param<?>> freeParams = new MonotonicHashMap<>();
+  private final Set<Field> optDecl = new MonotonicHashSet<>();
+  // Set of things that have been used in a bind. These must be equal
+  // to the decl counterparts before build() is called.
+  private final Set<Field> reqUsed = new MonotonicHashSet<>();
+  private final Set<Field> optUsed = new MonotonicHashSet<>();
+  private final Map<Class<?>, String> lateBindClazz = new MonotonicHashMap<>();
+
+  protected ConfigurationModuleBuilder() {
+    for (Field f : getClass().getDeclaredFields()) {
+      Class<?> t = f.getType();
+      if (paramBlacklist.contains(t)) {
+        throw new ClassHierarchyException(
+            "Found a field of type " + t + " which should be a Required/Optional Parameter/Implementation instead"
+        );
+      }
+      if (paramTypes.contains(t)) {
+        if (!Modifier.isPublic(f.getModifiers())) {
+          throw new ClassHierarchyException(
+              "Found a non-public configuration option in " + getClass() + ": "
+                  + f);
+        }
+        if (!Modifier.isStatic(f.getModifiers())) {
+          throw new ClassHierarchyException(
+              "Found a non-static configuration option in " + getClass() + ": "
+                  + f);
+        }
+        if (!Modifier.isFinal(f.getModifiers())) {
+          throw new ClassHierarchyException(
+              "Found a non-final configuration option in " + getClass() + ": "
+                  + f);
+        }
+        final Object o;
+        try {
+          o = f.get(null);
+        } catch (IllegalArgumentException | IllegalAccessException e) {
+          throw new ClassHierarchyException(
+              "Could not look up field instance in " + getClass() + " field: "
+                  + f, e);
+        }
+        if (map.containsKey(o)) {
+          throw new ClassHierarchyException(
+              "Detected aliased instances in class " + getClass()
+                  + " for fields " + map.get(o) + " and " + f);
+        }
+        if (t == RequiredImpl.class || t == RequiredParameter.class) {
+          reqDecl.add(f);
+        } else {
+          optDecl.add(f);
+        }
+        map.put(o, f);
+      }
+    }
+  }
+
+  private ConfigurationModuleBuilder(ConfigurationModuleBuilder c) {
+    try {
+      b.addConfiguration(c.b.build());
+    } catch (BindException e) {
+      throw new ClassHierarchyException(e);
+    }
+    reqDecl.addAll(c.reqDecl);
+    optDecl.addAll(c.optDecl);
+    reqUsed.addAll(c.reqUsed);
+    optUsed.addAll(c.optUsed);
+    setOpts.addAll(c.setOpts);
+    map.putAll(c.map);
+    freeImpls.putAll(c.freeImpls);
+    freeParams.putAll(c.freeParams);
+    lateBindClazz.putAll(c.lateBindClazz);
+
+  }
+
+  /**
+   * TODO: It would be nice if this incorporated d by reference so that static analysis / documentation tools
+   * could document the dependency between c and d.
+   */
+  public final ConfigurationModuleBuilder merge(ConfigurationModule d) {
+    if (d == null) {
+      throw new NullPointerException("If merge() was passed a static final field that is initialized to non-null, then this is almost certainly caused by a circular class dependency.");
+    }
+    try {
+      d.assertStaticClean();
+    } catch (ClassHierarchyException e) {
+      throw new ClassHierarchyException(ReflectionUtilities.getFullName(getClass()) + ": detected attempt to merge with ConfigurationModule that has had set() called on it", e);
+    }
+    ConfigurationModuleBuilder c = deepCopy();
+    try {
+      c.b.addConfiguration(d.builder.b.build());
+    } catch (BindException e) {
+      throw new ClassHierarchyException(e);
+    }
+    c.reqDecl.addAll(d.builder.reqDecl);
+    c.optDecl.addAll(d.builder.optDecl);
+    c.reqUsed.addAll(d.builder.reqUsed);
+    c.optUsed.addAll(d.builder.optUsed);
+    c.setOpts.addAll(d.builder.setOpts);
+    c.map.putAll(d.builder.map);
+    c.freeImpls.putAll(d.builder.freeImpls);
+    c.freeParams.putAll(d.builder.freeParams);
+    c.lateBindClazz.putAll(d.builder.lateBindClazz);
+
+    return c;
+  }
+
+  public final <T> ConfigurationModuleBuilder bind(Class<?> iface, Impl<?> opt) {
+    ConfigurationModuleBuilder c = deepCopy();
+    c.processUse(opt);
+    c.freeImpls.put(iface, opt);
+    return c;
+  }
+
+  public final <T> ConfigurationModuleBuilder bindSetEntry(Class<? extends Name<Set<T>>> iface, String impl) {
+    ConfigurationModuleBuilder c = deepCopy();
+    try {
+      c.b.bindSetEntry(iface, impl);
+    } catch (BindException e) {
+      throw new ClassHierarchyException(e);
+    }
+    return c;
+  }
+
+  public final <T> ConfigurationModuleBuilder bindSetEntry(Class<? extends Name<Set<T>>> iface, Class<? extends T> impl) {
+    ConfigurationModuleBuilder c = deepCopy();
+    try {
+      c.b.bindSetEntry(iface, impl);
+    } catch (BindException e) {
+      throw new ClassHierarchyException(e);
+    }
+    return c;
+  }
+
+  public final <T> ConfigurationModuleBuilder bindSetEntry(Class<? extends Name<Set<T>>> iface, Impl<? extends T> opt) {
+    ConfigurationModuleBuilder c = deepCopy();
+    c.processUse(opt);
+    c.freeImpls.put(iface, opt);
+    if (!setOpts.contains(opt)) {
+      c.setOpts.add(opt);
+    }
+    return c;
+  }
+
+  public final <T> ConfigurationModuleBuilder bindSetEntry(Class<? extends Name<Set<T>>> iface, Param<? extends T> opt) {
+    ConfigurationModuleBuilder c = deepCopy();
+    c.processUse(opt);
+    c.freeParams.put(iface, opt);
+    if (!setOpts.contains(opt)) {
+      c.setOpts.add(opt);
+    }
+    return c;
+  }
+
+
+  public final <T> ConfigurationModuleBuilder bindImplementation(Class<T> iface,
+                                                                 Class<? extends T> impl) {
+    ConfigurationModuleBuilder c = deepCopy();
+    try {
+      c.b.bindImplementation(iface, impl);
+    } catch (BindException e) {
+      throw new ClassHierarchyException(e);
+    }
+    return c;
+  }
+
+  public final <T> ConfigurationModuleBuilder bindImplementation(Class<T> iface,
+                                                                 String impl) {
+    ConfigurationModuleBuilder c = deepCopy();
+    c.lateBindClazz.put(iface, impl);
+    return c;
+  }
+
+  public final <T> ConfigurationModuleBuilder bindImplementation(Class<T> iface,
+                                                                 Impl<? extends T> opt) {
+    ConfigurationModuleBuilder c = deepCopy();
+    c.processUse(opt);
+    c.freeImpls.put(iface, opt);
+    return c;
+  }
+
+  public final <T> ConfigurationModuleBuilder bindNamedParameter(
+      Class<? extends Name<T>> name, String value) {
+    ConfigurationModuleBuilder c = deepCopy();
+    try {
+      c.b.bindNamedParameter(name, value);
+    } catch (BindException e) {
+      throw new ClassHierarchyException(e);
+    }
+    return c;
+  }
+
+  public final <T> ConfigurationModuleBuilder bindNamedParameter(
+      Class<? extends Name<T>> name, Param<T> opt) {
+    ConfigurationModuleBuilder c = deepCopy();
+    c.processUse(opt);
+    c.freeParams.put(name, opt);
+    return c;
+  }
+
+  public final <T> ConfigurationModuleBuilder bindNamedParameter(
+      Class<? extends Name<T>> iface, Class<? extends T> impl) {
+    ConfigurationModuleBuilder c = deepCopy();
+    try {
+      c.b.bindNamedParameter(iface, impl);
+    } catch (BindException e) {
+      throw new ClassHierarchyException(e);
+    }
+    return c;
+  }
+
+  public final <T> ConfigurationModuleBuilder bindNamedParameter(
+      Class<? extends Name<T>> iface, Impl<? extends T> opt) {
+    ConfigurationModuleBuilder c = deepCopy();
+    c.processUse(opt);
+    c.freeImpls.put(iface, opt);
+    return c;
+  }
+
+  public final <T> ConfigurationModuleBuilder bindConstructor(Class<T> clazz,
+                                                              Class<? extends ExternalConstructor<? extends T>> constructor) {
+    ConfigurationModuleBuilder c = deepCopy();
+    try {
+      c.b.bindConstructor(clazz, constructor);
+    } catch (BindException e) {
+      throw new ClassHierarchyException(e);
+    }
+    return c;
+  }
+
+  public final <T> ConfigurationModuleBuilder bindConstructor(Class<T> cons,
+                                                              Impl<? extends ExternalConstructor<? extends T>> v) {
+    ConfigurationModuleBuilder c = deepCopy();
+    c.processUse(v);
+    c.freeImpls.put(cons, v);
+    return c;
+  }
+
+  public final <T> ConfigurationModuleBuilder bindList(Class<? extends Name<List<T>>> iface,
+                                                       Impl<List> opt) {
+    ConfigurationModuleBuilder c = deepCopy();
+    c.processUse(opt);
+    c.freeImpls.put(iface, opt);
+    return c;
+  }
+
+  public final <T> ConfigurationModuleBuilder bindList(Class<? extends Name<List<T>>> iface,
+                                                       Param<List> opt) {
+    ConfigurationModuleBuilder c = deepCopy();
+    c.processUse(opt);
+    c.freeParams.put(iface, opt);
+    return c;
+  }
+
+  public final <T> ConfigurationModuleBuilder bindList(Class<? extends Name<List<T>>> iface, List list) {
+    ConfigurationModuleBuilder c = deepCopy();
+    c.b.bindList(iface, list);
+    return c;
+  }
+
+  private final <T> void processUse(Object impl) {
+    Field f = map.get(impl);
+    if (f == null) { /* throw */
+      throw new ClassHierarchyException("Unknown Impl/Param when binding " + ReflectionUtilities.getSimpleName(impl.getClass()) + ".  Did you pass in a field from some other module?");
+    }
+    if (!reqUsed.contains(f)) {
+      reqUsed.add(f);
+    }
+    if (!optUsed.contains(f)) {
+      optUsed.add(f);
+    }
+  }
+
+  public final ConfigurationModule build() throws ClassHierarchyException {
+    ConfigurationModuleBuilder c = deepCopy();
+
+    if (!(c.reqUsed.containsAll(c.reqDecl) && c.optUsed.containsAll(c.optDecl))) {
+      Set<Field> fset = new MonotonicHashSet<>();
+      for (Field f : c.reqDecl) {
+        if (!c.reqUsed.contains(f)) {
+          fset.add(f);
+        }
+      }
+      for (Field f : c.optDecl) {
+        if (!c.optUsed.contains(f)) {
+          fset.add(f);
+        }
+      }
+      throw new ClassHierarchyException(
+          "Found declared options that were not used in binds: "
+              + toString(fset));
+    }
+    for (Class<?> clz : c.lateBindClazz.keySet()) {
+      try {
+        c.b.bind(ReflectionUtilities.getFullName(clz), c.lateBindClazz.get(clz));
+      } catch (NameResolutionException e) {
+        throw new ClassHierarchyException("ConfigurationModule refers to unknown class: " + c.lateBindClazz.get(clz), e);
+      } catch (BindException e) {
+        throw new ClassHierarchyException("bind failed while initializing ConfigurationModuleBuilder", e);
+      }
+    }
+    return new ConfigurationModule(c);
+  }
+
+/*  public final <T> ConfigurationModuleBuilder bind(Class<T> iface, Class<?> impl) {
+    ConfigurationModuleBuilder c = deepCopy();
+    try {
+      c.b.bind(iface, impl);
+    } catch (BindException e) {
+      throw new ClassHierarchyException(e);
+    }
+    return c;
+  } */
+
+  final ConfigurationModuleBuilder deepCopy() {
+    // ooh... this is a dirty trick --- we strip this's type off here,
+    // fortunately, we've all ready looked at the root object's class's
+    // fields, and we copy the information we extracted from them, so
+    // everything works out OK w.r.t. field detection.
+    return new ConfigurationModuleBuilder(this) {
+    };
+  }
+
+  final String toString(Set<Field> s) {
+    StringBuilder sb = new StringBuilder("{");
+    boolean first = true;
+    for (Field f : s) {
+      sb.append((first ? " " : ", ") + f.getName());
+      first = false;
+    }
+    sb.append(" }");
+    return sb.toString();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ConfigurationSerializer.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ConfigurationSerializer.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ConfigurationSerializer.java
new file mode 100644
index 0000000..46fcaff
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ConfigurationSerializer.java
@@ -0,0 +1,154 @@
+/**
+ * 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.reef.tang.formats;
+
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.DefaultImplementation;
+import org.apache.reef.tang.exceptions.BindException;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * A base interface for Configuration serializers.
+ */
+@DefaultImplementation(AvroConfigurationSerializer.class)
+public interface ConfigurationSerializer {
+
+
+  /**
+   * Stores the given Configuration in the given File.
+   *
+   * @param conf the Configuration to store
+   * @param file the file to store the Configuration in
+   * @throws java.io.IOException if there is an IO error in the process.
+   */
+  public void toFile(final Configuration conf, final File file) throws IOException;
+
+  /**
+   * Stores the given Configuration in the given Text File.
+   *
+   * @param conf the Configuration to store
+   * @param file the file to store the Configuration in
+   * @throws java.io.IOException if there is an IO error in the process.
+   */
+  public void toTextFile(final Configuration conf, final File file) throws IOException;
+
+  /**
+   * Writes the Configuration to a byte[].
+   *
+   * @param conf
+   * @return
+   * @throws IOException
+   */
+  public byte[] toByteArray(final Configuration conf) throws IOException;
+
+  /**
+   * Writes the Configuration as a String.
+   *
+   * @param configuration
+   * @return a String representation of the Configuration
+   */
+  public String toString(final Configuration configuration);
+
+
+  /**
+   * Loads a Configuration from a File created with toFile().
+   *
+   * @param file the File to read from.
+   * @return the Configuration stored in the file.
+   * @throws IOException   if the File can't be read or parsed
+   * @throws BindException if the file contains an illegal Configuration
+   */
+  public Configuration fromFile(final File file) throws IOException, BindException;
+
+  /**
+   * Loads a Configuration from a File created with toFile().
+   *
+   * @param file the File to read from.
+   * @return the Configuration stored in the file.
+   * @throws IOException   if the File can't be read or parsed
+   * @throws BindException if the file contains an illegal Configuration
+   */
+  public Configuration fromTextFile(final File file) throws IOException, BindException;
+
+  /**
+   * Loads a Configuration from a File created with toFile() with ClassHierarchy
+   *
+   * @param file
+   * @param classHierarchy
+   * @return
+   * @throws IOException
+   */
+  public Configuration fromTextFile(final File file, final ClassHierarchy classHierarchy) throws IOException;
+
+  /**
+   * Loads a Configuration from a File created with toFile().
+   *
+   * @param file           the File to read from.
+   * @param classHierarchy used to validate the configuration against
+   * @return the Configuration stored in the file.
+   * @throws IOException   if the File can't be read or parsed
+   * @throws BindException if the file contains an illegal Configuration
+   */
+  public Configuration fromFile(final File file, final ClassHierarchy classHierarchy) throws IOException, BindException;
+
+  /**
+   * Loads a Configuration from a byte[] created with toByteArray().
+   *
+   * @param theBytes the bytes to deserialize.
+   * @return the Configuration stored.
+   * @throws IOException   if the byte[] can't be deserialized
+   * @throws BindException if the byte[] contains an illegal Configuration.
+   */
+  public Configuration fromByteArray(final byte[] theBytes) throws IOException, BindException;
+
+  /**
+   * Loads a Configuration from a byte[] created with toByteArray().
+   *
+   * @param theBytes       the bytes to deserialize.
+   * @param classHierarchy used to validate the configuration against
+   * @return the Configuration stored.
+   * @throws IOException   if the byte[] can't be deserialized
+   * @throws BindException if the byte[] contains an illegal Configuration.
+   */
+  public Configuration fromByteArray(final byte[] theBytes, final ClassHierarchy classHierarchy) throws IOException, BindException;
+
+  /**
+   * Decodes a String generated via toString()
+   *
+   * @param theString to be parsed
+   * @return the Configuration stored in theString.
+   * @throws IOException   if theString can't be parsed.
+   * @throws BindException if theString contains an illegal Configuration.
+   */
+  public Configuration fromString(final String theString) throws IOException, BindException;
+
+  /**
+   * Decodes a String generated via toString()
+   *
+   * @param theString      to be parsed
+   * @param classHierarchy used to validate the configuration against
+   * @return the Configuration stored in theString.
+   * @throws IOException   if theString can't be parsed.
+   * @throws BindException if theString contains an illegal Configuration.
+   */
+  public Configuration fromString(final String theString, final ClassHierarchy classHierarchy) throws IOException, BindException;
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/Impl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/Impl.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/Impl.java
new file mode 100644
index 0000000..f3426fb
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/Impl.java
@@ -0,0 +1,22 @@
+/**
+ * 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.reef.tang.formats;
+
+public interface Impl<T> {
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/OptionalImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/OptionalImpl.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/OptionalImpl.java
new file mode 100644
index 0000000..b730feb
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/OptionalImpl.java
@@ -0,0 +1,22 @@
+/**
+ * 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.reef.tang.formats;
+
+public final class OptionalImpl<T> implements Impl<T> {
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/OptionalParameter.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/OptionalParameter.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/OptionalParameter.java
new file mode 100644
index 0000000..26d597b
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/OptionalParameter.java
@@ -0,0 +1,22 @@
+/**
+ * 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.reef.tang.formats;
+
+public final class OptionalParameter<T> implements Param<T> {
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/Param.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/Param.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/Param.java
new file mode 100644
index 0000000..355030f
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/Param.java
@@ -0,0 +1,22 @@
+/**
+ * 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.reef.tang.formats;
+
+public interface Param<T> {
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ParameterParser.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ParameterParser.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ParameterParser.java
new file mode 100644
index 0000000..be73444
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/ParameterParser.java
@@ -0,0 +1,150 @@
+/**
+ * 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.reef.tang.formats;
+
+import org.apache.reef.tang.ExternalConstructor;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.util.MonotonicTreeMap;
+import org.apache.reef.tang.util.ReflectionUtilities;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+public class ParameterParser {
+  private static final Set<String> BUILTIN_NAMES = new HashSet<String>() {
+    private static final long serialVersionUID = 1L;
+
+    {
+      Collections.addAll(this,
+          String.class.getName(),
+          Byte.class.getName(),
+          Character.class.getName(),
+          Short.class.getName(),
+          Integer.class.getName(),
+          Long.class.getName(),
+          Float.class.getName(),
+          Double.class.getName(),
+          Boolean.class.getName(),
+          Void.class.getName());
+    }
+  };
+  MonotonicTreeMap<String, Constructor<? extends ExternalConstructor<?>>> parsers = new MonotonicTreeMap<>();
+
+  @SuppressWarnings({"unchecked", "rawtypes"})
+  public void addParser(Class<? extends ExternalConstructor<?>> ec) throws BindException {
+    Class<?> tc = (Class<?>) ReflectionUtilities.getInterfaceTarget(
+        ExternalConstructor.class, ec);
+    addParser((Class) tc, (Class) ec);
+  }
+
+  public <T, U extends T> void addParser(Class<U> clazz, Class<? extends ExternalConstructor<T>> ec) throws BindException {
+    Constructor<? extends ExternalConstructor<T>> c;
+    try {
+      c = ec.getDeclaredConstructor(String.class);
+      c.setAccessible(true);
+    } catch (NoSuchMethodException e) {
+      throw new BindException("Constructor "
+          + ReflectionUtilities.getFullName(ec) + "(String) does not exist!", e);
+    }
+    c.setAccessible(true);
+    parsers.put(ReflectionUtilities.getFullName(clazz), c);
+  }
+
+  public void mergeIn(ParameterParser p) {
+    for (String s : p.parsers.keySet()) {
+      if (!parsers.containsKey(s)) {
+        parsers.put(s, p.parsers.get(s));
+      } else {
+        if (!parsers.get(s).equals(p.parsers.get(s))) {
+          throw new IllegalArgumentException(
+              "Conflict detected when merging parameter parsers! To parse " + s
+                  + " I have a: " + ReflectionUtilities.getFullName(parsers.get(s).getDeclaringClass())
+                  + " the other instance has a: " + ReflectionUtilities.getFullName(p.parsers.get(s).getDeclaringClass()));
+        }
+      }
+    }
+  }
+
+  public <T> T parse(Class<T> c, String s) {
+    Class<?> d = ReflectionUtilities.boxClass(c);
+    for (Type e : ReflectionUtilities.classAndAncestors(d)) {
+      String name = ReflectionUtilities.getFullName(e);
+      if (parsers.containsKey(name)) {
+        T ret = parse(name, s);
+        if (c.isAssignableFrom(ret.getClass())) {
+          return ret;
+        } else {
+          throw new ClassCastException("Cannot cast from " + ret.getClass() + " to " + c);
+        }
+      }
+    }
+    return parse(ReflectionUtilities.getFullName(d), s);
+  }
+
+  @SuppressWarnings("unchecked")
+  public <T> T parse(String name, String value) {
+    if (parsers.containsKey(name)) {
+      try {
+        return (T) (parsers.get(name).newInstance(value).newInstance());
+      } catch (ReflectiveOperationException e) {
+        throw new IllegalArgumentException("Error invoking constructor for "
+            + name, e);
+      }
+    } else {
+      if (name.equals(String.class.getName())) {
+        return (T) value;
+      }
+      if (name.equals(Byte.class.getName())) {
+        return (T) (Byte) Byte.parseByte(value);
+      }
+      if (name.equals(Character.class.getName())) {
+        return (T) (Character) value.charAt(0);
+      }
+      if (name.equals(Short.class.getName())) {
+        return (T) (Short) Short.parseShort(value);
+      }
+      if (name.equals(Integer.class.getName())) {
+        return (T) (Integer) Integer.parseInt(value);
+      }
+      if (name.equals(Long.class.getName())) {
+        return (T) (Long) Long.parseLong(value);
+      }
+      if (name.equals(Float.class.getName())) {
+        return (T) (Float) Float.parseFloat(value);
+      }
+      if (name.equals(Double.class.getName())) {
+        return (T) (Double) Double.parseDouble(value);
+      }
+      if (name.equals(Boolean.class.getName())) {
+        return (T) (Boolean) Boolean.parseBoolean(value);
+      }
+      if (name.equals(Void.class.getName())) {
+        throw new ClassCastException("Can't instantiate void");
+      }
+      throw new UnsupportedOperationException("Don't know how to parse a " + name);
+    }
+  }
+
+  public boolean canParse(String name) {
+    return parsers.containsKey(name) || BUILTIN_NAMES.contains(name);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/Provides.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/Provides.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/Provides.java
new file mode 100644
index 0000000..a98f081
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/Provides.java
@@ -0,0 +1,22 @@
+/**
+ * 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.reef.tang.formats;
+
+public final class Provides<T> {
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/RequiredImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/RequiredImpl.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/RequiredImpl.java
new file mode 100644
index 0000000..6355af0
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/RequiredImpl.java
@@ -0,0 +1,22 @@
+/**
+ * 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.reef.tang.formats;
+
+public final class RequiredImpl<T> implements Impl<T> {
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/RequiredParameter.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/RequiredParameter.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/RequiredParameter.java
new file mode 100644
index 0000000..f0fa97f
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/formats/RequiredParameter.java
@@ -0,0 +1,22 @@
+/**
+ * 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.reef.tang.formats;
+
+public final class RequiredParameter<T> implements Param<T> {
+}
\ No newline at end of file


[18/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnContainerManager.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnContainerManager.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnContainerManager.java
new file mode 100644
index 0000000..fc1696e
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnContainerManager.java
@@ -0,0 +1,680 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+import com.google.protobuf.ByteString;
+import org.apache.commons.collections.ListUtils;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.io.IOUtils;
+import org.apache.hadoop.service.Service;
+import org.apache.hadoop.yarn.api.records.*;
+import org.apache.hadoop.yarn.client.api.AMRMClient;
+import org.apache.hadoop.yarn.client.api.YarnClient;
+import org.apache.hadoop.yarn.client.api.async.AMRMClientAsync;
+import org.apache.hadoop.yarn.client.api.async.NMClientAsync;
+import org.apache.hadoop.yarn.client.api.async.impl.NMClientAsyncImpl;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.exceptions.YarnException;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.proto.DriverRuntimeProtocol.NodeDescriptorProto;
+import org.apache.reef.proto.DriverRuntimeProtocol.ResourceAllocationProto;
+import org.apache.reef.proto.DriverRuntimeProtocol.ResourceStatusProto;
+import org.apache.reef.proto.DriverRuntimeProtocol.RuntimeStatusProto;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.driver.DriverStatusManager;
+import org.apache.reef.runtime.common.driver.evaluator.EvaluatorManager;
+import org.apache.reef.runtime.yarn.driver.parameters.YarnHeartbeatPeriod;
+import org.apache.reef.runtime.yarn.util.YarnTypes;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.remote.Encoder;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+
+import javax.inject.Inject;
+import java.io.*;
+import java.nio.ByteBuffer;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+final class YarnContainerManager
+    implements AMRMClientAsync.CallbackHandler, NMClientAsync.CallbackHandler {
+
+  private static final Logger LOG = Logger.getLogger(YarnContainerManager.class.getName());
+
+  private static final String RUNTIME_NAME = "YARN";
+
+  private static final String ADD_FLAG = "+";
+
+  private static final String REMOVE_FLAG = "-";
+
+  private final YarnClient yarnClient = YarnClient.createYarnClient();
+
+  private final Queue<AMRMClient.ContainerRequest> requestsBeforeSentToRM = new ConcurrentLinkedQueue<>();
+
+  private final Queue<AMRMClient.ContainerRequest> requestsAfterSentToRM = new ConcurrentLinkedQueue<>();
+
+  private final Map<String, String> nodeIdToRackName = new ConcurrentHashMap<>();
+
+  private final YarnConfiguration yarnConf;
+  private final AMRMClientAsync resourceManager;
+  private final NMClientAsync nodeManager;
+  private final REEFEventHandlers reefEventHandlers;
+  private final Containers containers;
+  private final ApplicationMasterRegistration registration;
+  private final ContainerRequestCounter containerRequestCounter;
+  private final DriverStatusManager driverStatusManager;
+  private final TrackingURLProvider trackingURLProvider;
+
+  @Inject
+  YarnContainerManager(
+      final YarnConfiguration yarnConf,
+      final @Parameter(YarnHeartbeatPeriod.class) int yarnRMHeartbeatPeriod,
+      final REEFEventHandlers reefEventHandlers,
+      final Containers containers,
+      final ApplicationMasterRegistration registration,
+      final ContainerRequestCounter containerRequestCounter,
+      final DriverStatusManager driverStatusManager,
+      final TrackingURLProvider trackingURLProvider) throws IOException {
+
+    this.reefEventHandlers = reefEventHandlers;
+    this.driverStatusManager = driverStatusManager;
+
+    this.containers = containers;
+    this.registration = registration;
+    this.containerRequestCounter = containerRequestCounter;
+    this.yarnConf = yarnConf;
+    this.trackingURLProvider = trackingURLProvider;
+
+
+    this.yarnClient.init(this.yarnConf);
+
+    this.resourceManager = AMRMClientAsync.createAMRMClientAsync(yarnRMHeartbeatPeriod, this);
+    this.nodeManager = new NMClientAsyncImpl(this);
+    LOG.log(Level.FINEST, "Instantiated YarnContainerManager");
+  }
+
+  @Override
+  public final void onContainersCompleted(final List<ContainerStatus> containerStatuses) {
+    for (final ContainerStatus containerStatus : containerStatuses) {
+      onContainerStatus(containerStatus);
+    }
+  }
+
+  @Override
+  public final void onContainersAllocated(final List<Container> containers) {
+
+    // ID is used for logging only
+    final String id = String.format("%s:%d",
+        Thread.currentThread().getName().replace(' ', '_'), System.currentTimeMillis());
+
+    LOG.log(Level.FINE, "TIME: Allocated Containers {0} {1} of {2}",
+        new Object[]{id, containers.size(), this.containerRequestCounter.get()});
+
+    for (final Container container : containers) {
+      handleNewContainer(container, false);
+    }
+
+    LOG.log(Level.FINE, "TIME: Processed Containers {0}", id);
+  }
+
+  @Override
+  public void onShutdownRequest() {
+    this.reefEventHandlers.onRuntimeStatus(RuntimeStatusProto.newBuilder()
+        .setName(RUNTIME_NAME).setState(ReefServiceProtos.State.DONE).build());
+    this.driverStatusManager.onError(new Exception("Shutdown requested by YARN."));
+  }
+
+  @Override
+  public void onNodesUpdated(final List<NodeReport> nodeReports) {
+    for (final NodeReport nodeReport : nodeReports) {
+      this.nodeIdToRackName.put(nodeReport.getNodeId().toString(), nodeReport.getRackName());
+      onNodeReport(nodeReport);
+    }
+  }
+
+  @Override
+  public final float getProgress() {
+    return 0; // TODO: return actual values for progress
+  }
+
+  @Override
+  public final void onError(final Throwable throwable) {
+    onRuntimeError(throwable);
+  }
+
+  @Override
+  public final void onContainerStarted(
+      final ContainerId containerId, final Map<String, ByteBuffer> stringByteBufferMap) {
+    final Optional<Container> container = this.containers.getOptional(containerId.toString());
+    if (container.isPresent()) {
+      this.nodeManager.getContainerStatusAsync(containerId, container.get().getNodeId());
+    }
+  }
+
+  @Override
+  public final void onContainerStatusReceived(
+      final ContainerId containerId, final ContainerStatus containerStatus) {
+    onContainerStatus(containerStatus);
+  }
+
+  @Override
+  public final void onContainerStopped(final ContainerId containerId) {
+    final boolean hasContainer = this.containers.hasContainer(containerId.toString());
+    if (hasContainer) {
+      final ResourceStatusProto.Builder resourceStatusBuilder =
+          ResourceStatusProto.newBuilder().setIdentifier(containerId.toString());
+      resourceStatusBuilder.setState(ReefServiceProtos.State.DONE);
+      this.reefEventHandlers.onResourceStatus(resourceStatusBuilder.build());
+    }
+  }
+
+  @Override
+  public final void onStartContainerError(
+      final ContainerId containerId, final Throwable throwable) {
+    handleContainerError(containerId, throwable);
+  }
+
+  @Override
+  public final void onGetContainerStatusError(
+      final ContainerId containerId, final Throwable throwable) {
+    handleContainerError(containerId, throwable);
+  }
+
+  @Override
+  public final void onStopContainerError(
+      final ContainerId containerId, final Throwable throwable) {
+    handleContainerError(containerId, throwable);
+  }
+
+  /**
+   * Submit the given launchContext to the given container.
+   */
+  void submit(final Container container, final ContainerLaunchContext launchContext) {
+    this.nodeManager.startContainerAsync(container, launchContext);
+  }
+
+  /**
+   * Release the given container.
+   */
+  void release(final String containerId) {
+    LOG.log(Level.FINE, "Release container: {0}", containerId);
+    final Container container = this.containers.removeAndGet(containerId);
+    this.resourceManager.releaseAssignedContainer(container.getId());
+    logContainerRemoval(container.getId().toString());
+    updateRuntimeStatus();
+  }
+
+  void onStart() {
+
+    this.yarnClient.start();
+    this.resourceManager.init(this.yarnConf);
+    this.resourceManager.start();
+    this.nodeManager.init(this.yarnConf);
+    this.nodeManager.start();
+
+    try {
+      for (final NodeReport nodeReport : this.yarnClient.getNodeReports(NodeState.RUNNING)) {
+        onNodeReport(nodeReport);
+      }
+    } catch (IOException | YarnException e) {
+      LOG.log(Level.WARNING, "Unable to fetch node reports from YARN.", e);
+      onRuntimeError(e);
+    }
+
+    try {
+      this.registration.setRegistration(this.resourceManager.registerApplicationMaster(
+          "", 0, this.trackingURLProvider.getTrackingUrl()));
+      LOG.log(Level.FINE, "YARN registration: {0}", registration);
+
+    } catch (final YarnException | IOException e) {
+      LOG.log(Level.WARNING, "Unable to register application master.", e);
+      onRuntimeError(e);
+    }
+
+    // TODO: this is currently being developed on a hacked 2.4.0 bits, should be 2.4.1
+    final String minVersionToGetPreviousContainer = "2.4.0";
+
+    // when supported, obtain the list of the containers previously allocated, and write info to driver folder
+    if (YarnTypes.isAtOrAfterVersion(minVersionToGetPreviousContainer)) {
+      LOG.log(Level.FINEST, "Hadoop version is {0} or after with support to retain previous containers, processing previous containers.", minVersionToGetPreviousContainer);
+      processPreviousContainers();
+    }
+  }
+
+  void onStop() {
+
+    LOG.log(Level.FINE, "Stop Runtime: RM status {0}", this.resourceManager.getServiceState());
+
+    if (this.resourceManager.getServiceState() == Service.STATE.STARTED) {
+      // invariant: if RM is still running then we declare success.
+      try {
+        this.reefEventHandlers.close();
+        this.resourceManager.unregisterApplicationMaster(
+            FinalApplicationStatus.SUCCEEDED, null, null);
+        this.resourceManager.close();
+      } catch (final Exception e) {
+        LOG.log(Level.WARNING, "Error shutting down YARN application", e);
+      }
+    }
+
+    if (this.nodeManager.getServiceState() == Service.STATE.STARTED) {
+      try {
+        this.nodeManager.close();
+      } catch (final IOException e) {
+        LOG.log(Level.WARNING, "Error closing YARN Node Manager", e);
+      }
+    }
+  }
+
+  /////////////////////////////////////////////////////////////
+  // HELPER METHODS
+
+  private void onNodeReport(final NodeReport nodeReport) {
+    LOG.log(Level.FINE, "Send node descriptor: {0}", nodeReport);
+    this.reefEventHandlers.onNodeDescriptor(NodeDescriptorProto.newBuilder()
+        .setIdentifier(nodeReport.getNodeId().toString())
+        .setHostName(nodeReport.getNodeId().getHost())
+        .setPort(nodeReport.getNodeId().getPort())
+        .setMemorySize(nodeReport.getCapability().getMemory())
+        .setRackName(nodeReport.getRackName())
+        .build());
+  }
+
+  private void handleContainerError(final ContainerId containerId, final Throwable throwable) {
+
+    final ResourceStatusProto.Builder resourceStatusBuilder =
+        ResourceStatusProto.newBuilder().setIdentifier(containerId.toString());
+
+    resourceStatusBuilder.setState(ReefServiceProtos.State.FAILED);
+    resourceStatusBuilder.setExitCode(1);
+    resourceStatusBuilder.setDiagnostics(throwable.getMessage());
+    this.reefEventHandlers.onResourceStatus(resourceStatusBuilder.build());
+  }
+
+  private void processPreviousContainers() {
+    final List<Container> previousContainers = this.registration.getRegistration().getContainersFromPreviousAttempts();
+    if (previousContainers != null && !previousContainers.isEmpty()) {
+      LOG.log(Level.INFO, "Driver restarted, with {0} previous containers", previousContainers.size());
+      this.driverStatusManager.setNumPreviousContainers(previousContainers.size());
+      final Set<String> expectedContainers = getExpectedContainersFromLogReplay();
+      final int numExpectedContainers = expectedContainers.size();
+      final int numPreviousContainers = previousContainers.size();
+      if (numExpectedContainers > numPreviousContainers) {
+        // we expected more containers to be alive, some containers must have died during driver restart
+        LOG.log(Level.WARNING, "Expected {0} containers while only {1} are still alive", new Object[]{numExpectedContainers, numPreviousContainers});
+        final Set<String> previousContainersIds = new HashSet<>();
+        for (final Container container : previousContainers) {
+          previousContainersIds.add(container.getId().toString());
+        }
+        for (final String expectedContainerId : expectedContainers) {
+          if (!previousContainersIds.contains(expectedContainerId)) {
+            logContainerRemoval(expectedContainerId);
+            LOG.log(Level.WARNING, "Expected container [{0}] not alive, must have failed during driver restart.", expectedContainerId);
+            informAboutConatinerFailureDuringRestart(expectedContainerId);
+          }
+        }
+      }
+      if (numExpectedContainers < numPreviousContainers) {
+        // somehow we have more alive evaluators, this should not happen
+        throw new RuntimeException("Expected only [" + numExpectedContainers + "] containers but resource manager believe that [" + numPreviousContainers + "] are outstanding for driver.");
+      }
+
+      //  numExpectedContainers == numPreviousContainers
+      for (final Container container : previousContainers) {
+        LOG.log(Level.FINE, "Previous container: [{0}]", container.toString());
+        if (!expectedContainers.contains(container.getId().toString())) {
+          throw new RuntimeException("Not expecting container " + container.getId().toString());
+        }
+        handleNewContainer(container, true);
+      }
+    }
+  }
+
+  /**
+   * Handles container status reports. Calls come from YARN.
+   *
+   * @param value containing the container status
+   */
+  private void onContainerStatus(final ContainerStatus value) {
+
+    final String containerId = value.getContainerId().toString();
+    final boolean hasContainer = this.containers.hasContainer(containerId);
+
+    if (hasContainer) {
+      LOG.log(Level.FINE, "Received container status: {0}", containerId);
+
+      final ResourceStatusProto.Builder status =
+          ResourceStatusProto.newBuilder().setIdentifier(containerId);
+
+      switch (value.getState()) {
+        case COMPLETE:
+          LOG.log(Level.FINE, "Container completed: status {0}", value.getExitStatus());
+          switch (value.getExitStatus()) {
+            case 0:
+              status.setState(ReefServiceProtos.State.DONE);
+              break;
+            case 143:
+              status.setState(ReefServiceProtos.State.KILLED);
+              break;
+            default:
+              status.setState(ReefServiceProtos.State.FAILED);
+          }
+          status.setExitCode(value.getExitStatus());
+          // remove the completed container (can be either done/killed/failed) from book keeping
+          this.containers.removeAndGet(containerId);
+          logContainerRemoval(containerId);
+          break;
+        default:
+          LOG.info("Container running");
+          status.setState(ReefServiceProtos.State.RUNNING);
+      }
+
+      if (value.getDiagnostics() != null) {
+        LOG.log(Level.FINE, "Container diagnostics: {0}", value.getDiagnostics());
+        status.setDiagnostics(value.getDiagnostics());
+      }
+
+      this.reefEventHandlers.onResourceStatus(status.build());
+    }
+  }
+
+  void onContainerRequest(final AMRMClient.ContainerRequest... containerRequests) {
+
+    synchronized (this) {
+      this.containerRequestCounter.incrementBy(containerRequests.length);
+      this.requestsBeforeSentToRM.addAll(Arrays.asList(containerRequests));
+      doHomogeneousRequests();
+    }
+
+    this.updateRuntimeStatus();
+  }
+
+  /**
+   * Handles new container allocations. Calls come from YARN.
+   *
+   * @param container newly allocated
+   */
+  private void handleNewContainer(final Container container, final boolean isRecoveredContainer) {
+
+    LOG.log(Level.FINE, "allocated container: id[ {0} ]", container.getId());
+    // recovered container is not new allocation, it is just checking back from previous driver failover
+    if (!isRecoveredContainer) {
+      synchronized (this) {
+        if (matchContainerWithPendingRequest(container)) {
+          final AMRMClient.ContainerRequest matchedRequest = this.requestsAfterSentToRM.peek();
+          this.containerRequestCounter.decrement();
+          this.containers.add(container);
+
+          LOG.log(Level.FINEST, "{0} matched with {1}", new Object[]{container.toString(), matchedRequest.toString()});
+
+          // Due to the bug YARN-314 and the workings of AMRMCClientAsync, when x-priority m-capacity zero-container request
+          // and x-priority n-capacity nonzero-container request are sent together, where m > n, RM ignores the latter.
+          // Therefore it is necessary avoid sending zero-container request, even it means getting extra containers.
+          // It is okay to send nonzero m-capacity and n-capacity request together since bigger containers can be matched.
+          // TODO: revisit this when implementing locality-strictness (i.e. a specific rack request can be ignored)
+          if (this.requestsAfterSentToRM.size() > 1) {
+            try {
+              this.resourceManager.removeContainerRequest(matchedRequest);
+            } catch (final Exception e) {
+              LOG.log(Level.WARNING, "Nothing to remove from Async AMRM client's queue, removal attempt failed with exception", e);
+            }
+          }
+
+          this.requestsAfterSentToRM.remove();
+          doHomogeneousRequests();
+
+          LOG.log(Level.FINEST, "Allocated Container: memory = {0}, core number = {1}", new Object[]{container.getResource().getMemory(), container.getResource().getVirtualCores()});
+          this.reefEventHandlers.onResourceAllocation(ResourceAllocationProto.newBuilder()
+              .setIdentifier(container.getId().toString())
+              .setNodeId(container.getNodeId().toString())
+              .setResourceMemory(container.getResource().getMemory())
+              .setVirtualCores(container.getResource().getVirtualCores())
+              .build());
+          // we only add this to Container log after the Container has been registered as an REEF Evaluator.
+          logContainerAddition(container.getId().toString());
+          this.updateRuntimeStatus();
+        } else {
+          LOG.log(Level.WARNING, "Got an extra container {0} that doesn't match, releasing...", container.getId());
+          this.resourceManager.releaseAssignedContainer(container.getId());
+        }
+      }
+    }
+  }
+
+  private synchronized void doHomogeneousRequests() {
+    if (this.requestsAfterSentToRM.isEmpty()) {
+      final AMRMClient.ContainerRequest firstRequest = this.requestsBeforeSentToRM.peek();
+
+      while (!this.requestsBeforeSentToRM.isEmpty() && isSameKindOfRequest(firstRequest, this.requestsBeforeSentToRM.peek())) {
+        final AMRMClient.ContainerRequest homogeneousRequest = this.requestsBeforeSentToRM.remove();
+        this.resourceManager.addContainerRequest(homogeneousRequest);
+        this.requestsAfterSentToRM.add(homogeneousRequest);
+      }
+    }
+  }
+
+  private boolean isSameKindOfRequest(AMRMClient.ContainerRequest r1, AMRMClient.ContainerRequest r2) {
+    return r1.getPriority().compareTo(r2.getPriority()) == 0
+        && r1.getCapability().compareTo(r2.getCapability()) == 0
+        && r1.getRelaxLocality() == r2.getRelaxLocality()
+        && ListUtils.isEqualList(r1.getNodes(), r2.getNodes())
+        && ListUtils.isEqualList(r1.getRacks(), r2.getRacks());
+  }
+
+  /**
+   * Match to see whether the container satisfies the request.
+   * We take into consideration that RM has some freedom in rounding
+   * up the allocation and in placing containers on other machines.
+   */
+  private boolean matchContainerWithPendingRequest(Container container) {
+    if (this.requestsAfterSentToRM.isEmpty()) {
+      return false;
+    }
+
+    final AMRMClient.ContainerRequest request = this.requestsAfterSentToRM.peek();
+    final boolean resourceCondition = container.getResource().getMemory() >= request.getCapability().getMemory(); // TODO: check vcores once YARN-2380 is resolved
+    final boolean nodeCondition = request.getNodes() == null
+        || request.getNodes().contains(container.getNodeId().getHost());
+    final boolean rackCondition = request.getRacks() == null
+        || request.getRacks().contains(this.nodeIdToRackName.get(container.getNodeId().toString()));
+
+    return resourceCondition && (request.getRelaxLocality() || (rackCondition && nodeCondition));
+  }
+
+  /**
+   * Update the driver with my current status
+   */
+  private void updateRuntimeStatus() {
+
+    final DriverRuntimeProtocol.RuntimeStatusProto.Builder builder =
+        DriverRuntimeProtocol.RuntimeStatusProto.newBuilder()
+            .setName(RUNTIME_NAME)
+            .setState(ReefServiceProtos.State.RUNNING)
+            .setOutstandingContainerRequests(this.containerRequestCounter.get());
+
+    for (final String allocatedContainerId : this.containers.getContainerIds()) {
+      builder.addContainerAllocation(allocatedContainerId);
+    }
+
+    this.reefEventHandlers.onRuntimeStatus(builder.build());
+  }
+
+  private void onRuntimeError(final Throwable throwable) {
+
+    // SHUTDOWN YARN
+    try {
+      this.reefEventHandlers.close();
+      this.resourceManager.unregisterApplicationMaster(
+          FinalApplicationStatus.FAILED, throwable.getMessage(), null);
+    } catch (final Exception e) {
+      LOG.log(Level.WARNING, "Error shutting down YARN application", e);
+    } finally {
+      this.resourceManager.stop();
+    }
+
+    final RuntimeStatusProto.Builder runtimeStatusBuilder = RuntimeStatusProto.newBuilder()
+        .setState(ReefServiceProtos.State.FAILED)
+        .setName(RUNTIME_NAME);
+
+    final Encoder<Throwable> codec = new ObjectSerializableCodec<>();
+    runtimeStatusBuilder.setError(ReefServiceProtos.RuntimeErrorProto.newBuilder()
+        .setName(RUNTIME_NAME)
+        .setMessage(throwable.getMessage())
+        .setException(ByteString.copyFrom(codec.encode(throwable)))
+        .build())
+        .build();
+
+    this.reefEventHandlers.onRuntimeStatus(runtimeStatusBuilder.build());
+  }
+
+  private Set<String> getExpectedContainersFromLogReplay() {
+    final org.apache.hadoop.conf.Configuration config = new org.apache.hadoop.conf.Configuration();
+    config.setBoolean("dfs.support.append", true);
+    config.setBoolean("dfs.support.broken.append", true);
+    final Set<String> expectedContainers = new HashSet<>();
+    try {
+      final FileSystem fs = FileSystem.get(config);
+      final Path path = new Path(getChangeLogLocation());
+      if (!fs.exists(path)) {
+        // empty set
+        return expectedContainers;
+      } else {
+        final BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(path)));
+        String line = br.readLine();
+        while (line != null) {
+          if (line.startsWith(ADD_FLAG)) {
+            final String containerId = line.substring(ADD_FLAG.length());
+            if (expectedContainers.contains(containerId)) {
+              throw new RuntimeException("Duplicated add container record found in the change log for container " + containerId);
+            }
+            expectedContainers.add(containerId);
+          } else if (line.startsWith(REMOVE_FLAG)) {
+            final String containerId = line.substring(REMOVE_FLAG.length());
+            if (!expectedContainers.contains(containerId)) {
+              throw new RuntimeException("Change log includes record that try to remove non-exist or duplicate remove record for container + " + containerId);
+            }
+            expectedContainers.remove(containerId);
+          }
+          line = br.readLine();
+        }
+        br.close();
+      }
+    } catch (final IOException e) {
+      throw new RuntimeException("Cannot read from log file", e);
+    }
+    return expectedContainers;
+  }
+
+  private void informAboutConatinerFailureDuringRestart(final String containerId) {
+    LOG.log(Level.WARNING, "Container [" + containerId +
+        "] has failed during driver restart process, FailedEvaluaorHandler will be triggered, but no additional evaluator can be requested due to YARN-2433.");
+    // trigger a failed evaluator event
+    this.reefEventHandlers.onResourceStatus(ResourceStatusProto.newBuilder()
+        .setIdentifier(containerId)
+        .setState(ReefServiceProtos.State.FAILED)
+        .setExitCode(1)
+        .setDiagnostics("Container [" + containerId + "] failed during driver restart process.")
+        .setIsFromPreviousDriver(true)
+        .build());
+  }
+
+  private void writeToEvaluatorLog(final String entry) throws IOException {
+    final org.apache.hadoop.conf.Configuration config = new org.apache.hadoop.conf.Configuration();
+    config.setBoolean("dfs.support.append", true);
+    config.setBoolean("dfs.support.broken.append", true);
+    final FileSystem fs = getFileSystemInstance();
+    final Path path = new Path(getChangeLogLocation());
+    final boolean appendToLog = fs.exists(path);
+
+    try (
+        final BufferedWriter bw = appendToLog ?
+            new BufferedWriter(new OutputStreamWriter(fs.append(path))) :
+            new BufferedWriter(new OutputStreamWriter(fs.create(path)));
+    ) {
+      bw.write(entry);
+    } catch (final IOException e) {
+      if (appendToLog) {
+        LOG.log(Level.FINE, "Unable to add an entry to the Evaluator log. Attempting append by delete and recreate", e);
+        appendByDeleteAndCreate(fs, path, entry);
+      }
+    }
+  }
+
+  private FileSystem getFileSystemInstance() throws IOException {
+    final org.apache.hadoop.conf.Configuration config = new org.apache.hadoop.conf.Configuration();
+    config.setBoolean("dfs.support.append", true);
+    config.setBoolean("dfs.support.broken.append", true);
+    return FileSystem.get(config);
+  }
+
+  /**
+   * For certain HDFS implementation, the append operation may not be supported (e.g., Azure blob - wasb)
+   * in this case, we will emulate the append operation by reading the content, appending entry at the end,
+   * then recreating the file with appended content.
+   *
+   * @throws java.io.IOException when the file can't be written.
+   */
+
+  private void appendByDeleteAndCreate(final FileSystem fs, final Path path, final String appendEntry) throws IOException {
+    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+
+    try (final InputStream inputStream = fs.open(path)) {
+      IOUtils.copyBytes(inputStream, outputStream, 4096, true);
+    }
+
+    final String newContent = outputStream.toString() + appendEntry;
+    fs.delete(path, true);
+
+    try (final FSDataOutputStream newOutput = fs.create(path);
+         final InputStream newInput = new ByteArrayInputStream(newContent.getBytes())) {
+      IOUtils.copyBytes(newInput, newOutput, 4096, true);
+    }
+
+  }
+
+  private String getChangeLogLocation() {
+    return "/ReefApplications/" + EvaluatorManager.getJobIdentifier() + "/evaluatorsChangesLog";
+  }
+
+  private void logContainerAddition(final String containerId) {
+    final String entry = ADD_FLAG + containerId + System.lineSeparator();
+    try {
+      writeToEvaluatorLog(entry);
+    } catch (final IOException e) {
+      LOG.log(Level.WARNING, "Unable to log the addition of container [" + containerId +
+          "] to the container log. Driver restart won't work properly.", e);
+    }
+  }
+
+  private void logContainerRemoval(final String containerId) {
+    final String entry = REMOVE_FLAG + containerId + System.lineSeparator();
+    try {
+      writeToEvaluatorLog(entry);
+    } catch (final IOException e) {
+      LOG.log(Level.WARNING, "Unable to log the removal of container [" + containerId +
+          "] to the container log. Driver restart won't work properly.", e);
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnContainerRequestHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnContainerRequestHandler.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnContainerRequestHandler.java
new file mode 100644
index 0000000..f2c3a24
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnContainerRequestHandler.java
@@ -0,0 +1,32 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+import org.apache.hadoop.yarn.client.api.AMRMClient;
+import org.apache.reef.tang.annotations.DefaultImplementation;
+
+@DefaultImplementation(YarnContainerRequestHandlerImpl.class)
+public interface YarnContainerRequestHandler {
+  /**
+   * Enqueue a set of container requests with YARN.
+   *
+   * @param containerRequests
+   */
+  void onContainerRequest(final AMRMClient.ContainerRequest... containerRequests);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnContainerRequestHandlerImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnContainerRequestHandlerImpl.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnContainerRequestHandlerImpl.java
new file mode 100644
index 0000000..4007a5d
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnContainerRequestHandlerImpl.java
@@ -0,0 +1,47 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+import org.apache.hadoop.yarn.client.api.AMRMClient;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Side-channel to request containers from YARN using AMRMClient.ContainerRequest requests.
+ */
+public final class YarnContainerRequestHandlerImpl implements YarnContainerRequestHandler {
+  private static final Logger LOG = Logger.getLogger(YarnContainerRequestHandlerImpl.class.getName());
+
+  private final YarnContainerManager containerManager;
+
+
+  @Inject
+  YarnContainerRequestHandlerImpl(final YarnContainerManager containerManager) {
+    this.containerManager = containerManager;
+    LOG.log(Level.FINEST, "Instantiated 'YarnContainerRequestHandler'");
+  }
+
+  @Override
+  public void onContainerRequest(final AMRMClient.ContainerRequest... containerRequests) {
+    LOG.log(Level.FINEST, "Sending container requests to YarnContainerManager.");
+    this.containerManager.onContainerRequest(containerRequests);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnDriverConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnDriverConfiguration.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnDriverConfiguration.java
new file mode 100644
index 0000000..f240b7c
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnDriverConfiguration.java
@@ -0,0 +1,95 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.reef.io.TempFileCreator;
+import org.apache.reef.io.WorkingDirectoryTempFileCreator;
+import org.apache.reef.runtime.common.driver.api.AbstractDriverRuntimeConfiguration;
+import org.apache.reef.runtime.common.driver.api.ResourceLaunchHandler;
+import org.apache.reef.runtime.common.driver.api.ResourceReleaseHandler;
+import org.apache.reef.runtime.common.driver.api.ResourceRequestHandler;
+import org.apache.reef.runtime.common.files.RuntimeClasspathProvider;
+import org.apache.reef.runtime.common.parameters.JVMHeapSlack;
+import org.apache.reef.runtime.yarn.YarnClasspathProvider;
+import org.apache.reef.runtime.yarn.driver.parameters.JobSubmissionDirectory;
+import org.apache.reef.runtime.yarn.driver.parameters.YarnHeartbeatPeriod;
+import org.apache.reef.runtime.yarn.util.YarnConfigurationConstructor;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.OptionalParameter;
+import org.apache.reef.tang.formats.RequiredParameter;
+import org.apache.reef.wake.time.Clock;
+
+/**
+ * Created by marku_000 on 2014-07-07.
+ */
+public class YarnDriverConfiguration extends ConfigurationModuleBuilder {
+  /**
+   * @see org.apache.reef.runtime.yarn.driver.parameters.JobSubmissionDirectory
+   */
+  public static final RequiredParameter<String> JOB_SUBMISSION_DIRECTORY = new RequiredParameter<>();
+  /**
+   * @see org.apache.reef.runtime.yarn.driver.parameters.YarnHeartbeatPeriod.class
+   */
+  public static final OptionalParameter<Integer> YARN_HEARTBEAT_INTERVAL = new OptionalParameter<>();
+
+  /**
+   * @see AbstractDriverRuntimeConfiguration.JobIdentifier.class
+   */
+  public static final RequiredParameter<String> JOB_IDENTIFIER = new RequiredParameter<>();
+
+  /**
+   * @see AbstractDriverRuntimeConfiguration.EvaluatorTimeout
+   */
+  public static final OptionalParameter<Long> EVALUATOR_TIMEOUT = new OptionalParameter<>();
+
+  /**
+   * The client remote identifier.
+   */
+  public static final OptionalParameter<String> CLIENT_REMOTE_IDENTIFIER = new OptionalParameter<>();
+
+  /**
+   * The fraction of the container memory NOT to use for the Java Heap.
+   */
+  public static final OptionalParameter<Double> JVM_HEAP_SLACK = new OptionalParameter<>();
+
+
+  public static ConfigurationModule CONF = new YarnDriverConfiguration()
+      // Bind the YARN runtime for the resource manager.
+      .bindImplementation(ResourceLaunchHandler.class, YARNResourceLaunchHandler.class)
+      .bindImplementation(ResourceReleaseHandler.class, YARNResourceReleaseHandler.class)
+      .bindImplementation(ResourceRequestHandler.class, YarnResourceRequestHandler.class)
+      .bindConstructor(YarnConfiguration.class, YarnConfigurationConstructor.class)
+      .bindSetEntry(Clock.RuntimeStartHandler.class, YARNRuntimeStartHandler.class)
+      .bindSetEntry(Clock.RuntimeStopHandler.class, YARNRuntimeStopHandler.class)
+      .bindImplementation(TempFileCreator.class, WorkingDirectoryTempFileCreator.class)
+
+          // Bind the YARN Configuration parameters
+      .bindNamedParameter(JobSubmissionDirectory.class, JOB_SUBMISSION_DIRECTORY)
+      .bindNamedParameter(YarnHeartbeatPeriod.class, YARN_HEARTBEAT_INTERVAL)
+
+          // Bind the fields bound in AbstractDriverRuntimeConfiguration
+      .bindNamedParameter(AbstractDriverRuntimeConfiguration.JobIdentifier.class, JOB_IDENTIFIER)
+      .bindNamedParameter(AbstractDriverRuntimeConfiguration.EvaluatorTimeout.class, EVALUATOR_TIMEOUT)
+      .bindNamedParameter(AbstractDriverRuntimeConfiguration.ClientRemoteIdentifier.class, CLIENT_REMOTE_IDENTIFIER)
+      .bindNamedParameter(JVMHeapSlack.class, JVM_HEAP_SLACK)
+      .bindImplementation(RuntimeClasspathProvider.class, YarnClasspathProvider.class)
+      .build();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnResourceRequestHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnResourceRequestHandler.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnResourceRequestHandler.java
new file mode 100644
index 0000000..6762362
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YarnResourceRequestHandler.java
@@ -0,0 +1,111 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+import org.apache.hadoop.yarn.api.records.Priority;
+import org.apache.hadoop.yarn.api.records.Resource;
+import org.apache.hadoop.yarn.client.api.AMRMClient;
+import org.apache.hadoop.yarn.util.Records;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.api.ResourceRequestHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Accepts resource requests from the REEF layer, translates them into requests for YARN and hands them to the
+ * appropriate handler for those.
+ */
+@DriverSide
+@Private
+public final class YarnResourceRequestHandler implements ResourceRequestHandler {
+
+  private static final Logger LOG = Logger.getLogger(YarnResourceRequestHandler.class.getName());
+  private final YarnContainerRequestHandler yarnContainerRequestHandler;
+  private final ApplicationMasterRegistration registration;
+
+  @Inject
+  YarnResourceRequestHandler(final YarnContainerRequestHandler yarnContainerRequestHandler,
+                             final ApplicationMasterRegistration registration) {
+    this.yarnContainerRequestHandler = yarnContainerRequestHandler;
+    this.registration = registration;
+  }
+
+  @Override
+  public synchronized void onNext(final DriverRuntimeProtocol.ResourceRequestProto resourceRequestProto) {
+    LOG.log(Level.FINEST, "Got ResourceRequestProto in YarnResourceRequestHandler: memory = {0}, cores = {1}.", new Object[]{resourceRequestProto.getMemorySize(), resourceRequestProto.getVirtualCores()});
+
+    final String[] nodes = resourceRequestProto.getNodeNameCount() == 0 ? null :
+        resourceRequestProto.getNodeNameList().toArray(new String[resourceRequestProto.getNodeNameCount()]);
+    final String[] racks = resourceRequestProto.getRackNameCount() == 0 ? null :
+        resourceRequestProto.getRackNameList().toArray(new String[resourceRequestProto.getRackNameCount()]);
+
+    // set the priority for the request
+    final Priority pri = getPriority(resourceRequestProto);
+    final Resource resource = getResource(resourceRequestProto);
+    final boolean relax_locality = !resourceRequestProto.hasRelaxLocality() || resourceRequestProto.getRelaxLocality();
+
+    final AMRMClient.ContainerRequest[] containerRequests =
+        new AMRMClient.ContainerRequest[resourceRequestProto.getResourceCount()];
+
+    for (int i = 0; i < resourceRequestProto.getResourceCount(); i++) {
+      containerRequests[i] = new AMRMClient.ContainerRequest(resource, nodes, racks, pri, relax_locality);
+    }
+    this.yarnContainerRequestHandler.onContainerRequest(containerRequests);
+  }
+
+  private synchronized Resource getResource(final DriverRuntimeProtocol.ResourceRequestProto resourceRequestProto) {
+    final Resource result = Records.newRecord(Resource.class);
+    final int memory = getMemory(resourceRequestProto.getMemorySize());
+    final int core = resourceRequestProto.getVirtualCores();
+    LOG.log(Level.FINEST, "Resource requested: memory = {0}, virtual core count = {1}.", new Object[]{memory, core});
+    result.setMemory(memory);
+    result.setVirtualCores(core);
+    return result;
+  }
+
+  private synchronized Priority getPriority(final DriverRuntimeProtocol.ResourceRequestProto resourceRequestProto) {
+    final Priority pri = Records.newRecord(Priority.class);
+    pri.setPriority(resourceRequestProto.hasPriority() ? resourceRequestProto.getPriority() : 1);
+    return pri;
+  }
+
+  private synchronized int getMemory(final int requestedMemory) {
+    final int result;
+    if (!this.registration.isPresent()) {
+      LOG.log(Level.WARNING, "AM doesn't seem to be registered. Proceed with fingers crossed.");
+      result = requestedMemory;
+    } else {
+      final int maxMemory = registration.getRegistration().getMaximumResourceCapability().getMemory();
+      if (requestedMemory > maxMemory) {
+        LOG.log(Level.WARNING, "Asking for {0}MB of memory, but max on this cluster is {1}MB ",
+            new Object[]{requestedMemory, maxMemory});
+        result = maxMemory;
+      } else {
+        result = requestedMemory;
+      }
+    }
+    return result;
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/package-info.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/package-info.java
new file mode 100644
index 0000000..63f621d
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * The Driver-Side implementation of the YARN adapter for REEF.
+ */
+package org.apache.reef.runtime.yarn.driver;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/parameters/JobSubmissionDirectory.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/parameters/JobSubmissionDirectory.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/parameters/JobSubmissionDirectory.java
new file mode 100644
index 0000000..395793d
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/parameters/JobSubmissionDirectory.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.runtime.yarn.driver.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The job submission directory.
+ */
+@NamedParameter(doc = "The job submission directory.")
+public final class JobSubmissionDirectory implements Name<String> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/parameters/YarnHeartbeatPeriod.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/parameters/YarnHeartbeatPeriod.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/parameters/YarnHeartbeatPeriod.java
new file mode 100644
index 0000000..f3f3c65
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/parameters/YarnHeartbeatPeriod.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.runtime.yarn.driver.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * How often we talk to YARN.
+ */
+@NamedParameter(doc = "How often we talk to YARN.", default_value = "1000")
+public final class YarnHeartbeatPeriod implements Name<Integer> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/util/YarnConfigurationConstructor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/util/YarnConfigurationConstructor.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/util/YarnConfigurationConstructor.java
new file mode 100644
index 0000000..c80f9bf
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/util/YarnConfigurationConstructor.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.runtime.yarn.util;
+
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.reef.tang.ExternalConstructor;
+
+import javax.inject.Inject;
+
+/**
+ * An external constructor that creates YarnConfiguration instances.
+ */
+public final class YarnConfigurationConstructor implements ExternalConstructor<YarnConfiguration> {
+  @Inject
+  YarnConfigurationConstructor() {
+  }
+
+  @Override
+  public YarnConfiguration newInstance() {
+    return new YarnConfiguration();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/util/YarnTypes.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/util/YarnTypes.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/util/YarnTypes.java
new file mode 100644
index 0000000..ad60db0
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/util/YarnTypes.java
@@ -0,0 +1,59 @@
+/**
+ * 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.reef.runtime.yarn.util;
+
+import org.apache.hadoop.util.VersionInfo;
+import org.apache.hadoop.yarn.api.records.ContainerLaunchContext;
+import org.apache.hadoop.yarn.api.records.LocalResource;
+import org.apache.hadoop.yarn.util.Records;
+import org.apache.reef.annotations.audience.Private;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Helper class that creates the various records in the YARN API
+ */
+@Private
+public final class YarnTypes {
+
+  private YarnTypes() {
+  }
+
+  /**
+   * @return a ContainerLaunchContext with the given commands and LocalResources.
+   */
+  public static final ContainerLaunchContext getContainerLaunchContext(
+      final List<String> commands, final Map<String, LocalResource> localResources) {
+    final ContainerLaunchContext context = Records.newRecord(ContainerLaunchContext.class);
+    context.setLocalResources(localResources);
+    context.setCommands(commands);
+    return context;
+  }
+
+  public static boolean isAtOrAfterVersion(final String version) {
+    final String hadoopVersion = VersionInfo.getVersion();
+
+    if (hadoopVersion == null || hadoopVersion.length() < version.length()) {
+      throw new RuntimeException("unsupported or incomplete hadoop version number provided for comparison: " + hadoopVersion);
+    }
+
+    return hadoopVersion.substring(0, version.length()).compareTo(version) >= 0;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/test/java/org/apache/reef/runtime/yarn/driver/YarnResourceRequestHandlerTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/test/java/org/apache/reef/runtime/yarn/driver/YarnResourceRequestHandlerTest.java b/lang/java/reef-runtime-yarn/src/main/test/java/org/apache/reef/runtime/yarn/driver/YarnResourceRequestHandlerTest.java
new file mode 100644
index 0000000..0f08b15
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/test/java/org/apache/reef/runtime/yarn/driver/YarnResourceRequestHandlerTest.java
@@ -0,0 +1,127 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+import org.apache.reef.driver.catalog.ResourceCatalog;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.runtime.common.driver.EvaluatorRequestorImpl;
+import org.apache.hadoop.yarn.client.api.AMRMClient;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ * Tests for YarnResourceRequestHandler.
+ */
+public final class YarnResourceRequestHandlerTest {
+  private final ApplicationMasterRegistration applicationMasterRegistration = new ApplicationMasterRegistration();
+  private final MockContainerRequestHandler containerRequestHandler = new MockContainerRequestHandler();
+  private final YarnResourceRequestHandler resourceRequestHandler = new YarnResourceRequestHandler(containerRequestHandler, applicationMasterRegistration);
+  private final ResourceCatalog resourceCatalog = Mockito.mock(ResourceCatalog.class);
+  private final EvaluatorRequestor evaluatorRequestor = new EvaluatorRequestorImpl(resourceCatalog, resourceRequestHandler);
+
+  private class MockContainerRequestHandler implements YarnContainerRequestHandler {
+    private AMRMClient.ContainerRequest[] requests;
+
+    @Override
+    public void onContainerRequest(AMRMClient.ContainerRequest... containerRequests) {
+      this.requests = containerRequests;
+    }
+
+    public AMRMClient.ContainerRequest[] getRequests() {
+      return requests;
+    }
+  }
+
+  /**
+   * Tests whether the amount of memory is transferred correctly.
+   */
+  @Test
+  public void testDifferentMemory() {
+    final EvaluatorRequest requestOne = EvaluatorRequest.newBuilder()
+        .setNumber(1)
+        .setMemory(64)
+        .setNumberOfCores(1)
+        .build();
+    final EvaluatorRequest requestTwo = EvaluatorRequest.newBuilder()
+        .setNumber(1)
+        .setMemory(128)
+        .setNumberOfCores(2)
+        .build();
+    {
+      evaluatorRequestor.submit(requestOne);
+      Assert.assertEquals("Request in REEF and YARN form should have the same amount of memory",
+          requestOne.getMegaBytes(),
+          containerRequestHandler.getRequests()[0].getCapability().getMemory()
+      );
+    }
+    {
+      evaluatorRequestor.submit(requestTwo);
+      Assert.assertEquals("Request in REEF and YARN form should have the same amount of memory",
+          requestTwo.getMegaBytes(),
+          containerRequestHandler.getRequests()[0].getCapability().getMemory()
+      );
+    }
+    {
+      evaluatorRequestor.submit(requestOne);
+      Assert.assertNotEquals("Request in REEF and YARN form should have the same amount of memory",
+          requestTwo.getMegaBytes(),
+          containerRequestHandler.getRequests()[0].getCapability().getMemory()
+      );
+    }
+  }
+
+  @Test
+  public void testEvaluatorCount() {
+    final EvaluatorRequest requestOne = EvaluatorRequest.newBuilder()
+        .setNumber(1)
+        .setMemory(64)
+        .setNumberOfCores(1)
+        .build();
+    final EvaluatorRequest requestTwo = EvaluatorRequest.newBuilder()
+        .setNumber(2)
+        .setMemory(128)
+        .setNumberOfCores(2)
+        .build();
+    {
+      evaluatorRequestor.submit(requestOne);
+      Assert.assertEquals("Request in REEF and YARN form should have the same number of Evaluators",
+          requestOne.getNumber(),
+          containerRequestHandler.getRequests().length
+      );
+    }
+        {
+      evaluatorRequestor.submit(requestTwo);
+      Assert.assertEquals("Request in REEF and YARN form should have the same number of Evaluators",
+          requestTwo.getNumber(),
+          containerRequestHandler.getRequests().length
+      );
+    }
+    {
+      evaluatorRequestor.submit(requestTwo);
+      Assert.assertNotEquals("Request in REEF and YARN form should have the same number of Evaluators",
+          requestOne.getNumber(),
+          containerRequestHandler.getRequests().length
+      );
+    }
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/.gitattributes
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/.gitattributes b/lang/java/reef-tang/.gitattributes
new file mode 100644
index 0000000..db5b15f
--- /dev/null
+++ b/lang/java/reef-tang/.gitattributes
@@ -0,0 +1,3 @@
+# Commit text files using LF endings
+*.java text eol=lf whitespace=trailing-space,space-before-tab,tab-in-indent,blank-at-eof
+* text=auto

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/.gitignore
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/.gitignore b/lang/java/reef-tang/.gitignore
new file mode 100644
index 0000000..7e02bcd
--- /dev/null
+++ b/lang/java/reef-tang/.gitignore
@@ -0,0 +1,15 @@
+tmp
+bin
+tang.conf
+.DS_Store
+target
+generated
+.settings
+.classpath
+.project
+.sw[op]
+*.sw[op]
+.externalToolBuilders
+*~
+*.iml
+.idea


[46/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/JobDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/JobDriver.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/JobDriver.java
new file mode 100644
index 0000000..b2e0083
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/JobDriver.java
@@ -0,0 +1,724 @@
+/**
+ * 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.reef.javabridge.generic;
+
+import org.apache.reef.driver.client.JobMessageObserver;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ClosedContext;
+import org.apache.reef.driver.context.ContextMessage;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.driver.evaluator.*;
+import org.apache.reef.driver.task.*;
+import org.apache.reef.io.network.naming.NameServer;
+import org.apache.reef.javabridge.*;
+import org.apache.reef.runtime.common.DriverRestartCompleted;
+import org.apache.reef.runtime.common.driver.DriverStatusManager;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.util.Optional;
+import org.apache.reef.util.logging.CLRBufferedLogHandler;
+import org.apache.reef.util.logging.LoggingScope;
+import org.apache.reef.util.logging.LoggingScopeFactory;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.NetUtils;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.event.Alarm;
+import org.apache.reef.wake.time.event.StartTime;
+import org.apache.reef.wake.time.event.StopTime;
+import org.apache.reef.webserver.*;
+
+import javax.inject.Inject;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Generic job driver for CLRBridge.
+ */
+@Unit
+public final class JobDriver {
+
+  private static final Logger LOG = Logger.getLogger(JobDriver.class.getName());
+  /**
+   * String codec is used to encode the results
+   * before passing them back to the client.
+   */
+  private static final ObjectSerializableCodec<String> JVM_CODEC = new ObjectSerializableCodec<>();
+  private final InteropLogger interopLogger = new InteropLogger();
+  private final NameServer nameServer;
+  private final String nameServerInfo;
+  private final HttpServer httpServer;
+  /**
+   * Wake clock is used to schedule periodical job check-ups.
+   */
+  private final Clock clock;
+  /**
+   * Job observer on the client.
+   * We use it to send results from the driver back to the client.
+   */
+  private final JobMessageObserver jobMessageObserver;
+  /**
+   * Job driver uses EvaluatorRequestor
+   * to request Evaluators that will run the Tasks.
+   */
+  private final EvaluatorRequestor evaluatorRequestor;
+
+  /**
+   * Driver status manager to monitor driver status
+   */
+  private final DriverStatusManager driverStatusManager;
+
+  /**
+   *  NativeInterop has function to load libs when driver starts
+   */
+  private final LibLoader libLoader;
+
+  /**
+   * Shell execution results from each Evaluator.
+   */
+  private final List<String> results = new ArrayList<>();
+  /**
+   * Map from context ID to running evaluator context.
+   */
+  private final Map<String, ActiveContext> contexts = new HashMap<>();
+
+  /**
+   * Logging scope factory that provides LoggingScope
+   */
+  private final LoggingScopeFactory loggingScopeFactory;
+
+  private long evaluatorRequestorHandler = 0;
+  private long allocatedEvaluatorHandler = 0;
+  private long activeContextHandler = 0;
+  private long taskMessageHandler = 0;
+  private long failedTaskHandler = 0;
+  private long failedEvaluatorHandler = 0;
+  private long httpServerEventHandler = 0;
+  private long completedTaskHandler = 0;
+  private long runningTaskHandler = 0;
+  private long suspendedTaskHandler = 0;
+  private long completedEvaluatorHandler = 0;
+  private long closedContextHandler = 0;
+  private long failedContextHandler = 0;
+  private long contextMessageHandler = 0;
+  private long driverRestartHandler = 0;
+  private long driverRestartActiveContextHandler = 0;
+  private long driverRestartRunningTaskHandler = 0;
+  private boolean clrBridgeSetup = false;
+  private boolean isRestarted = false;
+
+  /**
+   * Job driver constructor.
+   * All parameters are injected from TANG automatically.
+   *
+   * @param clock              Wake clock to schedule and check up running jobs.
+   * @param jobMessageObserver is used to send messages back to the client.
+   * @param evaluatorRequestor is used to request Evaluators.
+   */
+  @Inject
+  JobDriver(final Clock clock,
+            final HttpServer httpServer,
+            final NameServer nameServer,
+            final JobMessageObserver jobMessageObserver,
+            final EvaluatorRequestor evaluatorRequestor,
+            final DriverStatusManager driverStatusManager,
+            final LoggingScopeFactory loggingScopeFactory,
+            final LibLoader libLoader) {
+    this.clock = clock;
+    this.httpServer = httpServer;
+    this.jobMessageObserver = jobMessageObserver;
+    this.evaluatorRequestor = evaluatorRequestor;
+    this.nameServer = nameServer;
+    this.driverStatusManager = driverStatusManager;
+    this.nameServerInfo = NetUtils.getLocalAddress() + ":" + this.nameServer.getPort();
+    this.loggingScopeFactory = loggingScopeFactory;
+    this.libLoader = libLoader;
+  }
+
+  private void setupBridge(final StartTime startTime) {
+    // Signal to the clr buffered log handler that the driver has started and that
+    // we can begin logging
+    LOG.log(Level.INFO, "Initializing CLRBufferedLogHandler...");
+    try (final LoggingScope lb = this.loggingScopeFactory.setupBridge()) {
+
+      try {
+        libLoader.loadLib();
+      } catch (IOException e) {
+        throw new RuntimeException("Fail to load CLR libraries");
+      }
+
+      final CLRBufferedLogHandler handler = getCLRBufferedLogHandler();
+      if (handler == null) {
+        LOG.log(Level.WARNING, "CLRBufferedLogHandler could not be initialized");
+      } else {
+        handler.setDriverInitialized();
+        LOG.log(Level.INFO, "CLRBufferedLogHandler init complete.");
+      }
+
+      LOG.log(Level.INFO, "StartTime: {0}", new Object[]{startTime});
+      String portNumber = httpServer == null ? null : Integer.toString((httpServer.getPort()));
+      long[] handlers = NativeInterop.CallClrSystemOnStartHandler(startTime.toString(), portNumber);
+      if (handlers != null) {
+        if (handlers.length != NativeInterop.nHandlers) {
+          throw new RuntimeException(
+              String.format("%s handlers initialized in CLR while native bridge is expecting %s handlers",
+                  String.valueOf(handlers.length),
+                  String.valueOf(NativeInterop.nHandlers)));
+        }
+        this.evaluatorRequestorHandler = handlers[NativeInterop.Handlers.get(NativeInterop.EvaluatorRequestorKey)];
+        this.allocatedEvaluatorHandler = handlers[NativeInterop.Handlers.get(NativeInterop.AllocatedEvaluatorKey)];
+        this.activeContextHandler = handlers[NativeInterop.Handlers.get(NativeInterop.ActiveContextKey)];
+        this.taskMessageHandler = handlers[NativeInterop.Handlers.get(NativeInterop.TaskMessageKey)];
+        this.failedTaskHandler = handlers[NativeInterop.Handlers.get(NativeInterop.FailedTaskKey)];
+        this.failedEvaluatorHandler = handlers[NativeInterop.Handlers.get(NativeInterop.FailedEvaluatorKey)];
+        this.httpServerEventHandler = handlers[NativeInterop.Handlers.get(NativeInterop.HttpServerKey)];
+        this.completedTaskHandler = handlers[NativeInterop.Handlers.get(NativeInterop.CompletedTaskKey)];
+        this.runningTaskHandler = handlers[NativeInterop.Handlers.get(NativeInterop.RunningTaskKey)];
+        this.suspendedTaskHandler = handlers[NativeInterop.Handlers.get(NativeInterop.SuspendedTaskKey)];
+        this.completedEvaluatorHandler = handlers[NativeInterop.Handlers.get(NativeInterop.CompletedEvaluatorKey)];
+        this.closedContextHandler = handlers[NativeInterop.Handlers.get(NativeInterop.ClosedContextKey)];
+        this.failedContextHandler = handlers[NativeInterop.Handlers.get(NativeInterop.FailedContextKey)];
+        this.contextMessageHandler = handlers[NativeInterop.Handlers.get(NativeInterop.ContextMessageKey)];
+        this.driverRestartHandler = handlers[NativeInterop.Handlers.get(NativeInterop.DriverRestartKey)];
+        this.driverRestartActiveContextHandler = handlers[NativeInterop.Handlers.get(NativeInterop.DriverRestartActiveContextKey)];
+        this.driverRestartRunningTaskHandler = handlers[NativeInterop.Handlers.get(NativeInterop.DriverRestartRunningTaskKey)];
+      }
+
+      try (final LoggingScope lp = this.loggingScopeFactory.getNewLoggingScope("setupBridge::ClrSystemHttpServerHandlerOnNext")) {
+        final HttpServerEventBridge httpServerEventBridge = new HttpServerEventBridge("SPEC");
+        NativeInterop.ClrSystemHttpServerHandlerOnNext(this.httpServerEventHandler, httpServerEventBridge, this.interopLogger);
+        final String specList = httpServerEventBridge.getUriSpecification();
+        LOG.log(Level.INFO, "Starting http server, getUriSpecification: {0}", specList);
+        if (specList != null) {
+          final String[] specs = specList.split(":");
+          for (final String s : specs) {
+            final HttpHandler h = new HttpServerBridgeEventHandler();
+            h.setUriSpecification(s);
+            this.httpServer.addHttpHandler(h);
+          }
+        }
+      }
+      this.clrBridgeSetup = true;
+    }
+    LOG.log(Level.INFO, "CLR Bridge setup.");
+  }
+
+  private CLRBufferedLogHandler getCLRBufferedLogHandler() {
+    for (Handler handler : Logger.getLogger("").getHandlers()) {
+      if (handler instanceof CLRBufferedLogHandler)
+        return (CLRBufferedLogHandler) handler;
+    }
+    return null;
+  }
+
+  private void submitEvaluator(final AllocatedEvaluator eval, EvaluatorType type) {
+    synchronized (JobDriver.this) {
+      eval.setType(type);
+      LOG.log(Level.INFO, "Allocated Evaluator: {0}, total running running {1}",
+          new Object[]{eval.getId(), JobDriver.this.contexts.size()});
+      if (JobDriver.this.allocatedEvaluatorHandler == 0) {
+        throw new RuntimeException("Allocated Evaluator Handler not initialized by CLR.");
+      }
+      AllocatedEvaluatorBridge allocatedEvaluatorBridge = new AllocatedEvaluatorBridge(eval, JobDriver.this.nameServerInfo);
+      NativeInterop.ClrSystemAllocatedEvaluatorHandlerOnNext(JobDriver.this.allocatedEvaluatorHandler, allocatedEvaluatorBridge, this.interopLogger);
+    }
+  }
+
+  /**
+   * Submit a Task to a single Evaluator.
+   */
+  private void submit(final ActiveContext context) {
+    try {
+      LOG.log(Level.INFO, "Send task to context: {0}", new Object[]{context});
+      if (JobDriver.this.activeContextHandler == 0) {
+        throw new RuntimeException("Active Context Handler not initialized by CLR.");
+      }
+      ActiveContextBridge activeContextBridge = new ActiveContextBridge(context);
+      NativeInterop.ClrSystemActiveContextHandlerOnNext(JobDriver.this.activeContextHandler, activeContextBridge, JobDriver.this.interopLogger);
+    } catch (final Exception ex) {
+      LOG.log(Level.SEVERE, "Fail to submit task to active context");
+      context.close();
+      throw new RuntimeException(ex);
+    }
+  }
+
+  /**
+   * Handles AllocatedEvaluator: Submit an empty context
+   */
+  final class AllocatedEvaluatorHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+      try (final LoggingScope ls = loggingScopeFactory.evaluatorAllocated(allocatedEvaluator.getId())) {
+        synchronized (JobDriver.this) {
+          LOG.log(Level.INFO, "AllocatedEvaluatorHandler.OnNext");
+            JobDriver.this.submitEvaluator(allocatedEvaluator, EvaluatorType.CLR);
+        }
+      }
+    }
+  }
+
+  /**
+   * Receive notification that a new Context is available.
+   */
+  final class ActiveContextHandler implements EventHandler<ActiveContext> {
+    @Override
+    public void onNext(final ActiveContext context) {
+      try (final LoggingScope ls = loggingScopeFactory.activeContextReceived(context.getId())) {
+        synchronized (JobDriver.this) {
+          LOG.log(Level.INFO, "ActiveContextHandler: Context available: {0}",
+              new Object[]{context.getId()});
+          JobDriver.this.contexts.put(context.getId(), context);
+          JobDriver.this.submit(context);
+        }
+      }
+    }
+  }
+
+  /**
+   * Receive notification that the Task has completed successfully.
+   */
+  final class CompletedTaskHandler implements EventHandler<CompletedTask> {
+    @Override
+    public void onNext(final CompletedTask task) {
+      LOG.log(Level.INFO, "Completed task: {0}", task.getId());
+      try (final LoggingScope ls = loggingScopeFactory.taskCompleted(task.getId())) {
+        // Take the message returned by the task and add it to the running result.
+        String result = "default result";
+        try {
+          result = new String(task.get());
+        } catch (final Exception e) {
+          LOG.log(Level.WARNING, "failed to decode task outcome");
+        }
+        LOG.log(Level.INFO, "Return results to the client:\n{0}", result);
+        JobDriver.this.jobMessageObserver.sendMessageToClient(JVM_CODEC.encode(result));
+        if (JobDriver.this.completedTaskHandler == 0) {
+          LOG.log(Level.INFO, "No CLR handler bound to handle completed task.");
+        } else {
+          LOG.log(Level.INFO, "CLR CompletedTaskHandler handler set, handling things with CLR handler.");
+          CompletedTaskBridge completedTaskBridge = new CompletedTaskBridge(task);
+          NativeInterop.ClrSystemCompletedTaskHandlerOnNext(JobDriver.this.completedTaskHandler, completedTaskBridge, JobDriver.this.interopLogger);
+        }
+      }
+    }
+  }
+
+  /**
+   * Receive notification that the entire Evaluator had failed.
+   */
+  final class FailedEvaluatorHandler implements EventHandler<FailedEvaluator> {
+    @Override
+    public void onNext(final FailedEvaluator eval) {
+      try (final LoggingScope ls = loggingScopeFactory.evaluatorFailed(eval.getId())) {
+        synchronized (JobDriver.this) {
+          LOG.log(Level.SEVERE, "FailedEvaluator", eval);
+          for (final FailedContext failedContext : eval.getFailedContextList()) {
+            String failedContextId = failedContext.getId();
+            LOG.log(Level.INFO, "removing context " + failedContextId + " from job driver contexts.");
+            JobDriver.this.contexts.remove(failedContextId);
+          }
+          String message = "Evaluator " + eval.getId() + " failed with message: "
+              + eval.getEvaluatorException().getMessage();
+          JobDriver.this.jobMessageObserver.sendMessageToClient(message.getBytes());
+
+          if (failedEvaluatorHandler == 0) {
+            if (JobDriver.this.clrBridgeSetup) {
+              message = "No CLR FailedEvaluator handler was set, exiting now";
+              LOG.log(Level.WARNING, message);
+              JobDriver.this.jobMessageObserver.sendMessageToClient(message.getBytes());
+              return;
+            } else {
+              clock.scheduleAlarm(0, new EventHandler<Alarm>() {
+                @Override
+                public void onNext(final Alarm time) {
+                  if (JobDriver.this.clrBridgeSetup) {
+                    handleFailedEvaluatorInCLR(eval);
+                  } else {
+                    LOG.log(Level.INFO, "Waiting for CLR bridge to be set up");
+                    clock.scheduleAlarm(5000, this);
+                  }
+                }
+              });
+            }
+          } else {
+            handleFailedEvaluatorInCLR(eval);
+          }
+        }
+      }
+    }
+
+    private void handleFailedEvaluatorInCLR(final FailedEvaluator eval) {
+      final String message = "CLR FailedEvaluator handler set, handling things with CLR handler.";
+      LOG.log(Level.INFO, message);
+      FailedEvaluatorBridge failedEvaluatorBridge = new FailedEvaluatorBridge(eval, JobDriver.this.evaluatorRequestor, JobDriver.this.isRestarted, loggingScopeFactory);
+      NativeInterop.ClrSystemFailedEvaluatorHandlerOnNext(JobDriver.this.failedEvaluatorHandler, failedEvaluatorBridge, JobDriver.this.interopLogger);
+      int additionalRequestedEvaluatorNumber = failedEvaluatorBridge.getNewlyRequestedEvaluatorNumber();
+      if (additionalRequestedEvaluatorNumber > 0) {
+        LOG.log(Level.INFO, "number of additional evaluators requested after evaluator failure: " + additionalRequestedEvaluatorNumber);
+      }
+      JobDriver.this.jobMessageObserver.sendMessageToClient(message.getBytes());
+    }
+  }
+
+  final class HttpServerBridgeEventHandler implements HttpHandler {
+    private String uriSpecification;
+
+    /**
+     * returns URI specification for the handler
+     */
+    @Override
+    public String getUriSpecification() {
+      return uriSpecification;
+    }
+
+    public void setUriSpecification(String s) {
+      uriSpecification = s;
+    }
+
+    /**
+     * process http request
+     */
+    @Override
+    public void onHttpRequest(final ParsedHttpRequest parsedHttpRequest, final HttpServletResponse response) throws IOException, ServletException {
+      LOG.log(Level.INFO, "HttpServerBridgeEventHandler onHttpRequest: {0}", parsedHttpRequest.getRequestUri());
+      try (final LoggingScope ls = loggingScopeFactory.httpRequest(parsedHttpRequest.getRequestUri())) {
+        final AvroHttpSerializer httpSerializer = new AvroHttpSerializer();
+        final AvroHttpRequest avroHttpRequest = httpSerializer.toAvro(parsedHttpRequest);
+        final byte[] requestBytes = httpSerializer.toBytes(avroHttpRequest);
+
+        try {
+          final HttpServerEventBridge httpServerEventBridge = new HttpServerEventBridge(requestBytes);
+          NativeInterop.ClrSystemHttpServerHandlerOnNext(JobDriver.this.httpServerEventHandler, httpServerEventBridge, JobDriver.this.interopLogger);
+          final String responseBody = new String(httpServerEventBridge.getQueryResponseData(), "UTF-8");
+          response.getWriter().println(responseBody);
+          LOG.log(Level.INFO, "HttpServerBridgeEventHandler onHttpRequest received response: {0}", responseBody);
+        } catch (final Exception ex) {
+          LOG.log(Level.SEVERE, "Fail to invoke CLR Http Server handler", ex);
+          throw new RuntimeException(ex);
+        }
+      }
+    }
+  }
+
+  /**
+   * Handle failed task.
+   */
+  final class FailedTaskHandler implements EventHandler<FailedTask> {
+    @Override
+    public void onNext(final FailedTask task) throws RuntimeException {
+      LOG.log(Level.SEVERE, "FailedTask received, will be handle in CLR handler, if set.");
+      if (JobDriver.this.failedTaskHandler == 0) {
+        LOG.log(Level.SEVERE, "Failed Task Handler not initialized by CLR, fail for real.");
+        throw new RuntimeException("Failed Task Handler not initialized by CLR.");
+      }
+      try {
+        FailedTaskBridge failedTaskBridge = new FailedTaskBridge(task);
+        NativeInterop.ClrSystemFailedTaskHandlerOnNext(JobDriver.this.failedTaskHandler, failedTaskBridge, JobDriver.this.interopLogger);
+      } catch (final Exception ex) {
+        LOG.log(Level.SEVERE, "Fail to invoke CLR failed task handler");
+        throw new RuntimeException(ex);
+      }
+    }
+  }
+
+  /**
+   * Receive notification that the Task is running.
+   */
+  final class RunningTaskHandler implements EventHandler<RunningTask> {
+    @Override
+    public void onNext(final RunningTask task) {
+      try (final LoggingScope ls = loggingScopeFactory.taskRunning(task.getId())) {
+        if (JobDriver.this.runningTaskHandler == 0) {
+          LOG.log(Level.INFO, "RunningTask event received but no CLR handler was bound. Exiting handler.");
+        } else {
+          LOG.log(Level.INFO, "RunningTask will be handled by CLR handler. Task Id: {0}", task.getId());
+          try {
+            final RunningTaskBridge runningTaskBridge = new RunningTaskBridge(task);
+            NativeInterop.ClrSystemRunningTaskHandlerOnNext(JobDriver.this.runningTaskHandler, runningTaskBridge, JobDriver.this.interopLogger);
+          } catch (final Exception ex) {
+            LOG.log(Level.WARNING, "Fail to invoke CLR running task handler");
+            throw new RuntimeException(ex);
+          }
+        }
+      }
+    }
+  }
+
+  /**
+   * Receive notification that the Task is running when driver restarted.
+   */
+  final class DriverRestartRunningTaskHandler implements EventHandler<RunningTask> {
+    @Override
+    public void onNext(final RunningTask task) {
+      try (final LoggingScope ls = loggingScopeFactory.driverRestartRunningTask(task.getId())) {
+        clock.scheduleAlarm(0, new EventHandler<Alarm>() {
+          @Override
+          public void onNext(final Alarm time) {
+            if (JobDriver.this.clrBridgeSetup) {
+              if (JobDriver.this.driverRestartRunningTaskHandler != 0) {
+                LOG.log(Level.INFO, "CLR driver restart RunningTask handler implemented, now handle it in CLR.");
+                NativeInterop.ClrSystemDriverRestartRunningTaskHandlerOnNext(JobDriver.this.driverRestartRunningTaskHandler, new RunningTaskBridge(task));
+              } else {
+                LOG.log(Level.WARNING, "No CLR driver restart RunningTask handler implemented, done with DriverRestartRunningTaskHandler.");
+              }
+            } else {
+              LOG.log(Level.INFO, "Waiting for driver to complete restart process before checking out CLR driver restart RunningTaskHandler...");
+              clock.scheduleAlarm(2000, this);
+            }
+          }
+        });
+      }
+    }
+  }
+
+  /**
+   * Receive notification that an context is active on Evaluator when the driver restarted
+   */
+  final class DriverRestartActiveContextHandler implements EventHandler<ActiveContext> {
+    @Override
+    public void onNext(final ActiveContext context) {
+      try (final LoggingScope ls = loggingScopeFactory.driverRestartActiveContextReceived(context.getId())) {
+        JobDriver.this.contexts.put(context.getId(), context);
+      LOG.log(Level.INFO, "DriverRestartActiveContextHandler event received: " + context.getId());
+        clock.scheduleAlarm(0, new EventHandler<Alarm>() {
+          @Override
+          public void onNext(final Alarm time) {
+            if (JobDriver.this.clrBridgeSetup) {
+              if (JobDriver.this.driverRestartActiveContextHandler != 0) {
+                LOG.log(Level.INFO, "CLR driver restart ActiveContext handler implemented, now handle it in CLR.");
+                NativeInterop.ClrSystemDriverRestartActiveContextHandlerOnNext(JobDriver.this.driverRestartActiveContextHandler, new ActiveContextBridge(context));
+              } else {
+                LOG.log(Level.WARNING, "No CLR driver restart ActiveContext handler implemented, done with DriverRestartActiveContextHandler.");
+              }
+            } else {
+              LOG.log(Level.INFO, "Waiting for driver to complete restart process before checking out CLR driver restart DriverRestartActiveContextHandler...");
+              clock.scheduleAlarm(2000, this);
+            }
+          }
+        });
+      }
+    }
+  }
+
+  /**
+   * Job Driver is ready and the clock is set up: request the evaluators.
+   */
+  final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime startTime) {
+      try (final LoggingScope ls = loggingScopeFactory.driverStart(startTime)) {
+        synchronized (JobDriver.this) {
+
+          setupBridge(startTime);
+
+          LOG.log(Level.INFO, "Driver Started");
+
+          if (JobDriver.this.evaluatorRequestorHandler == 0) {
+            throw new RuntimeException("Evaluator Requestor Handler not initialized by CLR.");
+          }
+          EvaluatorRequestorBridge evaluatorRequestorBridge = new EvaluatorRequestorBridge(JobDriver.this.evaluatorRequestor, false, loggingScopeFactory);
+          NativeInterop.ClrSystemEvaluatorRequstorHandlerOnNext(JobDriver.this.evaluatorRequestorHandler, evaluatorRequestorBridge, JobDriver.this.interopLogger);
+          // get the evaluator numbers set by CLR handler
+          LOG.log(Level.INFO, "evaluator requested at start up: " + evaluatorRequestorBridge.getEvaluatorNumber());
+        }
+      }
+    }
+  }
+
+
+  /**
+   * Job driver is restarted after previous crash
+   */
+  final class RestartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime startTime) {
+      try (final LoggingScope ls = loggingScopeFactory.driverRestart(startTime)) {
+        synchronized (JobDriver.this) {
+
+          setupBridge(startTime);
+
+          JobDriver.this.isRestarted = true;
+
+          LOG.log(Level.INFO, "Driver Restarted and CLR bridge set up.");
+        }
+      }
+    }
+  }
+
+  /**
+   * Receive notification that driver restart has completed.
+   */
+  final class DriverRestartCompletedHandler implements EventHandler<DriverRestartCompleted> {
+    @Override
+    public void onNext(final DriverRestartCompleted driverRestartCompleted) {
+      LOG.log(Level.INFO, "Java DriverRestartCompleted event received at time [{0}]. ", driverRestartCompleted.getTimeStamp());
+      try (final LoggingScope ls = loggingScopeFactory.driverRestartCompleted(driverRestartCompleted.getTimeStamp())) {
+        if (JobDriver.this.driverRestartHandler != 0) {
+          LOG.log(Level.INFO, "CLR driver restart handler implemented, now handle it in CLR.");
+          NativeInterop.ClrSystemDriverRestartHandlerOnNext(JobDriver.this.driverRestartHandler);
+        } else {
+          LOG.log(Level.WARNING, "No CLR driver restart handler implemented, done with DriverRestartCompletedHandler.");
+
+        }
+      }
+    }
+  }
+
+  /**
+   * Shutting down the job driver: close the evaluators.
+   */
+  final class StopHandler implements EventHandler<StopTime> {
+    @Override
+    public void onNext(final StopTime time) {
+      LOG.log(Level.INFO, " StopTime: {0}", new Object[]{time});
+      try (final LoggingScope ls = loggingScopeFactory.driverStop(time.getTimeStamp())) {
+        for (final ActiveContext context : contexts.values()) {
+          context.close();
+        }
+      }
+    }
+  }
+
+  final class TaskMessageHandler implements EventHandler<TaskMessage> {
+    @Override
+    public void onNext(final TaskMessage taskMessage) {
+      String msg = new String(taskMessage.get());
+      LOG.log(Level.INFO, "Received TaskMessage: {0} from CLR", msg);
+      //try (LoggingScope ls = loggingScopeFactory.taskMessageReceived(new String(msg))) {
+      if (JobDriver.this.taskMessageHandler != 0) {
+        TaskMessageBridge taskMessageBridge = new TaskMessageBridge(taskMessage);
+        // if CLR implements the task message handler, handle the bytes in CLR handler
+        NativeInterop.ClrSystemTaskMessageHandlerOnNext(JobDriver.this.taskMessageHandler, taskMessage.get(), taskMessageBridge, JobDriver.this.interopLogger);
+      }
+      //}
+    }
+  }
+
+  /**
+   * Receive notification that the Task has been suspended.
+   */
+  final class SuspendedTaskHandler implements EventHandler<SuspendedTask> {
+    @Override
+    public final void onNext(final SuspendedTask task) {
+      final String message = "Received notification that task [" + task.getId() + "] has been suspended.";
+      LOG.log(Level.INFO, message);
+      try (final LoggingScope ls = loggingScopeFactory.taskSuspended(task.getId())) {
+        if (JobDriver.this.suspendedTaskHandler != 0) {
+          SuspendedTaskBridge suspendedTaskBridge = new SuspendedTaskBridge(task);
+          // if CLR implements the suspended task handler, handle it in CLR
+          LOG.log(Level.INFO, "Handling the event of suspended task in CLR bridge.");
+          NativeInterop.ClrSystemSupendedTaskHandlerOnNext(JobDriver.this.suspendedTaskHandler, suspendedTaskBridge);
+        }
+        JobDriver.this.jobMessageObserver.sendMessageToClient(JVM_CODEC.encode(message));
+      }
+    }
+  }
+
+  /**
+   * Receive notification that the Evaluator has been shut down.
+   */
+  final class CompletedEvaluatorHandler implements EventHandler<CompletedEvaluator> {
+    @Override
+    public void onNext(final CompletedEvaluator evaluator) {
+      LOG.log(Level.INFO, " Completed Evaluator {0}", evaluator.getId());
+      try (final LoggingScope ls = loggingScopeFactory.evaluatorCompleted(evaluator.getId())) {
+        if (JobDriver.this.completedEvaluatorHandler != 0) {
+          CompletedEvaluatorBridge completedEvaluatorBridge = new CompletedEvaluatorBridge(evaluator);
+          // if CLR implements the completed evaluator handler, handle it in CLR
+          LOG.log(Level.INFO, "Handling the event of completed evaluator in CLR bridge.");
+          NativeInterop.ClrSystemCompletdEvaluatorHandlerOnNext(completedEvaluatorHandler, completedEvaluatorBridge);
+        }
+      }
+    }
+  }
+
+
+  /**
+   * Receive notification that the Context had completed.
+   * Remove context from the list of active context.
+   */
+  final class ClosedContextHandler implements EventHandler<ClosedContext> {
+    @Override
+    public void onNext(final ClosedContext context) {
+      LOG.log(Level.INFO, "Completed Context: {0}", context.getId());
+      try (final LoggingScope ls = loggingScopeFactory.closedContext(context.getId())) {
+        if (JobDriver.this.closedContextHandler != 0) {
+          ClosedContextBridge closedContextBridge = new ClosedContextBridge(context);
+          // if CLR implements the closed context handler, handle it in CLR
+          LOG.log(Level.INFO, "Handling the event of closed context in CLR bridge.");
+          NativeInterop.ClrSystemClosedContextHandlerOnNext(JobDriver.this.closedContextHandler, closedContextBridge);
+        }
+        synchronized (JobDriver.this) {
+          JobDriver.this.contexts.remove(context.getId());
+        }
+      }
+    }
+  }
+
+
+  /**
+   * Receive notification that the Context had failed.
+   * Remove context from the list of active context and notify the client.
+   */
+  final class FailedContextHandler implements EventHandler<FailedContext> {
+    @Override
+    public void onNext(final FailedContext context) {
+      LOG.log(Level.SEVERE, "FailedContext", context);
+      try (final LoggingScope ls = loggingScopeFactory.evaluatorFailed(context.getId())) {
+        if (JobDriver.this.failedContextHandler != 0) {
+          FailedContextBridge failedContextBridge = new FailedContextBridge(context);
+          // if CLR implements the failed context handler, handle it in CLR
+          LOG.log(Level.INFO, "Handling the event of failed context in CLR bridge.");
+          NativeInterop.ClrSystemFailedContextHandlerOnNext(JobDriver.this.failedContextHandler, failedContextBridge);
+        }
+        synchronized (JobDriver.this) {
+          JobDriver.this.contexts.remove(context.getId());
+        }
+        Optional<byte[]> err = context.getData();
+        if (err.isPresent()) {
+          JobDriver.this.jobMessageObserver.sendMessageToClient(err.get());
+        }
+      }
+    }
+  }
+
+  /**
+   * Receive notification that a ContextMessage has been received
+   */
+  final class ContextMessageHandler implements EventHandler<ContextMessage> {
+    @Override
+    public void onNext(final ContextMessage message) {
+      LOG.log(Level.SEVERE, "Received ContextMessage:", message.get());
+      try (final LoggingScope ls = loggingScopeFactory.contextMessageReceived(message.get().toString())) {
+        if (JobDriver.this.contextMessageHandler != 0) {
+          ContextMessageBridge contextMessageBridge = new ContextMessageBridge(message);
+          // if CLR implements the context message handler, handle it in CLR
+          LOG.log(Level.INFO, "Handling the event of context message in CLR bridge.");
+          NativeInterop.ClrSystemContextMessageHandlerOnNext(JobDriver.this.contextMessageHandler, contextMessageBridge);
+        }
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/Launch.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/Launch.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/Launch.java
new file mode 100644
index 0000000..b1473ee
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/Launch.java
@@ -0,0 +1,236 @@
+/**
+ * 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.reef.javabridge.generic;
+
+import org.apache.reef.client.ClientConfiguration;
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.runtime.yarn.client.YarnClientConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.CommandLine;
+import org.apache.reef.util.logging.LoggingScope;
+import org.apache.reef.util.logging.LoggingScopeFactory;
+import org.apache.reef.util.logging.LoggingScopeImpl;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Clr Bridge example - main class.
+ */
+public final class Launch {
+
+  /**
+   * Number of REEF worker threads in local mode. We assume maximum 10 evaluators can be requested on local runtime
+   */
+  private static final int NUM_LOCAL_THREADS = 10;
+  /**
+   * Standard Java logger
+   */
+  private static final Logger LOG = Logger.getLogger(Launch.class.getName());
+
+  /**
+   * This class should not be instantiated.
+   */
+  private Launch() {
+    throw new RuntimeException("Do not instantiate this class!");
+  }
+
+  /**
+   * Parse the command line arguments.
+   *
+   * @param args command line arguments, as passed to main()
+   * @return Configuration object.
+   * @throws org.apache.reef.tang.exceptions.BindException configuration error.
+   * @throws java.io.IOException                           error reading the configuration.
+   */
+  private static Configuration parseCommandLine(final String[] args)
+      throws BindException, IOException {
+    final JavaConfigurationBuilder confBuilder = Tang.Factory.getTang().newConfigurationBuilder();
+    final CommandLine cl = new CommandLine(confBuilder);
+    cl.registerShortNameOfClass(Local.class);
+    cl.registerShortNameOfClass(NumRuns.class);
+    cl.registerShortNameOfClass(WaitTimeForDriver.class);
+    cl.registerShortNameOfClass(DriverMemoryInMb.class);
+    cl.registerShortNameOfClass(DriverIdentifier.class);
+    cl.registerShortNameOfClass(DriverJobSubmissionDirectory.class);
+    cl.registerShortNameOfClass(Submit.class);
+    cl.processCommandLine(args);
+    return confBuilder.build();
+  }
+
+  private static Configuration cloneCommandLineConfiguration(final Configuration commandLineConf)
+      throws InjectionException, BindException {
+    final Injector injector = Tang.Factory.getTang().newInjector(commandLineConf);
+    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindNamedParameter(NumRuns.class, String.valueOf(injector.getNamedInstance(NumRuns.class)));
+    return cb.build();
+  }
+
+  /**
+   * Parse command line arguments and create TANG configuration ready to be submitted to REEF.
+   *
+   * @param args Command line arguments, as passed into main().
+   * @return (immutable) TANG Configuration object.
+   * @throws org.apache.reef.tang.exceptions.BindException      if configuration commandLineInjector fails.
+   * @throws org.apache.reef.tang.exceptions.InjectionException if configuration commandLineInjector fails.
+   * @throws java.io.IOException                                error reading the configuration.
+   */
+  private static Configuration getClientConfiguration(final String[] args)
+      throws BindException, InjectionException, IOException {
+
+    try (final LoggingScope ls = LoggingScopeFactory.getNewLoggingScope(Level.INFO, "Launch::getClientConfiguration")) {
+      final Configuration commandLineConf = parseCommandLine(args);
+
+      final Configuration clientConfiguration = ClientConfiguration.CONF
+          .set(ClientConfiguration.ON_JOB_COMPLETED, JobClient.CompletedJobHandler.class)
+          .set(ClientConfiguration.ON_JOB_FAILED, JobClient.FailedJobHandler.class)
+          .set(ClientConfiguration.ON_RUNTIME_ERROR, JobClient.RuntimeErrorHandler.class)
+          //.set(ClientConfiguration.ON_WAKE_ERROR, JobClient.WakeErrorHandler.class )
+          .build();
+
+      // TODO: Remove the injector, have stuff injected.
+      final Injector commandLineInjector = Tang.Factory.getTang().newInjector(commandLineConf);
+      final boolean isLocal = commandLineInjector.getNamedInstance(Local.class);
+      final Configuration runtimeConfiguration;
+      if (isLocal) {
+        LOG.log(Level.INFO, "Running on the local runtime");
+        runtimeConfiguration = LocalRuntimeConfiguration.CONF
+            .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, NUM_LOCAL_THREADS)
+            .build();
+      } else {
+        LOG.log(Level.INFO, "Running on YARN");
+        runtimeConfiguration = YarnClientConfiguration.CONF.build();
+      }
+
+      return Tang.Factory.getTang()
+          .newConfigurationBuilder(runtimeConfiguration, clientConfiguration,
+              cloneCommandLineConfiguration(commandLineConf))
+          .build();
+    }
+  }
+
+  /**
+   * Main method that starts the CLR Bridge from Java
+   *
+   * @param args command line parameters.
+   */
+  public static void main(final String[] args) {
+    LOG.log(Level.INFO, "Entering Launch at :::" + new Date());
+    try {
+      if (args == null || args.length == 0) {
+        throw new IllegalArgumentException("No arguments provided, at least a clrFolder should be supplied.");
+      }
+      final File dotNetFolder = new File(args[0]).getAbsoluteFile();
+      String[] removedArgs = Arrays.copyOfRange(args, 1, args.length);
+
+      final Configuration config = getClientConfiguration(removedArgs);
+      final Injector commandLineInjector = Tang.Factory.getTang().newInjector(parseCommandLine(removedArgs));
+      final int waitTime = commandLineInjector.getNamedInstance(WaitTimeForDriver.class);
+      final int driverMemory = commandLineInjector.getNamedInstance(DriverMemoryInMb.class);
+      final String driverIdentifier = commandLineInjector.getNamedInstance(DriverIdentifier.class);
+      final String jobSubmissionDirectory = commandLineInjector.getNamedInstance(DriverJobSubmissionDirectory.class);
+      final boolean submit = commandLineInjector.getNamedInstance(Submit.class);
+      final Injector injector = Tang.Factory.getTang().newInjector(config);
+      final JobClient client = injector.getInstance(JobClient.class);
+      client.setDriverInfo(driverIdentifier, driverMemory, jobSubmissionDirectory);
+
+      if (submit) {
+        client.submit(dotNetFolder, true, null);
+        client.waitForCompletion(waitTime);
+      } else {
+        client.submit(dotNetFolder, false, config);
+        client.waitForCompletion(0);
+      }
+
+
+      LOG.info("Done!");
+    } catch (final BindException | InjectionException | IOException ex) {
+      LOG.log(Level.SEVERE, "Job configuration error", ex);
+    }
+  }
+
+  /**
+   * Command line parameter: number of experiments to run.
+   */
+  @NamedParameter(doc = "Number of times to run the command",
+      short_name = "num_runs", default_value = "1")
+  public static final class NumRuns implements Name<Integer> {
+  }
+
+  /**
+   * Command line parameter = true to run locally, or false to run on YARN.
+   */
+  @NamedParameter(doc = "Whether or not to run on the local runtime",
+      short_name = "local", default_value = "true")
+  public static final class Local implements Name<Boolean> {
+  }
+
+  /**
+   * Command line parameter, number of seconds  to wait till driver finishes ,
+   * = -1 : waits forever
+   * = 0: exit immediately without wait for driver.
+   */
+  @NamedParameter(doc = "Whether or not to wait for driver to finish",
+      short_name = "wait_time", default_value = "-1")
+  public static final class WaitTimeForDriver implements Name<Integer> {
+  }
+
+  /**
+   * Command line parameter, driver memory, in MB
+   */
+  @NamedParameter(doc = "memory allocated to driver JVM",
+      short_name = "driver_memory", default_value = "512")
+  public static final class DriverMemoryInMb implements Name<Integer> {
+  }
+
+  /**
+   * Command line parameter, driver identifier
+   */
+  @NamedParameter(doc = "driver identifier for clr bridge",
+      short_name = "driver_id", default_value = "ReefClrBridge")
+  public static final class DriverIdentifier implements Name<String> {
+  }
+
+  /**
+   * Command line parameter = true to submit the job with driver config, or false to write config to current directory
+   */
+  @NamedParameter(doc = "Whether or not to submit the reef job after driver config is constructed",
+      short_name = "submit", default_value = "true")
+  public static final class Submit implements Name<Boolean> {
+  }
+
+  /**
+   * Command line parameter, job submission directory, if set, user should guarantee its uniqueness
+   */
+  @NamedParameter(doc = "driver job submission directory",
+      short_name = "submission_directory", default_value = "empty")
+  public static final class DriverJobSubmissionDirectory implements Name<String> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/LaunchHeadless.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/LaunchHeadless.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/LaunchHeadless.java
new file mode 100644
index 0000000..ba2a5cb
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/LaunchHeadless.java
@@ -0,0 +1,100 @@
+/**
+ * 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.reef.javabridge.generic;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.REEF;
+import org.apache.reef.runtime.common.client.REEFImplementation;
+import org.apache.reef.runtime.yarn.client.YarnClientConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Configurations;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.ConfigurationModule;
+
+import java.io.File;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Clr Bridge example - main class.
+ */
+public final class LaunchHeadless {
+
+  /**
+   * Standard Java logger
+   */
+  private static final Logger LOG = Logger.getLogger(LaunchHeadless.class.getName());
+
+  /**
+   * This class should not be instantiated.
+   */
+  private LaunchHeadless() {
+    throw new RuntimeException("Do not instantiate this class!");
+  }
+
+
+  /**
+   * Parse command line arguments and create TANG configuration ready to be submitted to REEF.
+   *
+   * @param args Command line arguments, as passed into main().
+   * @return (immutable) TANG Configuration object.
+   * @throws org.apache.reef.tang.exceptions.BindException      if configuration commandLineInjector fails.
+   * @throws org.apache.reef.tang.exceptions.InjectionException if configuration commandLineInjector fails.
+   * @throws java.io.IOException        error reading the configuration.
+   */
+
+  /**
+   * Main method that starts the CLR Bridge from Java
+   *
+   * @param args command line parameters.
+   */
+  public static void main(final String[] args) {
+    try {
+      if (args == null || args.length == 0) {
+        throw new IllegalArgumentException("No arguments provided, at least a clrFolder should be supplied.");
+      }
+      final File dotNetFolder = new File(args[0]).getAbsoluteFile();
+
+      ConfigurationModule driverConfigModule = JobClient.getDriverConfiguration();
+
+      ConfigurationModule result = driverConfigModule;
+      for (final File f : dotNetFolder.listFiles()) {
+        if (f.canRead() && f.exists() && f.isFile()) {
+          result = result.set(DriverConfiguration.GLOBAL_FILES, f.getAbsolutePath());
+        }
+      }
+
+      driverConfigModule = result;
+      Configuration driverConfiguration = Configurations.merge(driverConfigModule.build(), JobClient.getHTTPConfiguration());
+
+      LOG.log(Level.INFO, "Running on YARN");
+
+      final Configuration runtimeConfiguration = YarnClientConfiguration.CONF.build();
+
+      final REEF reef = Tang.Factory.getTang().newInjector(runtimeConfiguration).getInstance(REEFImplementation.class);
+      reef.submit(driverConfiguration);
+
+      LOG.info("Done!");
+    } catch (final BindException | InjectionException ex) {
+      LOG.log(Level.SEVERE, "Job configuration error", ex);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/package-info.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/package-info.java
new file mode 100644
index 0000000..d93f6f4
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/javabridge/generic/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Generic java bridge driver/client
+ */
+package org.apache.reef.javabridge.generic;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/util/logging/CLRBufferedLogHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/util/logging/CLRBufferedLogHandler.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/util/logging/CLRBufferedLogHandler.java
new file mode 100644
index 0000000..46629c9
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/util/logging/CLRBufferedLogHandler.java
@@ -0,0 +1,167 @@
+/**
+ * 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.reef.util.logging;
+
+import org.apache.reef.javabridge.NativeInterop;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.SimpleFormatter;
+
+/**
+ * Logging Handler to intercept java logs and transfer them
+ * to the CLR side via the reef-bridge.
+ * <p/>
+ * Logs are buffered to avoid the cost of reef-bridge function calls.
+ * A thread is also scheduled to flush the log buffer at a certain interval,
+ * in case the log buffer remains unfilled for an extended period of time.
+ */
+public class CLRBufferedLogHandler extends Handler {
+  private static final int BUFFER_LEN = 10;
+  private static final int NUM_THREADS = 1;
+  private static final long LOG_SCHEDULE_PERIOD = 15;  // seconds
+  private SimpleFormatter formatter;
+  private ArrayList<LogRecord> logs;
+  private boolean driverInitialized;
+  private ScheduledThreadPoolExecutor logScheduler;
+
+  @Inject
+  public CLRBufferedLogHandler() {
+    super();
+    this.formatter = new SimpleFormatter();
+    this.logs = new ArrayList<LogRecord>();
+    this.driverInitialized = false;
+    this.logScheduler = new ScheduledThreadPoolExecutor(NUM_THREADS);
+  }
+
+  /**
+   * Signals the java-bridge has been initialized and that we can begin logging.
+   * Usually called from the StartHandler after the driver is up.
+   */
+  public void setDriverInitialized() {
+    synchronized (this) {
+      this.driverInitialized = true;
+    }
+    startLogScheduler();
+  }
+
+  /**
+   * Called whenever a log message is received on the java side.
+   * <p/>
+   * Adds the log record to the log buffer. If the log buffer is full and
+   * the driver has already been initialized, flush the buffer of the logs.
+   */
+  @Override
+  public void publish(LogRecord record) {
+    if (record == null)
+      return;
+
+    if (!isLoggable(record))
+      return;
+
+    synchronized (this) {
+      this.logs.add(record);
+      if (!this.driverInitialized || this.logs.size() < BUFFER_LEN)
+        return;
+    }
+
+    logAll();
+  }
+
+  @Override
+  public void flush() {
+    logAll();
+  }
+
+  /**
+   * Flushes the remaining buffered logs and shuts down the log scheduler thread.
+   */
+  @Override
+  public synchronized void close() throws SecurityException {
+    if (driverInitialized) {
+      this.logAll();
+    }
+    this.logScheduler.shutdown();
+  }
+
+  /**
+   * Starts a thread to flush the log buffer on an interval.
+   * <p/>
+   * This will ensure that logs get flushed periodically, even
+   * if the log buffer is not full.
+   */
+  private void startLogScheduler() {
+    this.logScheduler.scheduleAtFixedRate(
+        new Runnable() {
+          @Override
+          public void run() {
+            CLRBufferedLogHandler.this.logAll();
+          }
+        }, 0, LOG_SCHEDULE_PERIOD, TimeUnit.SECONDS);
+  }
+
+  /**
+   * Flushes the log buffer, logging each buffered log message using
+   * the reef-bridge log function.
+   */
+  private void logAll() {
+    synchronized (this) {
+      final StringBuilder sb = new StringBuilder();
+      Level highestLevel = Level.FINEST;
+      for (final LogRecord record : this.logs) {
+        sb.append(formatter.format(record));
+        sb.append("\n");
+        if (record.getLevel().intValue() > highestLevel.intValue()) {
+          highestLevel = record.getLevel();
+        }
+      }
+      try {
+        final int level = getLevel(highestLevel);
+        NativeInterop.ClrBufferedLog(level, sb.toString());
+      } catch (Exception e) {
+        System.err.println("Failed to perform CLRBufferedLogHandler");
+      }
+
+      this.logs.clear();
+    }
+  }
+
+  /**
+   * Returns the integer value of the log record's level to be used
+   * by the CLR Bridge log function.
+   */
+  private int getLevel(Level recordLevel) {
+    if (recordLevel.equals(Level.OFF)) {
+      return 0;
+    } else if (recordLevel.equals(Level.SEVERE)) {
+      return 1;
+    } else if (recordLevel.equals(Level.WARNING)) {
+      return 2;
+    } else if (recordLevel.equals(Level.ALL)) {
+      return 4;
+    } else {
+      return 3;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/util/logging/CLRLoggingConfig.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/util/logging/CLRLoggingConfig.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/util/logging/CLRLoggingConfig.java
new file mode 100644
index 0000000..7d82937
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/util/logging/CLRLoggingConfig.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.util.logging;
+
+import java.io.IOException;
+import java.util.logging.LogManager;
+
+public final class CLRLoggingConfig {
+
+  public CLRLoggingConfig() throws IOException {
+    LogManager.getLogManager().readConfiguration(
+        Thread.currentThread().getContextClassLoader()
+            .getResourceAsStream("com/microsoft/reef/clr.logging.properties"));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/util/logging/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/util/logging/package-info.java b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/util/logging/package-info.java
new file mode 100644
index 0000000..e0e79ce
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/java/org/apache/reef/util/logging/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Logging handler for clr bridge
+ */
+package org.apache.reef.util.logging;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-java/src/main/resources/org/apache/reef/clr.logging.properties
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-java/src/main/resources/org/apache/reef/clr.logging.properties b/lang/java/reef-bridge-project/reef-bridge-java/src/main/resources/org/apache/reef/clr.logging.properties
new file mode 100644
index 0000000..41c4024
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-java/src/main/resources/org/apache/reef/clr.logging.properties
@@ -0,0 +1,82 @@
+#
+# 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.
+#
+
+# Properties file which configures the operation of the JDK
+# logging facility.
+
+# The system will look for this config file, first using
+# a System property specified at startup:
+#
+# >java -Djava.utils.logging.config.file=myLoggingConfigFilePath
+#
+# If this property is not specified, then the config file is
+# retrieved from its default location at:
+#
+# JDK_HOME/jre/lib/logging.properties
+
+# Global logging properties.
+# ------------------------------------------
+# The set of handlers to be loaded upon startup.
+# Comma-separated list of class names.
+# (? LogManager docs say no comma here, but JDK example has comma.)
+# handlers=java.utils.logging.FileHandler, java.utils.logging.ConsoleHandler
+handlers=java.util.logging.ConsoleHandler,org.apache.reef.util.logging.CLRBufferedLogHandler
+
+java.util.logging.SimpleFormatter.format=%1$tF %1$tT,%1$tL %4$s %2$s - %5$s%6$s%n
+
+# Default global logging level.
+# Loggers and Handlers may override this level
+.level=ALL
+
+# Loggers
+# ------------------------------------------
+# Loggers are usually attached to packages.
+# Here, the level for each package is specified.
+# The global level is used by default, so levels
+# specified here simply act as an override.
+
+# org.apache.reef.examples.level=FINEST
+# org.apache.reef.tang.level=INFO
+
+# Handlers
+# -----------------------------------------
+
+# --- ConsoleHandler ---
+# Override of global logging level
+java.util.logging.ConsoleHandler.level=FINEST
+java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
+
+# --- FileHandler ---
+# Override of global logging level
+java.util.logging.FileHandler.level=FINEST
+
+# Naming style for the output file:
+# (The output file is placed in the directory
+# defined by the "user.home" System property.)
+java.util.logging.FileHandler.pattern=%h/reef.%u.log
+
+# Limiting size of output file in bytes:
+java.util.logging.FileHandler.limit=512000
+
+# Number of output files to cycle through, by appending an
+# integer to the base file name:
+java.util.logging.FileHandler.count=100
+
+# Style of output (Simple or XML):
+java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge/pom.xml b/lang/java/reef-bridge-project/reef-bridge/pom.xml
new file mode 100644
index 0000000..774e5f8
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge/pom.xml
@@ -0,0 +1,111 @@
+<?xml version="1.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.
+-->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+         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>
+    <artifactId>reef-bridge</artifactId>
+    <name>REEF Bridge</name>
+    <description>Bridge between JVM and CLR.</description>
+
+
+    <parent>
+        <groupId>org.apache.reef</groupId>
+        <artifactId>reef-bridge-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-local</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-yarn</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-io</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-checkpoint</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-bridge-java</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-bridge-clr</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>unpack-dependencies</id>
+                        <phase>process-resources</phase>
+                        <goals>
+                            <goal>unpack-dependencies</goal>
+                        </goals>
+
+                        <configuration>
+                            <includeArtifactIds>reef-bridge-java,reef-bridge-clr</includeArtifactIds>
+                            <outputDirectory>
+                                ${project.build.directory}/classes/ReefDriverAppDlls
+                            </outputDirectory>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <plugin>
+                <artifactId>maven-jar-plugin</artifactId>
+                <configuration>
+                    <archive>
+                        <manifest>
+                            <addClasspath>false</addClasspath>
+                            <classpathPrefix>lib/</classpathPrefix>
+                            <mainClass>org.apache.reef.javabridge.JavaBridge</mainClass>
+                        </manifest>
+                    </archive>
+                </configuration>
+            </plugin>
+
+        </plugins>
+    </build>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-checkpoint/maven-eclipse.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-checkpoint/maven-eclipse.xml b/lang/java/reef-checkpoint/maven-eclipse.xml
new file mode 100644
index 0000000..6c6b5ae
--- /dev/null
+++ b/lang/java/reef-checkpoint/maven-eclipse.xml
@@ -0,0 +1,28 @@
+<!--
+
+    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 default="copy-resources">
+  <target name="init"/>
+  <target name="copy-resources" depends="init">
+    <copy todir="target/classes/META-INF/conf" filtering="false">
+      <fileset dir="src/main/conf" includes="*.xml|*.properties" excludes="**/*.java"/>
+    </copy>
+  </target>
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-checkpoint/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-checkpoint/pom.xml b/lang/java/reef-checkpoint/pom.xml
new file mode 100644
index 0000000..147a158
--- /dev/null
+++ b/lang/java/reef-checkpoint/pom.xml
@@ -0,0 +1,68 @@
+<?xml version="1.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.
+-->
+<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.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+    <artifactId>reef-checkpoint</artifactId>
+    <name>REEF Checkpoint</name>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <test.build.webapps>${project.build.directory}/test-classes/webapps</test.build.webapps>
+    </properties>
+    <build>
+        <resources>
+            <resource>
+                <targetPath>META-INF/conf</targetPath>
+                <filtering>false</filtering>
+                <directory>${basedir}/src/main/conf</directory>
+                <includes>
+                    <include>*.xml</include>
+                    <include>*.properties</include>
+                    <include>webapps/**</include>
+                </includes>
+                <excludes>
+                </excludes>
+            </resource>
+        </resources>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-common</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-annotations</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>tang</artifactId>
+        </dependency>
+    </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/CheckpointID.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/CheckpointID.java b/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/CheckpointID.java
new file mode 100644
index 0000000..cd7cabe
--- /dev/null
+++ b/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/CheckpointID.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.io.checkpoint;
+
+import org.apache.hadoop.io.Writable;
+
+/**
+ * This class represent the identified (memento) for a checkpoint. It is allowed
+ * to contain small amount of metadata about a checkpoint and must provide sufficient
+ * information to the corresponding CheckpointService to locate and retrieve the
+ * data contained in the checkpoint.
+ */
+public interface CheckpointID extends Writable {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/CheckpointNamingService.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/CheckpointNamingService.java b/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/CheckpointNamingService.java
new file mode 100644
index 0000000..4415c46
--- /dev/null
+++ b/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/CheckpointNamingService.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.io.checkpoint;
+
+/**
+ * This class represent a naming service for checkpoints.
+ */
+public interface CheckpointNamingService {
+
+  /**
+   * Generate a new checkpoint Name
+   *
+   * @return the checkpoint name
+   */
+  public String getNewName();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/CheckpointService.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/CheckpointService.java b/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/CheckpointService.java
new file mode 100644
index 0000000..17af4ce
--- /dev/null
+++ b/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/CheckpointService.java
@@ -0,0 +1,100 @@
+/**
+ * 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.reef.io.checkpoint;
+
+import java.io.IOException;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+
+/**
+ * The CheckpointService provides a simple API to store and retrieve the state of a task.
+ * <p/>
+ * Checkpoints are atomic, single-writer, write-once, multiple-readers, ready-many type of objects.
+ * This is provided by releasing the CheckpointID for a checkpoint only upon commit of the checkpoint,
+ * and by preventing a checkpoint to be re-opened for writes.
+ * <p/>
+ * Non-functional properties such as durability, availability, compression, garbage collection,
+ * quotas are left to the implementation.
+ * <p/>
+ * This API is envisioned as the basic building block for a checkpoint service, on top of which richer
+ * interfaces can be layered (e.g., frameworks providing object-serialization, checkpoint metadata and
+ * provenance, etc.)
+ */
+public interface CheckpointService {
+
+  /**
+   * This method creates a checkpoint and provide a channel to write to it.
+   * The name/location of the checkpoint are unknown to the user as of this time, in fact,
+   * the CheckpointID is not released to the user until commit is called. This makes enforcing
+   * atomicity of writes easy.
+   *
+   * @return a CheckpointWriteChannel that can be used to write to the checkpoint
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  CheckpointWriteChannel create() throws IOException, InterruptedException;
+
+  /**
+   * Used to finalize and existing checkpoint. It returns the CheckpointID that can be later
+   * used to access (read-only) this checkpoint. This guarantees atomicity of the checkpoint.
+   *
+   * @param channel the CheckpointWriteChannel to commit
+   * @return a CheckpointID
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  CheckpointID commit(CheckpointWriteChannel channel) throws IOException, InterruptedException;
+
+  /**
+   * Dual to commit, it aborts the current checkpoint. Garbage collection choices are
+   * left to the implementation. The CheckpointID is not generated nor released to the
+   * user so the checkpoint is not accessible.
+   *
+   * @param channel the CheckpointWriteChannel to abort
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  void abort(CheckpointWriteChannel channel) throws IOException, InterruptedException;
+
+  /**
+   * Given a CheckpointID returns a reading channel.
+   *
+   * @param checkpointId CheckpointID for the checkpoint to be opened
+   * @return a CheckpointReadChannel
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  CheckpointReadChannel open(CheckpointID checkpointId) throws IOException, InterruptedException;
+
+  /**
+   * It discards an existing checkpoint identified by its CheckpointID.
+   *
+   * @param checkpointId CheckpointID for the checkpoint to be deleted
+   * @return a boolean confirming success of the deletion
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  boolean delete(CheckpointID checkpointId) throws IOException, InterruptedException;
+
+  interface CheckpointWriteChannel extends WritableByteChannel {
+  }
+
+  interface CheckpointReadChannel extends ReadableByteChannel {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/RandomNameCNS.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/RandomNameCNS.java b/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/RandomNameCNS.java
new file mode 100644
index 0000000..c71a191
--- /dev/null
+++ b/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/RandomNameCNS.java
@@ -0,0 +1,49 @@
+/**
+ * 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.reef.io.checkpoint;
+
+import org.apache.commons.lang.RandomStringUtils;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+
+/**
+ * Simple naming service that generates a random checkpoint name.
+ */
+public class RandomNameCNS implements CheckpointNamingService {
+
+  private final String prefix;
+
+  @Inject
+  public RandomNameCNS(@Parameter(PREFIX.class) final String prefix) {
+    this.prefix = prefix;
+  }
+
+  @Override
+  public String getNewName() {
+    return this.prefix + RandomStringUtils.randomAlphanumeric(8);
+  }
+
+  @NamedParameter(doc = "The prefix used for the random names returned.", default_value = "checkpoint_")
+  public static class PREFIX implements Name<String> {
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/SimpleNamingService.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/SimpleNamingService.java b/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/SimpleNamingService.java
new file mode 100644
index 0000000..69e3cbd
--- /dev/null
+++ b/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/SimpleNamingService.java
@@ -0,0 +1,55 @@
+/**
+ * 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.reef.io.checkpoint;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+
+/**
+ * A naming service that simply returns the name it has been initialized with.
+ */
+public class SimpleNamingService implements CheckpointNamingService {
+
+  private final String name;
+
+  @Inject
+  public SimpleNamingService(@Parameter(CheckpointName.class) final String name) {
+    this.name = "checkpoint_" + name;
+  }
+
+  /**
+   * Generate a new checkpoint Name.
+   *
+   * @return the checkpoint name
+   */
+  @Override
+  public String getNewName() {
+    return this.name;
+  }
+
+  /**
+   * Prefix for checkpoints.
+   */
+  @NamedParameter(doc = "Checkpoint prefix.", short_name = "checkpoint_prefix", default_value = "reef")
+  public static final class CheckpointName implements Name<String> {
+  }
+}


[17/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/README.md
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/README.md b/lang/java/reef-tang/README.md
new file mode 100644
index 0000000..9b72712
--- /dev/null
+++ b/lang/java/reef-tang/README.md
@@ -0,0 +1,562 @@
+Tang is a configuration managment and checking framework that  emphasizes explicit documentation and automatic checkability of configurations and applications instead of ad-hoc, application-specific configuration and bootstrapping logic.  It supports distributed, multi-language applications, but gracefully handles simpler use cases as well.
+
+Tang makes use of dependency injection to automatically instantiate applications.  Dependency injectors can be thought of as "make for objects"--given a request for some type of object, and information that explains how dependencies between objects should be resolved, dependency injectors automatically instantiate the requested object and all of the objects it dependes upon.  Tang makes use of a few simple wire formats to support remote and even cross-language dependency injection.
+
+Outline
+-------
+
+   * [Motivation](#motivation)
+   * [Design principles](#design-principles)
+   * [Tutorial: Getting started](#tutorial-getting-started)
+     * [Defining configuration parameters](#configuration-parameters)
+     * [Configuration Modules](#configuration-modules)
+     * [Raw configuration API](#raw-configuration-api)
+   * [Tutorial: Complex application architectures](#tutorial-complex-application-architectures)
+     * [Distributed dependency injection](#distributed-dependency-injection)
+     * [Dynamically setting parameters and choosing implementations](#bind)
+     * [Creating sets of similar injectors](#child-injectors)
+   * [Tutorial: Design patterns and best practices](#tutorial-design-patterns-and-best-practices)
+     * [Modularity and complex configurations](#modularity-and-complex-configurations)
+     * [Cyclic dependencies](#cyclic-dependencies)
+   * [Roadmap](#roadmap)
+     * [Using the injection plan API to choose between multiple implementations](#injection-plans)
+     * [Language interoperability](#language-interoperability)
+
+Motivation
+============
+
+Distributed systems suffer from problems that arise due to complex compositions of software modules and configuration errors.  These problems compound over time: best-practice object oriented design dictates that code be factored into independent reusable modules, and today's distributed applications are increasingly expected to run atop multiple runtime environments.  This leads application developers to push complexity into configuration settings, to the point where misconfiguration is now a primary cause of unavailability in fault tolerant systems.
+
+Tang is our attempt to address these problems.  It consists of a dependency injection framework and a set of configuration and debugging tools that automatically and transparently bootstrap applications.  We have focused on providing a narrow set of primitives that support the full range of design patterns that arise in distributed system development, and that encourage application developers to build their systems in a maintainable and debuggable way.
+
+Tang leverages existing language type systems, allowing unmodified IDEs such as Eclipse or NetBeans to surface configuration information in tooltips, provide auto-complete of configuration parameters, and to detect a wide range of configuration problems as you edit your code.  Since such functionality is surfaced in the tools you are already familiar with, there is no need to install (or learn) additional development software to get started with Tang.  Furthermore, we provide a set of sophisticated build time and runtime tools that detect a wide range of common architectural problems and configuration errors.
+
+This documentation consists of tutorials that present prefered Tang design patterns.  By structuring your application according to the patterns we suggest throughout the tutorials, you will allow our static analysis framework, Tint ("Tang Lint"), to detect problematic design patterns and high-level configuration problems as part of your build.  These patterns provide the cornerstone for a number of more advanced features, such as interacting with legacy configuration systems, designing for cross-language applications, and multi-tenancy issues, such as secure injections of untrusted application code.  To the best of our knowledge, implementing such tools and addressing these real-world implementation constraints would be difficult, or even impossible, atop competing frameworks.
+
+Design principles
+=================
+
+Tang encourages application developers to specify default implementations and constructor parameters in terms of code annotations and configuration modules.  This avoids the need for a number of subtle (and often confusing) dependency injection software patterns, though it does lead to a different approach to dependency injection than other frameworks encourage.
+
+In the process of building complicated systems built atop Tang, we found that, as the length of configurations that are passed around at runtime increased, it rapidly became impossible to debug or maintain our higher-level applications.  In an attempt to address this problem, traditional dependency injection systems actually compound this issue.  They encourage the developers of each application-level component to implement hand-written "Modules" that are executed at runtime.  Hand-written modules introspect on the current runtime configuration, augment and modify it, and then return a new configuration that takes the new application component into account.
+
+In other systems, developers interact with modules by invoking ad-hoc builder methods, and passing configurations (in the correct order) from module to module.  Modules frequently delgate to each other, either via inheritance or wrappers.  This makes it difficult for developers and end-users to figure out which value of a given parameter will be used, or even to figure out why it was (or was not) set.
+
+Tang provides an alternative called `ConfigurationModule`s:
+
+- `Configurations` and `ConfigurationModules` are "just data," and can be read and written in human readable formats.
+- Interfaces and configuration parameters are encouraged to specify defaults, significantly shortening the configurations generated at runtime, and making it easy to see what was "strange" about a given run of the application.
+- Tang's static analysis and documentation tools sanity check `ConfigurationModule`s, and document their behavior and any extra parameters they export.
+- Configuration options can be set at most once.  This avoids (or at least detects) situations in which users and application-level code inadvertantly "fight" over the setting of a particular option.
+
+The last property comes from Tang's use of _monotonic_ set oriented primitives.  This allows us to leverage recent theoretical results in commtative data types; particularly CRDTs, and the CALM theorem.  Concretely:
+- A large subset of Tang's public API is commutative, which frees application-level configuration and bootstrapping logic from worrying about the order in which configuration sources are processed at runtime.
+- Tang can detect configuration and injection problems much earlier than is possible with other approaches.  Also, upon detecting a conflict, Tang lists the configuration sources that contributed to the problem.
+
+Finally, Tang is divided into a set of "core" primtives, and higher-level configuration "formats".  Tang's core focuses on dependency injection and static checking of configurations.  The formats provide higher-level configuration languages primitives, such as distributed, cross-language injection, configuration files, and `ConfigurationModule`.  Each Tang format imports and/or exports standard Tang `Configuration` objects, which can then be composed with other configuration data at runtime.
+
+Improvements to these formats are planned, such as command-line tab completion, and improved APIs for extremely complex applications that are built by composing multiple Tang configurations to inject arbitrary object graphs.
+Furthermore, Tang formats include documentation facilities, and automatic command line and configuration file parsing.  From an end-user perspective, this takes a lot of the guesswork out of configuration file formats.
+
+Although Tang surfaces a text-based interface for end-users of the applications built atop it, all configuration options and their types are specified in terms of Java classes and annotations.  As with the core Tang primitives, this allows the Java compiler to statically check Tang formats for problems such as inconsistent usage of configuration parameters, naming conflicts and so on.  This eliminates broad classes of runtime errors.   These checks can be run independently of the application's runtime environment, and can find problems both in the Java-level implementation of the system, and with user-provided configuration files.  The tools that perform these checks are designed to run as a post-processing step of projects built atop Tang.  Like the Java compiler checks, this prevents such errors from making it to production environments.  It also prevents such errors from being exposed to application logic or end-users, greatly simplifying applications built atop Tang.
+
+Taken together, these properties greatly simplify dependency injection in distributed environments.  We expect Tang to be used in environments that are dominated by "plugin"-style APIs with many alternative implementations.  Tang cleanly separates concerns over configuration management, dependency injection and object implementations, which hides most of the complexity of dependency injection from plugin implementers.  It also prevents plugin implementations from inadvertently conflicting with each other or their runtime environements.  Such clean semantics are crucial in distributed, heterogeneous environments.
+
+Tutorial: Getting started
+=========================
+
+This tutorial is geared toward people that would like to quickly get started with Tang, or that are modifying an existing Tang application.
+
+Constructors, @Inject and @Parameter
+------------------------
+
+Suppose you are implementing a new class, and would like to automatically pass configuration parameters to it at runtime:
+
+```java
+package com.example;
+
+public class Timer {
+  private final int seconds;
+
+  public Timer(int seconds) {
+    if(seconds < 0) {
+      throw new IllegalArgumentException("Cannot sleep for negative time!");
+    }
+    this.seconds = seconds;
+  }
+
+  public void sleep() throws Exception {
+    java.lang.Thread.sleep(seconds * 1000);
+  }
+}
+```
+Tang encourages applications to use Plain Old Java Objects (POJOs), and emphasizes the use of immutable state for configuration parameters.  This reduces boiler plate (there is no need for extra setter methods), and does not interfere with encapsulation (the fields and even the constructor can be private).  Furthermore, it is trivial for well-written classes to ensure that all objects are completely and properly instantiated:  They simply need to check constructor parameters as any other POJO would, except that Tang never passes `null` references into constructors, allowing their implementations to assume that all parameter values are non-null.
+
+Tang aims to provide end users with error messages as early as possible, and encourages developers to throw exceptions inside of constructors.  This allows it to automatically provide additional information to end-users when things go wrong:
+
+```
+Exception in thread "main" org.apache.reef.tang.exceptions.InjectionException: Could not invoke constructor: new Timer(Integer Seconds = -1)
+	at org.apache.reef.tang.implementation.java.InjectorImpl.injectFromPlan(InjectorImpl.java:585)
+	at org.apache.reef.tang.implementation.java.InjectorImpl.getInstance(InjectorImpl.java:449)
+	at org.apache.reef.tang.implementation.java.InjectorImpl.getInstance(InjectorImpl.java:466)
+	at org.apache.reef.tang.examples.Timer.main(Timer.java:48)
+Caused by: java.lang.IllegalArgumentException: Cannot sleep for negative time!
+	at org.apache.reef.tang.examples.Timer.<init>(Timer.java:25)
+	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
+	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
+	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
+	at java.lang.reflect.Constructor.newInstance(Unknown Source)
+	at org.apache.reef.tang.implementation.java.InjectorImpl.injectFromPlan(InjectorImpl.java:569)
+	... 3 more
+```
+
+In order for Tang to instantiate an object, we need to annotate the constructor with an `@Inject` annotation.  While we're at it, we'll define a configuration parameter, allowing us to specify seconds on the command line and in a config file:
+
+```java
+package com.example;
+
+import javax.inject.Inject;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+
+public class Timer {
+  @NamedParameter(default_value="10",
+      doc="Number of seconds to sleep", short_name="sec")
+  class Seconds implements Name<Integer> {}
+  private final int seconds;
+
+  @Inject
+  public Timer(@Parameter(Seconds.class) int seconds) {
+    if(seconds < 0) {
+      throw new IllegalArgumentException("Cannot sleep for negative time!");
+    }
+    this.seconds = seconds;
+  }
+
+  public void sleep() throws Exception {
+    java.lang.Thread.sleep(seconds * 1000);
+  }
+}
+```
+A few things happened here.  First, we create the new configuration parameter by declaring a dummy class that implements Tang's `Name` interface.  `Name` is a generic type with a single mandatory parameter that specifies the type of object to be passed in.  Since `Seconds` implements `Name<Integer>`, it is a parameter called `Seconds` that expects `Integer` values.  More precisely, `Seconds` is actually named `com.example.Timer.Seconds`.  This reliance on language types to define parameter names exposes parameters to the compiler and IDE.  Concretely:
+ * `javac` maps from `Seconds` to the full class name in the usual way, preventing parameters with the same name, but in different packages from conflicting.
+ * The Java classloader ensures that classes are unique at runtime. 
+ * Standard IDE features, such as code navigation, completion and refactoring work as they normally would for class names.
+
+
+All instances of `Name` must be annotated with `@NamedParameter`, which takes the following optional parameters:
+ * `default_value`: The default value of the constructor parameter, encoded as a string.  Tang will parse this value (and ones in config files and on the command line), and pass it into the constructor.  For convenience Tang includes a number of helper variants of default value.  `default_class` takes a Class (instead of a String), while `default_values` and `default_classes` take sets of values.
+ * `short_name`: The name of the command line option associated with this parameter.  If omitted, no command line option will be created.  Short names must be registered by calling `registerShortName()` on the instance of `org.apache.reef.tang.formats.CommandLine` that will process the command line options.
+ * `doc` (optional): Human readable documentation that describes the purpose of the parameter.
+
+Tang only invokes constructors that have been annotated with `@Inject`.  This allows injectable constructors to coexist with ones that should not be invoked via dependency injection (such as ones with destructive side effects, or that expect `null` references).  Constructor parameters must not be ambiguous.  If two parameters in the same constructor have the same type, then they must be annotated with `@Parameter`, which associates a named parameter with the argument.  Furthermore, two parameters to the same constructor cannot have the same name.  This allows Tang to safely invoke constructors without exposing low level details (such as parameter ordering) as configuration options.
+
+Example:
+
+![screenshot of tooltip](doc/tooltip.png "IDE contextual help contains information about Tang named parameters")
+
+Configuration modules
+---------
+Configuration modules allow applications to perform most configuration generation and verification tasks at build time.  This allows Tang to automatically generate rich configuration-related documentation, to detect problematic design patterns, and to report errors before the application even begins to run.
+
+In the example below, we extend the Timer API to include a second implementation that simply outputs the amount of
+time a real timer would have slept to stderr.  In a real unit testing example, it would likely interact with a scheduler based on logical time.  Of course, in isolation, having the ability to specify configuration parameters is not particularly useful; this example also adds a `main()` method that invokes Tang, and instantiates an object.
+
+The process of instantiting an object with Tang is called _injection_.  As with configurations, Tang's injection process is designed to catch as many potential runtime errors as possible before application code begins to run.  This simplifies debugging and eliminates many types of runtime error handling code, since many configurations can be caught before running (or examining) application-specific initialization code. 
+
+
+```java
+package org.apache.reef.tang.examples.timer;
+
+import javax.inject.Inject;
+
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+
+import org.apache.reef.tang.annotations.DefaultImplementation;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.OptionalParameter;
+
+@DefaultImplementation(TimerImpl.class)
+public interface Timer {
+  @NamedParameter(default_value="10",
+      doc="Number of seconds to sleep", short_name="sec")
+  public static class Seconds implements Name<Integer> { }
+  public void sleep() throws Exception;
+}
+
+public class TimerImpl implements Timer {
+
+  private final int seconds;
+  @Inject
+  public TimerImpl(@Parameter(Timer.Seconds.class) int seconds) {
+    if(seconds < 0) {
+      throw new IllegalArgumentException("Cannot sleep for negative time!");
+    }
+    this.seconds = seconds;
+  }
+  @Override
+  public void sleep() throws Exception {
+    java.lang.Thread.sleep(seconds);
+  }
+
+}
+
+public class TimerMock implements Timer {
+
+  public static class TimerMockConf extends ConfigurationModuleBuilder {
+    public static final OptionalParameter<Integer> MOCK_SLEEP_TIME = new OptionalParameter<>();
+  }
+  public static final ConfigurationModule CONF = new TimerMockConf()
+    .bindImplementation(Timer.class, TimerMock.class)
+    .bindNamedParameter(Timer.Seconds.class, TimerMockConf.MOCK_SLEEP_TIME)
+    .build();
+  
+  private final int seconds;
+  
+  @Inject
+  TimerMock(@Parameter(Timer.Seconds.class) int seconds) {
+    if(seconds < 0) {
+      throw new IllegalArgumentException("Cannot sleep for negative time!");
+    }
+    this.seconds = seconds; 
+  }
+  @Override
+  public void sleep() {
+    System.out.println("Would have slept for " + seconds + "sec.");
+  }
+
+  public static void main(String[] args) throws BindException, InjectionException, Exception {
+    Configuration c = TimerMock.CONF
+      .set(TimerMockConf.MOCK_SLEEP_TIME, 1)
+      .build();
+    Timer t = Tang.Factory.getTang().newInjector(c).getInstance(Timer.class);
+    System.out.println("Tick...");
+    t.sleep();
+    System.out.println("...tock.");
+  }
+}
+```
+Again, there are a few things going on here:
+   - First, we push the implementation of `Timer` into a new class, `TimerImpl`.  The `@DefaultImplementation` tells Tang to use `TimerImpl` when no other implementation is explicitly provided.
+   - We leave the `Sleep` class in the Timer interface.  This, plus the `@DefaultImplementation` annotation maintain backward compatibility with code that used Tang to inject the old `Timer` class.
+   - The `TimerMock` class includes a dummy implementation of Timer, along with a `ConfigurationModule` final static field called `CONF`.
+   - The main method uses `CONF` to generate a configuration.  Rather than set `Timer.Sleep` directly, it sets `MOCK_SLEEP_TIME`.  In a more complicated example, this would allow `CONF` to route the sleep time to testing infrastructure, or other classes that are specific to the testing environment or implemenation of `TimerMock`.
+
+`ConfigurationModule`s serve a number of purposes:
+   - They allow application and library developers to encapsulate the details surrounding their code's instantiation.
+   - They provide Java APIs that expose `OptionalParameter`, `RequiredParameter`, `OptionalImplementation`, `RequiredImpementation` fields.  These fields tell users of the ConfigurationModule which subsystems of the application require which configuration parameters, and allow the author of the ConfigurationModule to use JavaDoc to document the parameters they export.
+   - Finally, because ConfigurationModule data structures are populated at class load time (before the application begins to run), they can be inspected by Tang's static analysis tools.
+
+These tools are provided by `org.apache.reef.tang.util.Tint`, which is included by default in all Tang builds.  As long as Tang is on the classpath, invoking:
+```
+java org.apache.reef.tang.util.Tint --doc tangdoc.html
+```
+will perform full static analysis of all classes the class path, and emit a nicely formatted HTML document.  The documentation generated by Tint includes cross-references between configuration options, interfaces, classes, and the `ConfigurationModules` that use and set them. 
+
+Here is the documentation for the Timer example:
+
+![screenshot of tooltip](doc/tangdoc.png "Automatically generated documentation of Tang configuration data.")
+
+Note that this documentation is generated before the application code runs, so it does not reflect the fact that `MOCK_SLEEP_TIME` is set to 1 by `main()`.
+
+Here are some sample Tint errors.  These (and others) can be run by passing `--tang-tests` into Tint, and ensuring that Tang's unit tests are on the class path.:
+```
+interface org.apache.reef.tang.MyEventHandlerIface declares its default implementation to be non-subclass class org.apache.reef.tang.MyEventHandler
+class org.apache.reef.tang.WaterBottleName defines a default class org.apache.reef.tang.GasCan with a type that does not extend its target's type org.apache.reef.tang.Bottle<org.apache.reef.tang.Water>
+Named parameters org.apache.reef.tang.examples.Timer$Seconds and org.apache.reef.tang.examples.TimerV1$Seconds have the same short name: sec
+Named parameter org.apache.reef.tang.implementation.AnnotatedNameMultipleInterfaces implements multiple interfaces.  It is only allowed to implement Name<T>
+Found illegal @NamedParameter org.apache.reef.tang.implementation.AnnotatedNotName does not implement Name<?>
+interface org.apache.reef.tang.implementation.BadIfaceDefault declares its default implementation to be non-subclass class java.lang.String
+class org.apache.reef.tang.implementation.BadName defines a default class java.lang.Integer with a raw type that does not extend of its target's raw type class java.lang.String
+Named parameter org.apache.reef.tang.implementation.BadParsableDefaultClass defines default implementation for parsable type java.lang.String
+Class org.apache.reef.tang.implementation.DanglingUnit has an @Unit annotation, but no non-static inner classes.  Such @Unit annotations would have no effect, and are therefore disallowed.
+Cannot @Inject non-static member class unless the enclosing class an @Unit.  Nested class is:org.apache.reef.tang.implementation.InjectNonStaticLocalType$NonStaticLocal
+Named parameter org.apache.reef.tang.implementation.NameWithConstructor has a constructor.  Named parameters must not declare any constructors.
+Named parameter type mismatch.  Constructor expects a java.lang.String but Foo is a java.lang.Integer
+public org.apache.reef.tang.implementation.NonInjectableParam(int) is not injectable, but it has an @Parameter annotation.
+Detected explicit constructor in class enclosed in @Unit org.apache.reef.tang.implementation.OuterUnitBad$InA  Such constructors are disallowed.
+Repeated constructor parameter detected.  Cannot inject constructor org.apache.reef.tang.implementation.RepeatConstructorArg(int,int)
+Named parameters org.apache.reef.tang.implementation.ShortNameFooA and org.apache.reef.tang.implementation.ShortNameFooB have the same short name: foo
+Named parameter org.apache.reef.tang.implementation.UnannotatedName is missing its @NamedParameter annotation.
+Field org.apache.reef.tang.formats.MyMissingBindConfigurationModule.BAD_CONF: Found declared options that were not used in binds: { FOO_NESS }
+```
+
+Injecting objects with `getInstance()`
+--------------------------------------
+
+Above, we explain how to register constructors with Tang, and how to configure Tang to inject the desired objects at runtime.  This section explains how Tang actually instantiates objects, and how the primitives it provides can be combined to support sophisticated application architectures.
+
+In order to instantiate objects with Tang, one must invoke Tang.Factory.getTang().newInjector(Configuration...).  This returns a new "empty" injector that will honor the configuration options that were set in the provided configurations, and that will have access to a merged version of the classpath they refer to.
+
+In a given Tang injector, all classes are treated as singletons: at most one instance of each class may exist.  Furthermore, Tang Configuration objects are designed to be built up from trees of related (but non-conflicting) configuration files, command line parameters, and so on.  At first, this may seem to be overly restrictive, since it prevents applications from creating multiple instances of the same class (or even two classes that require different values of the same named parameter).
+
+Tang addresses this by providing the runtime environment more explicit control over object and configuration parameter scopes.  Taken together, `forkInjector()`, `bindVolatile()` and `InjectionFuture<T>` allow Tang to inject arbitrary sets of objects (including ones with multiple instances of the same class).
+
+Other injection frameworks take a different approach, and allow class implementations to decide if they should be singletons across a given JVM (e.g., with an `@Singleton` annotation), user session (for web services), user connection, and so on.  This approach has at least two problems:
+ * It is not general purpose: after all, it encodes deployment scenarios into the injection framework and application APIs!
+ * It trades one barrier to composability and reuse: _hard-coded constructor invocations_ with another: _hard-coded runtime environments_.  The former prevents runtime environments from adapting to application-level changes, while the latter prevents application code from adapting to new runtimes.
+
+Tang's approach avoids both issues by giving the implementation of the runtime environment explicit control over object scopes and lifetimes.
+
+`forkInjector()` makes a copy of a given injector, including references to all the objects already instantiated by the original injector.  This allows runtime environments to implement scopes.  First, a root injector is created.  In order to create a child scope, the runtime simply invokes `forkInjector()` on the root context, and optionally passes additional `Configuration` objects in.  These additional configurations allow the runtime to specialize the root context.
+
+Although the forked injector will have access to any objects and configuration bindings that existed when `forkInjector()` was called, neither the original nor the forked injectors will reflect future changes to the other injector.
+
+The second primitive, `bindVolatile()`, provides an injector with an instance of a class or named parameter.  The injector treats this instance as though it had injected the object directly.  This:
+ * allows passing of information between child scopes
+ * makes it possible to create (for example) chains of objects of the same type
+ * and allows objects that cannot be instantiated via Tang to be passed into injectable constructors.
+
+### Cyclic injections
+
+Although the above primitives allow applications to inject arbitrary DAGs (directed acyclic graphs) of objects, they do not support cycles of objects.  Tang provides the `InjectionFuture<T>` interfaces to support such _cyclic injections_.
+
+When Tang encounters a constructor parameter of type `InjectionFuture<T>`, it injects an object that provides a method `T get()` that returns an injected instance of `T`.  
+
+
+This can be used to break cycles:
+
+```java
+A(B b) {...}
+B(InjectionFuture<A> a) {...}
+```
+
+In order to inject an instance of `A`, Tang first injects an instance of `B` by passing it an `InjectionFuture<A>`.  Tang then invoke's `A`'s constructor, passing in the instance of `B`.  Once the constructor returns, the new instance of `A` is passed into `B`'s `InjectionFuture<A>`.  At this point, it becomes safe for `B` to invoke `get()`, which establishes the circular reference.
+
+Therefore, along with `forkInjector()` and `bindVolatile()`, this allows Tang to inject arbitrary graphs of objects.  This pattern avoids non-final fields (once set, all fields of all objects are constant), and it also avoids boiler plate error handling code that checks to see if `B`'s instance of `A` has been set.
+
+
+When `get()` is called after the application-level call to `getInstance()` returns, it is guranteed to return a non-null reference to an injected instance of the object.  However, if `get()` is called _before_ the constructor it was passed to returns, then it is guaranteed to throw an exception.    In between these two points in time, `get()`'s behavior is undefined, but, for the sake of race-detection and forward compatibility it makes a best-effort attempt to throw an exception.
+
+Following Tang's singleton semantics, the instance returned by `get()` will be the same instance the injector would pass into other constructors or return from `getInstance()`.
+
+Alternative configuration sources
+=================================
+
+Tang provides a number of so-called _formats_ that interface with external configuration data.  `ConfigurationModule` is one such example (see above).  These formats transform configuration data to and from Tang's raw configuration API.  The raw API provides an implementation of ConfigurationBuilder, which implements most of Tang's configuration checks.  It also provides a `JavaConfigurationBuilder` interface provides convenience methods that take Java Classes, and leverage Java's generic type system to push a range of static type checks to Java compilation time.
+
+Raw configuration API
+---------
+Tang also provides a lower level configurtion API for applications that need more dynamic control over their configurations:
+
+```java
+...
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.ConfigurationBuilder;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+
+...
+  public static void main(String[] args) throws BindException, InjectionException {
+    Tang tang = Tang.Factory.getTang();
+    ConfigurationBuilder cb = (ConfigurationBuilder)tang.newConfigurationBuilder();
+    cb.bindNamedParameter(Timer.Seconds.class, 5);
+    Configuration conf = cb.build();
+    Injector injector = tang.newInjector(conf);
+    if(!injector.isInjectable(Timer.class)) {
+      System.err.println("If isInjectable returns false, the next line will throw an exception");
+    }
+    Timer timer = injector.getInstance(Timer.class);
+
+    try {
+      System.out.println("Tick...");
+      timer.sleep();
+      System.out.println("Tock.");
+    } catch(InterruptedException e) {
+      e.printStackTrace();
+    }
+  }
+```
+The first step in using Tang is to get a handle to a Tang object by calling "Tang.Factory.getTang()".  Having obtained a handle, we run through each of the phases of a Tang injection:
+   * We use `ConfigurationBuilder` objects to tell Tang about the class hierarchy that it will be using to inject objects and (in later examples) to register the contents of configuration files, override default configuration values, and to set default implementations of classes.  `ConfigurationBuilder` and `ConfigurationModuleBuider` export similar API's.  The difference is that `ConfigurationBuilder` produces `Configuration` objects directly, and is designed to be used at runtime.  `ConfigurationModuleBuilder` is desgined to produce data structures that will be generated and analyzed during the build, and at class load time.
+   * `bindNamedParameter()` overrides the default value of Timer.Sleep, setting it to 5.  Tang inteprets the 5 as a string, but allows instances of Number to be passed in as syntactic sugar.
+   * We call `.build()` on the `ConfigurationBuilder`, creating an immutable `Configuration` object.  At this point, Tang ensures that all of the classes it has encountered so far are consistent with each other, and that they are suitable for injection.  When Tang encounters conflicting classes or configuration files, it throws a `BindException` to indicate that the problem is due to configuration issues. Note that `ConfigurationBuilder` and `Configuration` do not determine whether or not a particular injection will succeed; that is the business of the _Injector_.
+   * To obtain an instance of Injector, we pass our Configuration object into `tang.newInjector()`.
+   * `injector.isInjectable(Timer.class)` checks to see if Timer is injectable without actually performing an injection or running application code.  (Note that, in this example, the Java classloader may have run application code.  For more information, see the advanced tutorials on cross-language injections and securely building configurations for untrusted code.)
+   * Finally, we call `injector.getInstance(Timer.class)`.  Internally, this method considers all possible injection plans for `Timer`.  If there is exactly one such plan, it performs the injection.  Otherwise, it throws an `InjectionException`.
+
+
+
+Tang configuration information can be divided into two categories.  The first type, _parameters_, pass values such as strings and integers into constructors.  Users of Tang encode configuration parameters as strings, allowing them to be stored in configuration files, and passed in on the command line.
+
+The second type of configuration option, _implementation bindings_, are used to tell Tang which implementation should be used when an instance of an interface is requested.  Like configuration parameters, implementation bindings are expressible as strings: Tang configuration files simply contain the raw (without the generic parameters) name of the Java Classes to be bound together.
+
+New parameters are created and passed into constructors as in the examples above, by creating implementations of `Name<T>`, and adding `@NamedParameter`, `@Parameter` and `@Inject` annotations as necessary.  Specifying implementations for interfaces is a bit more involved, as a number of subtle use cases arise.
+
+However, all configuration settings in Tang can be unambiguously represented as a `key=value` pair that can be interpreted either asan `interface=implementation` pair or a `configuration_parameter=value` pair.  This maps well to Java-style properties files.  For example:
+
+```properties
+com.examples.Interface=com.examples.Implementation
+```
+
+tells Tang to create a new Implementation each time it wants to invoke a constructor that asks for an instance of Interface.  In most circumstances, Implementation extends or implements Interface (`ExternalConstructors` are the exception -- see the next section).  In such cases, Tang makes sure that Implementation contains at least one constructor with an `@Inject` annotation, and performs the binding.
+
+See the `ConfigurationFile` API for more information about processing configuration files in this format.
+
+
+<!--
+[**TODO:** document configuration file API here]
+
+[**TODO:** explain `processCommandLine()`]
+
+
+Advanced Object Injection Patterns
+----------------------------------
+
+### Cyclic injections with `InjectionFuture`
+
+Unlike other dependency injection frameworks, all Tang injections are performed by invoking object constructors.  Although it is generally considered bad practice to create classes with circular dependencies, there are valid reasons to have two objects that point to each other at runtime.  For concreteness, call these two objects `a` and `b`.
+
+The simplest way to achieve this is to add a setter to one of the objects, and then invoke the setter in the other object's constructor:
+
+```java
+  a.setB(b);
+```
+
+Although this works, it has a few disadvantages:
+ - `a` is no longer immutable (or fully instantiated when its constructor returns), which means that its implementation should contain checks to ensure that b is set exactly once before execution proceeds.
+ - `a`'s dependency on `b` is no longer apparent from `a`'s constructor signatures.
+
+This is a shame; when coupled with immutable fields, Tang's use of constructor-based injetion eliminates both these problems, saving application developers from implementing and documenting setters and runtime checks.
+
+Based on these observations, Tang offers an alternative called an `InjectionFuture`.  In our example, we would declare two consructors:
+```java
+@Inject A(InjectionFuture<B> b) { this.b_f = b; }
+@Inject B(A a ) { this.a = a; }
+```
+Instead of passing `b` directly into `a`'s constructor, Tang creates an `InjectionFuture<B>` with a single method `public B get()`.  `get()` is guaranteed to throw an exception if called before `A`'s constructor returns, and is guaranteed to return the injected instance of `B` if called after Tang's `Injector.getInstance()` successfuly returns.  This allows application designers to break cycles in injections without resorting to mutable fields, or runtime error checking.  `get()` throws a `RuntimeException` that object implementors should ignore and pass up the stack.  Note that calling methods that transitively call `InjectionFuture.get()` within a constructor is fundamentally unsafe.  Such calls have undefined behavior, but Tang makes a best effort attempt to throw an exception when such a call is made.
+
+
+### Using `@Unit` to implement multiple versions of a generic interface
+
+### Using `ExternalConstructor` to inject legacy code or delegate to a subtype during injection.
+
+TODO promote to top-level section.
+
+Tang's _ExternalConstructor_ API supports injection of legacy code.  If Implementation does not subclass Interface, Tang checks to see if it subclasses ExternalConstructor<? extends Interface> instead.  If so, Tang checks that Implementation has an `@Inject` annotation on at least one constructor, and performs the binding as usual.  At injection time, Tang injects Implementation as though it implemented Interface, and then calls `newInstance()`, which returns the value to be injected.  Note that `ExternalConstructor` objects are single-use: `newInstance()` will only be called once.  If the `ExternalConstructor` class is marked as a singleton, Tang internally retains the return value of `newInstance()`, exactly as if the object had been created with a regular constructor.
+
+Tutorial: Complex application architectures
+===========================================
+
+Composing configurations from multiple sources
+----------------------------------------------
+
+Distributed dependency injection
+--------------------------------
+In Tang, distributed injection is performed by writing Tang's current state out to configuration files, shipping them to remote machines, and using the configuration file to instantiate an identical Tang instance on the remote machine.  Two methods support such use cases.  The first is part of the Configuration API, and writes a well-formed configuration file to an output stream.  Its method signature is self-explanatory:
+
+```java
+public void writeConfigurationFile(OutputStream s)
+```
+
+Reading the file back is the responsibility of `ConfigurationBuilder`.  The following methods read the file line by line, merging the Configuration options they find with the current state of the `ConfigurationBuilder`.  If a conflicting or already-set option is encountered, processing halts on the line that caused the problem, and a `BindException` is thrown:
+
+```java
+public void addConfiguration(final File istream) throws IOException, BindException;
+public void addConfiguration(final String istream) throws BindException;
+```
+
+Bind
+----
+Sometimes it is necessary to compute configuration information at runtime, and pass the result into Tang.  Tang provides two types of `bind()` methods for such purposes.  The first reside in `configurationBuilder()`, and are designed to preserve Tang's ability to write back the resulting configuration to a file.  Like configuration files, these methods can tell Tang which implementation should be used for a given interface, provide strings to be parsed into configuration parameters, and so on:
+
+```java
+void bind(String iface, String impl) throws ClassNotFoundException;
+void bind(Class<T> iface, Class<?> impl);
+void bindImplementation(Class<T> iface, Class<? extends T> impl);
+void bindSingletonImplementation(Class<T> iface, Class<? extends T> impl);
+void bindSingleton(Class<T> iface) throws BindException;
+void bindNamedParameter(Class<? extends Name<T>> name, String value);
+void bindConstructor(Class<T> c, Class<? extends ExternalConstructor<? extends T>> v);
+```
+Each of these methods throws BindException as well as the exceptions mentioned above, and behaves identically to the analogous configuration file primitives discussed above.  Note that, when possible, adding final [`StaticConfiguration`](static-configuration) objects to class definitions objects is always preferable to writing a method that invokes bind...() directly.
+
+The second class of bind operations allow callers to pass object instances to Tang directly.  This prevents it from writing back its current state to a configuration file.  Because these methods are incompatible with writing configuration files, their names contain the word "Volatile", and they are part of the Injector API instead of ConfigurationBuilder.  Injectors cannot be serialized, and they are not allowed to modify the Configuration object that was used to create them, making it impossible to use the Tang API to write volatile objects to disk.
+
+```java
+Injector bindVolatileInstance(Class<T> iface, T inst) throws BindException;
+Injector bindVolatileParameter(Class<? extends Name<T>> iface, T inst) throws BindException;
+```
+Note that these methods return new Injector objects.  Tang Injectors are immutable, and the original Injector is not modified by these calls.
+
+A final method, `getNamedParameter()`, is sometimes useful when dealing with instances of objects used for Tang injections.  Unlike `getInstance()`, which performs a normal injection, `getNamedParameter()` instantiates an object in the same way as it would during an injection, as it prepares to pass a configuration parameter to a constructor (note that whether a new instance of the parameter is instantiated for each constructor invocation is not specified by the Tang API, so while the object returned likely `.equals()` the one that would be passed to a constructor, it may or may not `==` it.
+
+Roadmap
+=======
+
+Injection plans
+---------------
+[Coming soon]
+
+Language interoperability
+-------------------------
+[Coming soon]
+
+When things go wrong
+--------------------
+In the timer example, we specified a default value for the Sleep parameter.  If we hadn't done this, then the call
+to `getInstance()` would have thrown an exception:
+````
+Exception in thread "main"
+java.lang.IllegalArgumentException: Attempt to inject infeasible plan: com.example.Timer(Integer Seconds = null)
+...
+````
+Since Tang refuses to inject null values into object constructors, the plan to invoke `Timer(null)` is considered infeasible.  Note that this error message enumerates all possible injection plans.  If Timer had more constructors or implementations those would be enumerated here as well.  Similarly, if more than one feasible plan existed, Tang would refuse to perform the injection, and throw a similar exception.
+
+In both cases, the solution is to set additional configuration parameters to create a single feasible plan.  This can be done using any of the methods described above.
+-->
+Looking under the hood
+----------------------
+
+### InjectionPlan
+
+InjectionPlan objects explain what Tang would do to instantiate a new object, but don't actually instantiate anything.
+Add the following lines to the Timer example;
+
+````java
+import org.apache.reef.tang.implementation.InjectionPlan;
+import org.apache.reef.tang.implementation.InjectorImpl;
+...
+    InjectorImpl injector = (InjectorImpl)tang.newInjector(conf);
+    InjectionPlan<Timer> ip = injector.getInjectionPlan(Timer.class);
+    System.out.println(ip.toPrettyString());
+    System.out.println("Number of plans:" + ip.getNumAlternatives());
+````
+
+Running the program now produces a bit of additional output:
+````
+new Timer(Integer Seconds = 10)
+Number of plans:1
+````
+
+InjectionPlan objects can be serialized to protocol buffers.  The following file documents their format:
+
+https://github.com/apache/incubator-reef/blob/master/reef-tang/tang/src/main/proto/injection_plan.proto
+
+### ClassHierachy
+
+InjectionPlan explains what would happen if you asked Tang to take some action, but it doesn't provide much insight into Tang's view of the object hierarchy, parameter defaults and so on.  ClassHierarchy objects encode the state that Tang gets from .class files, including class inheritance relationships, parameter annotations, and so on.
+
+Internally, in the example above, TypeHierarchy walks the class definition for Timer, looking for superclasses, interfaces, and classes referenced by its constructors.
+
+ClassHierarchy objects can be serialized to protocol buffers.  The following file documents their format:
+
+https://github.com/apache/incubator-reef/blob/master/reef-tang/tang/src/main/proto/class_hierarchy.proto
+
+The java interfaces are available in this package:
+
+https://github.com/apache/incubator-reef/tree/master/reef-tang/tang/src/main/java/org/apache/reef/tang/types
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/doc/tangdoc.png
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/doc/tangdoc.png b/lang/java/reef-tang/doc/tangdoc.png
new file mode 100644
index 0000000..04a09a1
Binary files /dev/null and b/lang/java/reef-tang/doc/tangdoc.png differ

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/doc/tooltip.png
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/doc/tooltip.png b/lang/java/reef-tang/doc/tooltip.png
new file mode 100644
index 0000000..bd0efe1
Binary files /dev/null and b/lang/java/reef-tang/doc/tooltip.png differ

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/pom.xml b/lang/java/reef-tang/pom.xml
new file mode 100644
index 0000000..35df7a5
--- /dev/null
+++ b/lang/java/reef-tang/pom.xml
@@ -0,0 +1,40 @@
+<?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>
+    <packaging>pom</packaging>
+    <name>REEF Tang Project</name>
+    <artifactId>tang-project</artifactId>
+
+    <parent>
+        <groupId>org.apache.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <modules>
+        <module>tang-test-jarA</module>
+        <module>tang-test-jarB</module>
+        <module>tang-test-jarAB</module>
+        <module>tang-test-jarB-conflictA</module>
+        <module>tang</module>
+    </modules>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang-test-jarA/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang-test-jarA/pom.xml b/lang/java/reef-tang/tang-test-jarA/pom.xml
new file mode 100644
index 0000000..5f3f309
--- /dev/null
+++ b/lang/java/reef-tang/tang-test-jarA/pom.xml
@@ -0,0 +1,31 @@
+<?xml version="1.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.
+-->
+<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.reef</groupId>
+        <artifactId>tang-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>tang-test-jarA</artifactId>
+    <name>Tang Test Jar A</name>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang-test-jarA/src/main/java/org/apache/reef/tang/examples/A.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang-test-jarA/src/main/java/org/apache/reef/tang/examples/A.java b/lang/java/reef-tang/tang-test-jarA/src/main/java/org/apache/reef/tang/examples/A.java
new file mode 100644
index 0000000..2eb49cf
--- /dev/null
+++ b/lang/java/reef-tang/tang-test-jarA/src/main/java/org/apache/reef/tang/examples/A.java
@@ -0,0 +1,23 @@
+/**
+ * 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.reef.tang.examples;
+
+public class A {
+  int iAmAClass = 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang-test-jarAB/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang-test-jarAB/pom.xml b/lang/java/reef-tang/tang-test-jarAB/pom.xml
new file mode 100644
index 0000000..e951be4
--- /dev/null
+++ b/lang/java/reef-tang/tang-test-jarAB/pom.xml
@@ -0,0 +1,38 @@
+<?xml version="1.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.
+-->
+<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.reef</groupId>
+        <artifactId>tang-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>tang-test-jarAB</artifactId>
+    <name>Tang Test Jar AB</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>javax.inject</groupId>
+            <artifactId>javax.inject</artifactId>
+        </dependency>
+    </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang-test-jarAB/src/main/java/org/apache/reef/tang/examples/A.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang-test-jarAB/src/main/java/org/apache/reef/tang/examples/A.java b/lang/java/reef-tang/tang-test-jarAB/src/main/java/org/apache/reef/tang/examples/A.java
new file mode 100644
index 0000000..7586c16
--- /dev/null
+++ b/lang/java/reef-tang/tang-test-jarAB/src/main/java/org/apache/reef/tang/examples/A.java
@@ -0,0 +1,25 @@
+/**
+ * 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.reef.tang.examples;
+
+import javax.inject.Inject;
+
+public class A {
+  @Inject public A() {}
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang-test-jarAB/src/main/java/org/apache/reef/tang/examples/B.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang-test-jarAB/src/main/java/org/apache/reef/tang/examples/B.java b/lang/java/reef-tang/tang-test-jarAB/src/main/java/org/apache/reef/tang/examples/B.java
new file mode 100644
index 0000000..991461f
--- /dev/null
+++ b/lang/java/reef-tang/tang-test-jarAB/src/main/java/org/apache/reef/tang/examples/B.java
@@ -0,0 +1,25 @@
+/**
+ * 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.reef.tang.examples;
+
+import javax.inject.Inject;
+
+public class B extends A {
+  @Inject public B() { }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang-test-jarB-conflictA/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang-test-jarB-conflictA/pom.xml b/lang/java/reef-tang/tang-test-jarB-conflictA/pom.xml
new file mode 100644
index 0000000..860cecd
--- /dev/null
+++ b/lang/java/reef-tang/tang-test-jarB-conflictA/pom.xml
@@ -0,0 +1,31 @@
+<?xml version="1.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.
+-->
+<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.reef</groupId>
+        <artifactId>tang-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>tang-test-jarB-conflictA</artifactId>
+    <name>Tang Test Jar B conflict A</name>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang-test-jarB/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang-test-jarB/pom.xml b/lang/java/reef-tang/tang-test-jarB/pom.xml
new file mode 100644
index 0000000..15025c2
--- /dev/null
+++ b/lang/java/reef-tang/tang-test-jarB/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.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.
+-->
+<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.reef</groupId>
+        <artifactId>tang-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>tang-test-jarB</artifactId>
+    <name>Tang Test Jar B</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>tang-test-jarA</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang-test-jarB/src/main/java/org/apache/reef/tang/examples/B.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang-test-jarB/src/main/java/org/apache/reef/tang/examples/B.java b/lang/java/reef-tang/tang-test-jarB/src/main/java/org/apache/reef/tang/examples/B.java
new file mode 100644
index 0000000..5b44ca7
--- /dev/null
+++ b/lang/java/reef-tang/tang-test-jarB/src/main/java/org/apache/reef/tang/examples/B.java
@@ -0,0 +1,23 @@
+/**
+ * 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.reef.tang.examples;
+
+public class B extends A {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/.gitignore
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/.gitignore b/lang/java/reef-tang/tang/.gitignore
new file mode 100644
index 0000000..1a0e03a
--- /dev/null
+++ b/lang/java/reef-tang/tang/.gitignore
@@ -0,0 +1,2 @@
+type-hierarchy.*
+injection-plan.*

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/maven-eclipse.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/maven-eclipse.xml b/lang/java/reef-tang/tang/maven-eclipse.xml
new file mode 100644
index 0000000..6c6b5ae
--- /dev/null
+++ b/lang/java/reef-tang/tang/maven-eclipse.xml
@@ -0,0 +1,28 @@
+<!--
+
+    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 default="copy-resources">
+  <target name="init"/>
+  <target name="copy-resources" depends="init">
+    <copy todir="target/classes/META-INF/conf" filtering="false">
+      <fileset dir="src/main/conf" includes="*.xml|*.properties" excludes="**/*.java"/>
+    </copy>
+  </target>
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/pom.xml b/lang/java/reef-tang/tang/pom.xml
new file mode 100644
index 0000000..d8404c3
--- /dev/null
+++ b/lang/java/reef-tang/tang/pom.xml
@@ -0,0 +1,171 @@
+<?xml version="1.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.
+-->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+         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.reef</groupId>
+        <artifactId>tang-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>tang</artifactId>
+    <name>REEF Tang</name>
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-antrun-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>generate-sources</id>
+                        <phase>generate-sources</phase>
+                        <configuration>
+                            <tasks>
+                                <mkdir dir="target/generated-sources/proto"/>
+                                <exec executable="protoc">
+                                    <arg value="--proto_path=src/main/proto/"/>
+                                    <arg value="--java_out=target/generated-sources/proto"/>
+                                    <arg value="src/main/proto/injection_plan.proto"/>
+                                    <arg value="src/main/proto/class_hierarchy.proto"/>
+                                </exec>
+                            </tasks>
+                            <sourceRoot>target/generated-sources/proto</sourceRoot>
+                        </configuration>
+                        <goals>
+                            <goal>run</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>add-source</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>target/generated-sources/proto</source>
+                            </sources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <configuration>
+                    <descriptorRefs>
+                        <descriptorRef>jar-with-dependencies</descriptorRef>
+                    </descriptorRefs>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.avro</groupId>
+                <artifactId>avro-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>schema</goal>
+                        </goals>
+                        <configuration>
+                            <sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory>
+                            <outputDirectory>${project.basedir}/target/generated-sources/avro/</outputDirectory>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.rat</groupId>
+                <artifactId>apache-rat-plugin</artifactId>
+                <configuration>
+                    <excludes>
+                        <!-- The following binary files are generated from the sources and shouldn't be checked -->
+                        <exclude>src/test/resources/Event.bin</exclude>
+                        <exclude>src/test/resources/Task.bin</exclude>
+
+                    </excludes>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.google.protobuf</groupId>
+            <artifactId>protobuf-java</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-configuration</groupId>
+            <artifactId>commons-configuration</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-cli</groupId>
+            <artifactId>commons-cli</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>javax.inject</groupId>
+            <artifactId>javax.inject</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.reflections</groupId>
+            <artifactId>reflections</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.avro</groupId>
+            <artifactId>avro</artifactId>
+        </dependency>
+    </dependencies>
+
+    <profiles>
+        <profile>
+            <id>PrintTypeHierarchy</id>
+            <build>
+                <defaultGoal>exec:exec</defaultGoal>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <configuration>
+                            <executable>java</executable>
+                            <arguments>
+                                <argument>-classpath</argument>
+                                <classpath/>
+                                <argument>org.apache.reef.tang.examples.PrintTypeHierarchy</argument>
+                            </arguments>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/avro/configuration.avsc
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/avro/configuration.avsc b/lang/java/reef-tang/tang/src/main/avro/configuration.avsc
new file mode 100644
index 0000000..4a7b4f9
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/avro/configuration.avsc
@@ -0,0 +1,37 @@
+/**
+ * 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.
+ */
+ [
+{
+    "namespace":"org.apache.reef.tang.formats.avro",
+    "type":"record",
+    "name":"ConfigurationEntry",
+    "fields":[
+	{"name":"key","type":"string"},
+	{"name":"value","type":"string"}
+    ]
+},
+{
+    "namespace":"org.apache.reef.tang.formats.avro",
+    "type":"record",
+    "name":"AvroConfiguration",
+    "fields":[
+	{"name":"Bindings","type":{"type":"array", "items":"ConfigurationEntry"}}
+    ]
+}
+]

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Aspect.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Aspect.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Aspect.java
new file mode 100644
index 0000000..5ddb1e2
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Aspect.java
@@ -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.reef.tang;
+
+import org.apache.reef.tang.types.ConstructorDef;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * A simple interface that allows external code to interpose on Tang object
+ * injections.  This can be used to implement simplistic aspect oriented
+ * design patterns by interposing wrapper objects at injection time.  It
+ * can also be used for more mundane purposes, such as tracking the
+ * relationship between the objects that are instantiated at runtime.
+ * <p/>
+ * The Wake project contains a full-featured implementation of this API that
+ * may serve as a useful example.
+ */
+public interface Aspect {
+  /**
+   * Inject an object of type T.
+   * <p/>
+   * Note that it is never OK to return an instance of ExternalConstructor.
+   * Typical implementations check to see if they are about to return an
+   * instance of ExternalConstructor.  If so, they return ret.newInstance()
+   * instead.
+   *
+   * @param def         information about the constructor to be invoked.  This is
+   *                    mostly useful because it contains references to any relevant named
+   *                    parameters, and to the class to be injected.
+   * @param constructor The java constructor to be injected.  Tang automatically
+   *                    chooses the appropriate constructor and ensures that we have permission
+   *                    to invoke it.
+   * @param args        The parameters to be passed into constructor.newInstance(), in the correct order.
+   * @return A new instance of T.
+   * Note, it is inject()'s responsibility to call <tt>ret.getInstance() if ret instanceof ExternalConstructor</tt>.
+   * @throws A number of exceptions which are passed-through from the wrapped call to newInstance().
+   */
+  <T> T inject(ConstructorDef<T> def, Constructor<T> constructor, Object[] args) throws InvocationTargetException, IllegalAccessException, IllegalArgumentException, InstantiationException;
+
+  /**
+   * TANG calls this the first time get() is called on an injection future.  This informs the aspect of
+   * the relationship between InjectionFutures (that were already passed into inject()) and the instantiated
+   * object.
+   *
+   * @param f An InjectionFuture that was passed to the args[] array of inject at some point in the past.
+   * @param t An object instance that was returned by inject().
+   */
+  <T> void injectionFutureInstantiated(InjectionFuture<T> f, T t);
+
+  /**
+   * This method creates a child aspect, and returns it.  This allows aspects to track information about
+   * Tang injection scopes.  If such information is not needed, it is legal for Aspect implementations to
+   * return "this".
+   */
+  Aspect createChildAspect();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/BindLocation.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/BindLocation.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/BindLocation.java
new file mode 100644
index 0000000..5e0829e
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/BindLocation.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.tang;
+
+/**
+ * This interface is used to track the source of configuration bindings.
+ * <p/>
+ * This can be explicitly set (such as by configuration file parsers), or be
+ * implicitly bound to the stack trace of bind() invocation.
+ */
+public interface BindLocation {
+  /**
+   * Implementations of BindLocation should override toString() so that it
+   * returns a human readable representation of the source of the
+   * configuration option in question.
+   *
+   * @return A (potentially multi-line) string that represents the stack
+   * trace, configuration file location, or other source of some
+   * configuration data.
+   */
+  public abstract String toString();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/ClassHierarchy.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/ClassHierarchy.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/ClassHierarchy.java
new file mode 100644
index 0000000..4ef4cc6
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/ClassHierarchy.java
@@ -0,0 +1,86 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.exceptions.NameResolutionException;
+import org.apache.reef.tang.types.ClassNode;
+import org.apache.reef.tang.types.Node;
+
+/**
+ * ClassHierarchy objects store information about the interfaces
+ * and implementations that are available in a particular runtime
+ * environment.
+ * <p/>
+ * When Tang is running inside the same environment as the injected
+ * objects, ClassHierarchy is simply a read-only representation of
+ * information that is made available via language reflection.
+ * <p/>
+ * If Tang is set up to perform remote injection, then the ClassHierarchy
+ * it runs against is backed by a flat file, or other summary of the
+ * libraries that will be available during injection.
+ */
+public interface ClassHierarchy {
+  /**
+   * Lookup a node in this class hierarchy.
+   *
+   * @param fullName The full name of the class that will be looked up.
+   * @return A non-null reference to a ClassNode or a NamedParameterNode.
+   * @throws NameResolutionException If the class is not found.
+   * @throws ClassHierarchyException If the class does not pass Tang's static analysis.
+   */
+  public Node getNode(String fullName) throws NameResolutionException;
+
+  /**
+   * @return true if impl is a subclass of inter.
+   */
+  public boolean isImplementation(ClassNode<?> inter, ClassNode<?> impl);
+
+  /**
+   * Merge the contents of this ClassHierarchy and the provided one into a new
+   * class hierarchy.  This allows reflection information from multiple jars to
+   * be incorporated into a single ClassHierarchy object.  Typical applications
+   * do not call this method, and instead provide classpath (or C# assembly)
+   * information to Tang when they create ConfigurationBuilder and Configuration
+   * objects.  The Configuration API transparently invokes merge as necessary,
+   * allowing applications to combine configurations that were built against
+   * differing classpaths.
+   * <p/>
+   * ClassHierarchies derived from applications written in different languages
+   * cannot be merged.
+   */
+  public ClassHierarchy merge(ClassHierarchy ch);
+
+  /**
+   * Return a reference to the root of the ClassHierarchy.  This is needed by
+   * serialization routines (which have to iterate over the ClassHierarchy's
+   * state).  Unfortunately, due to limitations of Java, JavaClassHierarchy
+   * objects need to be built lazily as callers request classes by name.
+   * There is no way to provide an interface that enumerates known claases
+   * without exposing this fact; therefore, the Node returned by this method
+   * can change over time.
+   * <p/>
+   * Normal callers (all use cases except ClassHierarchy serialization)
+   * should use getNode(String) to lookup classes, since getNamespace() can
+   * not support lazy loading of unknown classes.
+   *
+   * @return a reference to the root node of this ClassHierarchy.
+   */
+  Node getNamespace();
+
+}
\ No newline at end of file


[30/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/pool/JobDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/pool/JobDriver.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/pool/JobDriver.java
new file mode 100644
index 0000000..653b240
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/pool/JobDriver.java
@@ -0,0 +1,306 @@
+/**
+ * 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.reef.examples.pool;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.CompletedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.driver.task.CompletedTask;
+import org.apache.reef.driver.task.RunningTask;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+import org.apache.reef.wake.time.event.StopTime;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Allocate N evaluators, submit M tasks to them, and measure the time.
+ * Each task does nothing but sleeps for D seconds.
+ */
+@Unit
+public final class JobDriver {
+
+  /**
+   * Standard Java logger.
+   */
+  private static final Logger LOG = Logger.getLogger(JobDriver.class.getName());
+
+  /**
+   * Job driver uses EvaluatorRequestor to request Evaluators that will run the Tasks.
+   */
+  private final EvaluatorRequestor evaluatorRequestor;
+
+  /**
+   * If true, submit context and task in one request.
+   */
+  private final boolean isPiggyback;
+
+  /**
+   * Number of Evaluators to request.
+   */
+  private final int numEvaluators;
+
+  /**
+   * Number of Tasks to run.
+   */
+  private final int numTasks;
+  /**
+   * Number of seconds to sleep in each Task.
+   * (has to be a String to pass it into Task config).
+   */
+  private final String delayStr;
+  /**
+   * Number of Evaluators started.
+   */
+  private int numEvaluatorsStarted = 0;
+  /**
+   * Number of Tasks launched.
+   */
+  private int numTasksStarted = 0;
+
+  /**
+   * Job driver constructor.
+   * All parameters are injected from TANG automatically.
+   *
+   * @param evaluatorRequestor is used to request Evaluators.
+   */
+  @Inject
+  JobDriver(final EvaluatorRequestor evaluatorRequestor,
+            final @Parameter(Launch.Piggyback.class) Boolean isPiggyback,
+            final @Parameter(Launch.NumEvaluators.class) Integer numEvaluators,
+            final @Parameter(Launch.NumTasks.class) Integer numTasks,
+            final @Parameter(Launch.Delay.class) Integer delay) {
+    this.evaluatorRequestor = evaluatorRequestor;
+    this.isPiggyback = isPiggyback;
+    this.numEvaluators = numEvaluators;
+    this.numTasks = numTasks;
+    this.delayStr = "" + delay;
+  }
+
+  /**
+   * Build a new Task configuration for a given task ID.
+   *
+   * @param taskId Unique string ID of the task
+   * @return Immutable task configuration object, ready to be submitted to REEF.
+   * @throws RuntimeException that wraps BindException if unable to build the configuration.
+   */
+  private Configuration getTaskConfiguration(final String taskId) {
+    try {
+      return TaskConfiguration.CONF
+          .set(TaskConfiguration.IDENTIFIER, taskId)
+          .set(TaskConfiguration.TASK, SleepTask.class)
+          .build();
+    } catch (final BindException ex) {
+      LOG.log(Level.SEVERE, "Failed to create  Task Configuration: " + taskId, ex);
+      throw new RuntimeException(ex);
+    }
+  }
+
+  /**
+   * Job Driver is ready and the clock is set up: request the evaluators.
+   */
+  final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime startTime) {
+      LOG.log(Level.INFO, "TIME: Start Driver with {0} Evaluators", numEvaluators);
+      evaluatorRequestor.submit(
+          EvaluatorRequest.newBuilder()
+              .setMemory(128)
+              .setNumberOfCores(1)
+              .setNumber(numEvaluators).build()
+      );
+    }
+  }
+
+  /**
+   * Job Driver is is shutting down: write to the log.
+   */
+  final class StopHandler implements EventHandler<StopTime> {
+    @Override
+    public void onNext(final StopTime stopTime) {
+      LOG.log(Level.INFO, "TIME: Stop Driver");
+    }
+  }
+
+  /**
+   * Receive notification that an Evaluator had been allocated,
+   * and submitTask a new Task in that Evaluator.
+   */
+  final class AllocatedEvaluatorHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator eval) {
+
+      LOG.log(Level.INFO, "TIME: Allocated Evaluator {0}", eval.getId());
+
+      final boolean runTask;
+      final int nEval;
+      final int nTask;
+
+      synchronized (JobDriver.this) {
+        runTask = numTasksStarted < numTasks;
+        if (runTask) {
+          ++numEvaluatorsStarted;
+          if (isPiggyback) {
+            ++numTasksStarted;
+          }
+        }
+        nEval = numEvaluatorsStarted;
+        nTask = numTasksStarted;
+      }
+
+      if (runTask) {
+
+        final String contextId = String.format("Context_%06d", nEval);
+        LOG.log(Level.INFO, "TIME: Submit Context {0} to Evaluator {1}",
+            new Object[]{contextId, eval.getId()});
+
+        try {
+
+          final JavaConfigurationBuilder contextConfigBuilder =
+              Tang.Factory.getTang().newConfigurationBuilder();
+
+          contextConfigBuilder.addConfiguration(ContextConfiguration.CONF
+              .set(ContextConfiguration.IDENTIFIER, contextId)
+              .build());
+
+          contextConfigBuilder.bindNamedParameter(Launch.Delay.class, delayStr);
+
+          if (isPiggyback) {
+
+            final String taskId = String.format("StartTask_%08d", nTask);
+            final Configuration taskConfig = getTaskConfiguration(taskId);
+
+            LOG.log(Level.INFO, "TIME: Submit Task {0} to Evaluator {1}",
+                new Object[]{taskId, eval.getId()});
+
+            eval.submitContextAndTask(contextConfigBuilder.build(), taskConfig);
+
+          } else {
+            eval.submitContext(contextConfigBuilder.build());
+          }
+
+        } catch (final BindException ex) {
+          LOG.log(Level.SEVERE, "Failed to submit Context to Evaluator: " + eval.getId(), ex);
+          throw new RuntimeException(ex);
+        }
+      } else {
+        LOG.log(Level.INFO, "TIME: Close Evaluator {0}", eval.getId());
+        eval.close();
+      }
+    }
+  }
+
+  /**
+   * Receive notification that the Context is active.
+   */
+  final class ActiveContextHandler implements EventHandler<ActiveContext> {
+    @Override
+    public void onNext(final ActiveContext context) {
+
+      LOG.log(Level.INFO, "TIME: Active Context {0}", context.getId());
+
+      if (isPiggyback) return; // Task already submitted
+
+      final boolean runTask;
+      final int nTask;
+
+      synchronized (JobDriver.this) {
+        runTask = numTasksStarted < numTasks;
+        if (runTask) {
+          ++numTasksStarted;
+        }
+        nTask = numTasksStarted;
+      }
+
+      if (runTask) {
+        final String taskId = String.format("StartTask_%08d", nTask);
+        LOG.log(Level.INFO, "TIME: Submit Task {0} to Evaluator {1}",
+            new Object[]{taskId, context.getEvaluatorId()});
+        context.submitTask(getTaskConfiguration(taskId));
+      } else {
+        context.close();
+      }
+    }
+  }
+
+  /**
+   * Receive notification that the Task is running.
+   */
+  final class RunningTaskHandler implements EventHandler<RunningTask> {
+    @Override
+    public void onNext(final RunningTask task) {
+      LOG.log(Level.INFO, "TIME: Running Task {0}", task.getId());
+    }
+  }
+
+  /**
+   * Receive notification that the Task has completed successfully.
+   */
+  final class CompletedTaskHandler implements EventHandler<CompletedTask> {
+    @Override
+    public void onNext(final CompletedTask task) {
+
+      final ActiveContext context = task.getActiveContext();
+      LOG.log(Level.INFO, "TIME: Completed Task {0} on Evaluator {1}",
+          new Object[]{task.getId(), context.getEvaluatorId()});
+
+      final boolean runTask;
+      final int nTask;
+      synchronized (JobDriver.this) {
+        runTask = numTasksStarted < numTasks;
+        if (runTask) {
+          ++numTasksStarted;
+        }
+        nTask = numTasksStarted;
+      }
+
+      if (runTask) {
+        final String taskId = String.format("Task_%08d", nTask);
+        LOG.log(Level.INFO, "TIME: Submit Task {0} to Evaluator {1}",
+            new Object[]{taskId, context.getEvaluatorId()});
+        context.submitTask(getTaskConfiguration(taskId));
+      } else {
+        LOG.log(Level.INFO, "TIME: Close Evaluator {0}", context.getEvaluatorId());
+        context.close();
+      }
+    }
+  }
+
+  /**
+   * Receive notification that the Evaluator has been shut down.
+   */
+  final class CompletedEvaluatorHandler implements EventHandler<CompletedEvaluator> {
+    @Override
+    public void onNext(final CompletedEvaluator eval) {
+      LOG.log(Level.INFO, "TIME: Completed Evaluator {0}", eval.getId());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/pool/Launch.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/pool/Launch.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/pool/Launch.java
new file mode 100644
index 0000000..af8f455
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/pool/Launch.java
@@ -0,0 +1,216 @@
+/**
+ * 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.reef.examples.pool;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.runtime.yarn.client.YarnClientConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.AvroConfigurationSerializer;
+import org.apache.reef.tang.formats.CommandLine;
+import org.apache.reef.util.EnvironmentUtils;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Pool of Evaluators example - main class.
+ */
+public final class Launch {
+
+  /**
+   * Number of REEF worker threads in local mode.
+   */
+  private static final int NUM_LOCAL_THREADS = 4;
+  /**
+   * Standard Java logger
+   */
+  private static final Logger LOG = Logger.getLogger(Launch.class.getName());
+
+  /**
+   * This class should not be instantiated.
+   */
+  private Launch() {
+    throw new RuntimeException("Do not instantiate this class!");
+  }
+
+  /**
+   * Parse the command line arguments.
+   *
+   * @param args command line arguments, as passed to main()
+   * @return Configuration object.
+   * @throws BindException configuration error.
+   * @throws IOException   error reading the configuration.
+   */
+  private static Configuration parseCommandLine(final String[] args)
+      throws BindException, IOException {
+    final JavaConfigurationBuilder confBuilder = Tang.Factory.getTang().newConfigurationBuilder();
+    final CommandLine cl = new CommandLine(confBuilder);
+    cl.registerShortNameOfClass(Local.class);
+    cl.registerShortNameOfClass(Piggyback.class);
+    cl.registerShortNameOfClass(NumEvaluators.class);
+    cl.registerShortNameOfClass(NumTasks.class);
+    cl.registerShortNameOfClass(Delay.class);
+    cl.registerShortNameOfClass(JobId.class);
+    cl.processCommandLine(args);
+    return confBuilder.build();
+  }
+
+  private static Configuration cloneCommandLineConfiguration(final Configuration commandLineConf)
+      throws InjectionException, BindException {
+    final Injector injector = Tang.Factory.getTang().newInjector(commandLineConf);
+    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindNamedParameter(Piggyback.class, String.valueOf(injector.getNamedInstance(Piggyback.class)));
+    cb.bindNamedParameter(NumEvaluators.class, String.valueOf(injector.getNamedInstance(NumEvaluators.class)));
+    cb.bindNamedParameter(NumTasks.class, String.valueOf(injector.getNamedInstance(NumTasks.class)));
+    cb.bindNamedParameter(Delay.class, String.valueOf(injector.getNamedInstance(Delay.class)));
+    return cb.build();
+  }
+
+  /**
+   * Parse command line arguments and create TANG configuration ready to be submitted to REEF.
+   *
+   * @param commandLineConf Parsed command line arguments, as passed into main().
+   * @return (immutable) TANG Configuration object.
+   * @throws BindException      if configuration commandLineInjector fails.
+   * @throws InjectionException if configuration commandLineInjector fails.
+   */
+  private static Configuration getClientConfiguration(
+      final Configuration commandLineConf, final boolean isLocal)
+      throws BindException, InjectionException {
+    final Configuration runtimeConfiguration;
+    if (isLocal) {
+      LOG.log(Level.FINE, "Running on the local runtime");
+      runtimeConfiguration = LocalRuntimeConfiguration.CONF
+          .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, NUM_LOCAL_THREADS)
+          .build();
+    } else {
+      LOG.log(Level.FINE, "Running on YARN");
+      runtimeConfiguration = YarnClientConfiguration.CONF.build();
+    }
+    return Tang.Factory.getTang().newConfigurationBuilder(
+        runtimeConfiguration, cloneCommandLineConfiguration(commandLineConf))
+        .build();
+  }
+
+  /**
+   * Main method that launches the REEF job.
+   *
+   * @param args command line parameters.
+   */
+  public static void main(final String[] args) {
+
+    try {
+
+      final Configuration commandLineConf = parseCommandLine(args);
+      final Injector injector = Tang.Factory.getTang().newInjector(commandLineConf);
+
+      final boolean isLocal = injector.getNamedInstance(Local.class);
+      final int numEvaluators = injector.getNamedInstance(NumEvaluators.class);
+      final int numTasks = injector.getNamedInstance(NumTasks.class);
+      final int delay = injector.getNamedInstance(Delay.class);
+      final int jobNum = injector.getNamedInstance(JobId.class);
+
+      final String jobId = String.format("pool.e_%d.a_%d.d_%d.%d",
+          numEvaluators, numTasks, delay, jobNum < 0 ? System.currentTimeMillis() : jobNum);
+
+      // Timeout: delay + 6 extra seconds per Task per Evaluator + 2 minutes to allocate each Evaluator:
+      final int timeout = numTasks * (delay + 6) * 1000 / numEvaluators + numEvaluators * 120000;
+
+      final Configuration runtimeConfig = getClientConfiguration(commandLineConf, isLocal);
+      LOG.log(Level.INFO, "TIME: Start Client {0} with timeout {1} sec. Configuration:\n--\n{2}--",
+          new Object[]{jobId, timeout / 1000, new AvroConfigurationSerializer().toString(runtimeConfig)});
+
+      final Configuration driverConfig = DriverConfiguration.CONF
+          .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(JobDriver.class))
+          .set(DriverConfiguration.DRIVER_IDENTIFIER, jobId)
+          .set(DriverConfiguration.ON_DRIVER_STARTED, JobDriver.StartHandler.class)
+          .set(DriverConfiguration.ON_DRIVER_STOP, JobDriver.StopHandler.class)
+          .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, JobDriver.AllocatedEvaluatorHandler.class)
+          .set(DriverConfiguration.ON_CONTEXT_ACTIVE, JobDriver.ActiveContextHandler.class)
+          .set(DriverConfiguration.ON_TASK_RUNNING, JobDriver.RunningTaskHandler.class)
+          .set(DriverConfiguration.ON_TASK_COMPLETED, JobDriver.CompletedTaskHandler.class)
+          .set(DriverConfiguration.ON_EVALUATOR_COMPLETED, JobDriver.CompletedEvaluatorHandler.class)
+          .build();
+
+      final Configuration submittedConfiguration = Tang.Factory.getTang()
+          .newConfigurationBuilder(driverConfig, commandLineConf).build();
+      DriverLauncher.getLauncher(runtimeConfig)
+          .run(submittedConfiguration, timeout);
+
+      LOG.log(Level.INFO, "TIME: Stop Client {0}", jobId);
+
+    } catch (final BindException | InjectionException | IOException ex) {
+      LOG.log(Level.SEVERE, "Job configuration error", ex);
+    }
+  }
+
+  /**
+   * Command line parameter: number of Evaluators to request.
+   */
+  @NamedParameter(doc = "Number of evaluators to request", short_name = "evaluators")
+  public static final class NumEvaluators implements Name<Integer> {
+  }
+
+  /**
+   * Command line parameter: number of Tasks to run.
+   */
+  @NamedParameter(doc = "Number of tasks to run", short_name = "tasks")
+  public static final class NumTasks implements Name<Integer> {
+  }
+
+  /**
+   * Command line parameter: number of experiments to run.
+   */
+  @NamedParameter(doc = "Number of seconds to sleep in each task", short_name = "delay")
+  public static final class Delay implements Name<Integer> {
+  }
+
+  /**
+   * Command line parameter = true to submit task and context in one request.
+   */
+  @NamedParameter(doc = "Submit task and context together",
+      short_name = "piggyback", default_value = "true")
+  public static final class Piggyback implements Name<Boolean> {
+  }
+
+  /**
+   * Command line parameter = true to run locally, or false to run on YARN.
+   */
+  @NamedParameter(doc = "Whether or not to run on the local runtime",
+      short_name = "local", default_value = "true")
+  public static final class Local implements Name<Boolean> {
+  }
+
+  /**
+   * Command line parameter = Numeric ID for the job.
+   */
+  @NamedParameter(doc = "Numeric ID for the job", short_name = "id", default_value = "-1")
+  public static final class JobId implements Name<Integer> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/pool/SleepTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/pool/SleepTask.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/pool/SleepTask.java
new file mode 100644
index 0000000..1bd2059
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/pool/SleepTask.java
@@ -0,0 +1,73 @@
+/**
+ * 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.reef.examples.pool;
+
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.task.Task;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Sleep for delay seconds and quit.
+ */
+public class SleepTask implements Task {
+
+  /**
+   * Standard java logger.
+   */
+  private static final Logger LOG = Logger.getLogger(SleepTask.class.getName());
+
+  /**
+   * Number of milliseconds to sleep.
+   */
+  private final int delay;
+
+  /**
+   * Task constructor. Parameters are injected automatically by TANG.
+   *
+   * @param delay number of seconds to sleep.
+   */
+  @Inject
+  private SleepTask(final @Parameter(Launch.Delay.class) Integer delay) {
+    this.delay = delay * 1000;
+  }
+
+  /**
+   * Sleep for delay milliseconds and return.
+   *
+   * @param memento ignored.
+   * @return null.
+   */
+  @Override
+  public byte[] call(final byte[] memento) {
+    LOG.log(Level.FINE, "Task started: sleep for: {0} msec.", this.delay);
+    final long ts = System.currentTimeMillis();
+    for (long period = this.delay; period > 0; period -= System.currentTimeMillis() - ts) {
+      try {
+        Thread.sleep(period);
+      } catch (final InterruptedException ex) {
+        LOG.log(Level.FINEST, "Interrupted: {0}", ex);
+      }
+    }
+    LOG.log(Level.FINE, "Task finished after {0} msec.", System.currentTimeMillis() - ts);
+    return null;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/pool/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/pool/package-info.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/pool/package-info.java
new file mode 100644
index 0000000..e67c862
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/pool/package-info.java
@@ -0,0 +1,23 @@
+/**
+ * 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.
+ */
+/**
+ * Allocate N evaluators, submit M tasks to them, and measure the time.
+ * Each task does nothing but sleeps for D seconds.
+ */
+package org.apache.reef.examples.pool;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/JobClient.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/JobClient.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/JobClient.java
new file mode 100644
index 0000000..61d549d
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/JobClient.java
@@ -0,0 +1,335 @@
+/**
+ * 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.reef.examples.retained_eval;
+
+import org.apache.reef.client.*;
+import org.apache.reef.examples.library.Command;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.util.EnvironmentUtils;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+
+import javax.inject.Inject;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Retained Evaluator Shell Client.
+ */
+@Unit
+public class JobClient {
+
+  /**
+   * Standard java logger.
+   */
+  private static final Logger LOG = Logger.getLogger(JobClient.class.getName());
+
+  /**
+   * Codec to translate messages to and from the job driver
+   */
+  private static final ObjectSerializableCodec<String> CODEC = new ObjectSerializableCodec<>();
+
+  /**
+   * Reference to the REEF framework.
+   * This variable is injected automatically in the constructor.
+   */
+  private final REEF reef;
+
+  /**
+   * Shell command to submitTask to the job driver.
+   */
+  private final String command;
+
+  /**
+   * Job Driver configuration.
+   */
+  private final Configuration driverConfiguration;
+
+  /**
+   * If true, take commands from stdin; otherwise, use -cmd parameter in batch mode.
+   */
+  private final boolean isInteractive;
+
+  /**
+   * Total number of experiments to run.
+   */
+  private final int maxRuns;
+
+  /**
+   * Command prompt reader for the interactive mode (stdin).
+   */
+  private final BufferedReader prompt;
+
+  /**
+   * A reference to the running job that allows client to send messages back to the job driver
+   */
+  private RunningJob runningJob;
+
+  /**
+   * Start timestamp of the current task.
+   */
+  private long startTime = 0;
+
+  /**
+   * Total time spent performing tasks in Evaluators.
+   */
+  private long totalTime = 0;
+
+  /**
+   * Number of experiments ran so far.
+   */
+  private int numRuns = 0;
+
+  /**
+   * Set to false when job driver is done.
+   */
+  private boolean isBusy = true;
+
+  /**
+   * Last result returned from the job driver.
+   */
+  private String lastResult;
+
+  /**
+   * Retained Evaluator client.
+   * Parameters are injected automatically by TANG.
+   *
+   * @param command Shell command to run on each Evaluator.
+   * @param reef    Reference to the REEF framework.
+   */
+  @Inject
+  JobClient(final REEF reef,
+            @Parameter(Command.class) final String command,
+            @Parameter(Launch.NumRuns.class) final Integer numRuns,
+            @Parameter(Launch.NumEval.class) final Integer numEvaluators) throws BindException {
+
+    this.reef = reef;
+    this.command = command;
+    this.maxRuns = numRuns;
+
+    // If command is not set, switch to interactive mode. (Yes, we compare pointers here)
+    this.isInteractive = this.command ==
+        Command.class.getAnnotation(NamedParameter.class).default_value();
+
+    this.prompt = this.isInteractive ?
+        new BufferedReader(new InputStreamReader(System.in)) : null;
+
+    final JavaConfigurationBuilder configBuilder = Tang.Factory.getTang().newConfigurationBuilder();
+    configBuilder.addConfiguration(
+        DriverConfiguration.CONF
+            .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(JobDriver.class))
+            .set(DriverConfiguration.DRIVER_IDENTIFIER, "eval-" + System.currentTimeMillis())
+            .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, JobDriver.AllocatedEvaluatorHandler.class)
+            .set(DriverConfiguration.ON_EVALUATOR_FAILED, JobDriver.FailedEvaluatorHandler.class)
+            .set(DriverConfiguration.ON_CONTEXT_ACTIVE, JobDriver.ActiveContextHandler.class)
+            .set(DriverConfiguration.ON_CONTEXT_CLOSED, JobDriver.ClosedContextHandler.class)
+            .set(DriverConfiguration.ON_CONTEXT_FAILED, JobDriver.FailedContextHandler.class)
+            .set(DriverConfiguration.ON_TASK_COMPLETED, JobDriver.CompletedTaskHandler.class)
+            .set(DriverConfiguration.ON_CLIENT_MESSAGE, JobDriver.ClientMessageHandler.class)
+            .set(DriverConfiguration.ON_DRIVER_STARTED, JobDriver.StartHandler.class)
+            .set(DriverConfiguration.ON_DRIVER_STOP, JobDriver.StopHandler.class)
+            .build()
+    );
+    configBuilder.bindNamedParameter(Launch.NumEval.class, "" + numEvaluators);
+    this.driverConfiguration = configBuilder.build();
+  }
+
+  /**
+   * @return a Configuration binding the ClientConfiguration.* event handlers to this Client.
+   */
+  public static Configuration getClientConfiguration() {
+    return ClientConfiguration.CONF
+        .set(ClientConfiguration.ON_JOB_RUNNING, JobClient.RunningJobHandler.class)
+        .set(ClientConfiguration.ON_JOB_MESSAGE, JobClient.JobMessageHandler.class)
+        .set(ClientConfiguration.ON_JOB_COMPLETED, JobClient.CompletedJobHandler.class)
+        .set(ClientConfiguration.ON_JOB_FAILED, JobClient.FailedJobHandler.class)
+        .set(ClientConfiguration.ON_RUNTIME_ERROR, JobClient.RuntimeErrorHandler.class)
+        .build();
+  }
+
+  /**
+   * Launch the job driver.
+   *
+   * @throws BindException configuration error.
+   */
+  public void submit() {
+    this.reef.submit(this.driverConfiguration);
+  }
+
+  /**
+   * Send command to the job driver. Record timestamp when the command was sent.
+   * If this.command is set, use it; otherwise, ask user for the command.
+   */
+  private synchronized void submitTask() {
+    if (this.isInteractive) {
+      String cmd;
+      try {
+        do {
+          System.out.print("\nRE> ");
+          cmd = this.prompt.readLine();
+        } while (cmd != null && cmd.trim().isEmpty());
+      } catch (final IOException ex) {
+        LOG.log(Level.FINE, "Error reading from stdin: {0}", ex);
+        cmd = null;
+      }
+      if (cmd == null || cmd.equals("exit")) {
+        this.runningJob.close();
+        stopAndNotify();
+      } else {
+        this.submitTask(cmd);
+      }
+    } else {
+      // non-interactive batch mode:
+      this.submitTask(this.command);
+    }
+  }
+
+  /**
+   * Send command to the job driver. Record timestamp when the command was sent.
+   *
+   * @param cmd shell command to execute in all Evaluators.
+   */
+  private synchronized void submitTask(final String cmd) {
+    LOG.log(Level.FINE, "Submit task {0} \"{1}\" to {2}",
+        new Object[]{this.numRuns + 1, cmd, this.runningJob});
+    this.startTime = System.currentTimeMillis();
+    this.runningJob.send(CODEC.encode(cmd));
+  }
+
+  /**
+   * Notify the process in waitForCompletion() method that the main process has finished.
+   */
+  private synchronized void stopAndNotify() {
+    this.runningJob = null;
+    this.isBusy = false;
+    this.notify();
+  }
+
+  /**
+   * Wait for the job driver to complete. This method is called from Launch.main()
+   */
+  public String waitForCompletion() {
+    while (this.isBusy) {
+      LOG.log(Level.FINE, "Waiting for the Job Driver to complete.");
+      try {
+        synchronized (this) {
+          this.wait();
+        }
+      } catch (final InterruptedException ex) {
+        LOG.log(Level.WARNING, "Waiting for result interrupted.", ex);
+      }
+    }
+    return this.lastResult;
+  }
+
+  public void close() {
+    this.reef.close();
+  }
+
+  /**
+   * Receive notification from the job driver that the job is running.
+   */
+  final class RunningJobHandler implements EventHandler<RunningJob> {
+    @Override
+    public void onNext(final RunningJob job) {
+      LOG.log(Level.FINE, "Running job: {0}", job.getId());
+      synchronized (JobClient.this) {
+        JobClient.this.runningJob = job;
+        JobClient.this.submitTask();
+      }
+    }
+  }
+
+  /**
+   * Receive message from the job driver.
+   * There is only one message, which comes at the end of the driver execution
+   * and contains shell command output on each node.
+   */
+  final class JobMessageHandler implements EventHandler<JobMessage> {
+    @Override
+    public void onNext(final JobMessage message) {
+      synchronized (JobClient.this) {
+
+        lastResult = CODEC.decode(message.get());
+        final long jobTime = System.currentTimeMillis() - startTime;
+        totalTime += jobTime;
+        ++numRuns;
+
+        LOG.log(Level.FINE, "TIME: Task {0} completed in {1} msec.:\n{2}",
+            new Object[]{"" + numRuns, "" + jobTime, lastResult});
+
+        System.out.println(lastResult);
+
+        if (runningJob != null) {
+          if (isInteractive || numRuns < maxRuns) {
+            submitTask();
+          } else {
+            LOG.log(Level.INFO,
+                "All {0} tasks complete; Average task time: {1}. Closing the job driver.",
+                new Object[]{maxRuns, totalTime / (double) maxRuns});
+            runningJob.close();
+            stopAndNotify();
+          }
+        }
+      }
+    }
+  }
+
+  /**
+   * Receive notification from the job driver that the job had failed.
+   */
+  final class FailedJobHandler implements EventHandler<FailedJob> {
+    @Override
+    public void onNext(final FailedJob job) {
+      LOG.log(Level.SEVERE, "Failed job: " + job.getId(), job.getReason().orElse(null));
+      stopAndNotify();
+    }
+  }
+
+  /**
+   * Receive notification from the job driver that the job had completed successfully.
+   */
+  final class CompletedJobHandler implements EventHandler<CompletedJob> {
+    @Override
+    public void onNext(final CompletedJob job) {
+      LOG.log(Level.FINE, "Completed job: {0}", job.getId());
+      stopAndNotify();
+    }
+  }
+
+  /**
+   * Receive notification that there was an exception thrown from the job driver.
+   */
+  final class RuntimeErrorHandler implements EventHandler<FailedRuntime> {
+    @Override
+    public void onNext(final FailedRuntime error) {
+      LOG.log(Level.SEVERE, "Error in job driver: " + error, error.getReason().orElse(null));
+      stopAndNotify();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/JobDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/JobDriver.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/JobDriver.java
new file mode 100644
index 0000000..b2b2055
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/JobDriver.java
@@ -0,0 +1,370 @@
+/**
+ * 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.reef.examples.retained_eval;
+
+import org.apache.reef.driver.client.JobMessageObserver;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ClosedContext;
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.driver.evaluator.FailedEvaluator;
+import org.apache.reef.driver.task.CompletedTask;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.examples.library.Command;
+import org.apache.reef.examples.library.ShellTask;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+import org.apache.reef.wake.time.event.StartTime;
+import org.apache.reef.wake.time.event.StopTime;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Retained Evaluator example job driver. Execute shell command on all evaluators,
+ * capture stdout, and return concatenated results back to the client.
+ */
+@Unit
+public final class JobDriver {
+  /**
+   * Standard Java logger.
+   */
+  private static final Logger LOG = Logger.getLogger(JobDriver.class.getName());
+
+  /**
+   * Duration of one clock interval.
+   */
+  private static final int CHECK_UP_INTERVAL = 1000; // 1 sec.
+
+  /**
+   * String codec is used to encode the results
+   * before passing them back to the client.
+   */
+  private static final ObjectSerializableCodec<String> CODEC = new ObjectSerializableCodec<>();
+  /**
+   * Job observer on the client.
+   * We use it to send results from the driver back to the client.
+   */
+  private final JobMessageObserver jobMessageObserver;
+  /**
+   * Job driver uses EvaluatorRequestor
+   * to request Evaluators that will run the Tasks.
+   */
+  private final EvaluatorRequestor evaluatorRequestor;
+  /**
+   * Number of Evalutors to request (default is 1).
+   */
+  private final int numEvaluators;
+  /**
+   * Shell execution results from each Evaluator.
+   */
+  private final List<String> results = new ArrayList<>();
+  /**
+   * Map from context ID to running evaluator context.
+   */
+  private final Map<String, ActiveContext> contexts = new HashMap<>();
+  /**
+   * Job driver state.
+   */
+  private State state = State.INIT;
+  /**
+   * First command to execute. Sometimes client can send us the first command
+   * before Evaluators are available; we need to store this command here.
+   */
+  private String cmd;
+  /**
+   * Number of evaluators/tasks to complete.
+   */
+  private int expectCount = 0;
+
+  /**
+   * Job driver constructor.
+   * All parameters are injected from TANG automatically.
+   *
+   * @param jobMessageObserver is used to send messages back to the client.
+   * @param evaluatorRequestor is used to request Evaluators.
+   */
+  @Inject
+  JobDriver(final JobMessageObserver jobMessageObserver,
+            final EvaluatorRequestor evaluatorRequestor,
+            final @Parameter(Launch.NumEval.class) Integer numEvaluators) {
+    this.jobMessageObserver = jobMessageObserver;
+    this.evaluatorRequestor = evaluatorRequestor;
+    this.numEvaluators = numEvaluators;
+  }
+
+  /**
+   * Construct the final result and forward it to the Client.
+   */
+  private void returnResults() {
+    final StringBuilder sb = new StringBuilder();
+    for (final String result : this.results) {
+      sb.append(result);
+    }
+    this.results.clear();
+    LOG.log(Level.INFO, "Return results to the client:\n{0}", sb);
+    this.jobMessageObserver.sendMessageToClient(CODEC.encode(sb.toString()));
+  }
+
+  /**
+   * Submit command to all available evaluators.
+   *
+   * @param command shell command to execute.
+   */
+  private void submit(final String command) {
+    LOG.log(Level.INFO, "Submit command {0} to {1} evaluators. state: {2}",
+        new Object[]{command, this.contexts.size(), this.state});
+    assert (this.state == State.READY);
+    this.expectCount = this.contexts.size();
+    this.state = State.WAIT_TASKS;
+    this.cmd = null;
+    for (final ActiveContext context : this.contexts.values()) {
+      this.submit(context, command);
+    }
+  }
+
+  /**
+   * Submit a Task that execute the command to a single Evaluator.
+   * This method is called from <code>submitTask(cmd)</code>.
+   */
+  private void submit(final ActiveContext context, final String command) {
+    try {
+      LOG.log(Level.INFO, "Send command {0} to context: {1}", new Object[]{command, context});
+      final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+      cb.addConfiguration(
+          TaskConfiguration.CONF
+              .set(TaskConfiguration.IDENTIFIER, context.getId() + "_task")
+              .set(TaskConfiguration.TASK, ShellTask.class)
+              .build()
+      );
+      cb.bindNamedParameter(Command.class, command);
+      context.submitTask(cb.build());
+    } catch (final BindException ex) {
+      LOG.log(Level.SEVERE, "Bad Task configuration for context: " + context.getId(), ex);
+      context.close();
+      throw new RuntimeException(ex);
+    }
+  }
+
+  /**
+   * Request the evaluators.
+   */
+  private synchronized void requestEvaluators() {
+    assert (this.state == State.INIT);
+    LOG.log(Level.INFO, "Schedule on {0} Evaluators.", this.numEvaluators);
+    this.evaluatorRequestor.submit(
+        EvaluatorRequest.newBuilder()
+            .setMemory(128)
+            .setNumberOfCores(1)
+            .setNumber(this.numEvaluators).build()
+    );
+    this.state = State.WAIT_EVALUATORS;
+    this.expectCount = this.numEvaluators;
+  }
+
+  /**
+   * Possible states of the job driver. Can be one of:
+   * <dl>
+   * <du><code>INIT</code></du><dd>initial state, ready to request the evaluators.</dd>
+   * <du><code>WAIT_EVALUATORS</code></du><dd>Wait for requested evaluators to initialize.</dd>
+   * <du><code>READY</code></du><dd>Ready to submitTask a new task.</dd>
+   * <du><code>WAIT_TASKS</code></du><dd>Wait for tasks to complete.</dd>
+   * </dl>
+   */
+  private enum State {
+    INIT, WAIT_EVALUATORS, READY, WAIT_TASKS
+  }
+
+  /**
+   * Receive notification that an Evaluator had been allocated,
+   * and submitTask a new Task in that Evaluator.
+   */
+  final class AllocatedEvaluatorHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator eval) {
+      synchronized (JobDriver.this) {
+        LOG.log(Level.INFO, "Allocated Evaluator: {0} expect {1} running {2}",
+            new Object[]{eval.getId(), JobDriver.this.expectCount, JobDriver.this.contexts.size()});
+        assert (JobDriver.this.state == State.WAIT_EVALUATORS);
+        try {
+          eval.submitContext(ContextConfiguration.CONF.set(
+              ContextConfiguration.IDENTIFIER, eval.getId() + "_context").build());
+        } catch (final BindException ex) {
+          LOG.log(Level.SEVERE, "Failed to submit a context to evaluator: " + eval.getId(), ex);
+          throw new RuntimeException(ex);
+        }
+      }
+    }
+  }
+
+  /**
+   * Receive notification that the entire Evaluator had failed.
+   * Stop other jobs and pass this error to the job observer on the client.
+   */
+  final class FailedEvaluatorHandler implements EventHandler<FailedEvaluator> {
+    @Override
+    public void onNext(final FailedEvaluator eval) {
+      synchronized (JobDriver.this) {
+        LOG.log(Level.SEVERE, "FailedEvaluator", eval);
+        for (final FailedContext failedContext : eval.getFailedContextList()) {
+          JobDriver.this.contexts.remove(failedContext.getId());
+        }
+        throw new RuntimeException("Failed Evaluator: ", eval.getEvaluatorException());
+      }
+    }
+  }
+
+  /**
+   * Receive notification that a new Context is available.
+   * Submit a new Distributed Shell Task to that Context.
+   */
+  final class ActiveContextHandler implements EventHandler<ActiveContext> {
+    @Override
+    public void onNext(final ActiveContext context) {
+      synchronized (JobDriver.this) {
+        LOG.log(Level.INFO, "Context available: {0} expect {1} state {2}",
+            new Object[]{context.getId(), JobDriver.this.expectCount, JobDriver.this.state});
+        assert (JobDriver.this.state == State.WAIT_EVALUATORS);
+        JobDriver.this.contexts.put(context.getId(), context);
+        if (--JobDriver.this.expectCount <= 0) {
+          JobDriver.this.state = State.READY;
+          if (JobDriver.this.cmd == null) {
+            LOG.log(Level.INFO, "All evaluators ready; waiting for command. State: {0}",
+                JobDriver.this.state);
+          } else {
+            JobDriver.this.submit(JobDriver.this.cmd);
+          }
+        }
+      }
+    }
+  }
+
+  /**
+   * Receive notification that the Context had completed.
+   * Remove context from the list of active context.
+   */
+  final class ClosedContextHandler implements EventHandler<ClosedContext> {
+    @Override
+    public void onNext(final ClosedContext context) {
+      LOG.log(Level.INFO, "Completed Context: {0}", context.getId());
+      synchronized (JobDriver.this) {
+        JobDriver.this.contexts.remove(context.getId());
+      }
+    }
+  }
+
+  /**
+   * Receive notification that the Context had failed.
+   * Remove context from the list of active context and notify the client.
+   */
+  final class FailedContextHandler implements EventHandler<FailedContext> {
+    @Override
+    public void onNext(final FailedContext context) {
+      LOG.log(Level.SEVERE, "FailedContext", context);
+      synchronized (JobDriver.this) {
+        JobDriver.this.contexts.remove(context.getId());
+      }
+      throw new RuntimeException("Failed context: ", context.asError());
+    }
+  }
+
+  /**
+   * Receive notification that the Task has completed successfully.
+   */
+  final class CompletedTaskHandler implements EventHandler<CompletedTask> {
+    @Override
+    public void onNext(final CompletedTask task) {
+      LOG.log(Level.INFO, "Completed task: {0}", task.getId());
+      // Take the message returned by the task and add it to the running result.
+      final String result = CODEC.decode(task.get());
+      synchronized (JobDriver.this) {
+        JobDriver.this.results.add(task.getId() + " :: " + result);
+        LOG.log(Level.INFO, "Task {0} result {1}: {2} state: {3}", new Object[]{
+            task.getId(), JobDriver.this.results.size(), result, JobDriver.this.state});
+        if (--JobDriver.this.expectCount <= 0) {
+          JobDriver.this.returnResults();
+          JobDriver.this.state = State.READY;
+          if (JobDriver.this.cmd != null) {
+            JobDriver.this.submit(JobDriver.this.cmd);
+          }
+        }
+      }
+    }
+  }
+
+  /**
+   * Receive notification from the client.
+   */
+  final class ClientMessageHandler implements EventHandler<byte[]> {
+    @Override
+    public void onNext(final byte[] message) {
+      synchronized (JobDriver.this) {
+        final String command = CODEC.decode(message);
+        LOG.log(Level.INFO, "Client message: {0} state: {1}",
+            new Object[]{command, JobDriver.this.state});
+        assert (JobDriver.this.cmd == null);
+        if (JobDriver.this.state == State.READY) {
+          JobDriver.this.submit(command);
+        } else {
+          // not ready yet - save the command for better times.
+          assert (JobDriver.this.state == State.WAIT_EVALUATORS);
+          JobDriver.this.cmd = command;
+        }
+      }
+    }
+  }
+
+  /**
+   * Job Driver is ready and the clock is set up: request the evaluators.
+   */
+  final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime startTime) {
+      LOG.log(Level.INFO, "{0} StartTime: {1}", new Object[]{state, startTime});
+      assert (state == State.INIT);
+      requestEvaluators();
+    }
+  }
+
+  /**
+   * Shutting down the job driver: close the evaluators.
+   */
+  final class StopHandler implements EventHandler<StopTime> {
+    @Override
+    public void onNext(final StopTime time) {
+      LOG.log(Level.INFO, "{0} StopTime: {1}", new Object[]{state, time});
+      for (final ActiveContext context : contexts.values()) {
+        context.close();
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/Launch.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/Launch.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/Launch.java
new file mode 100644
index 0000000..cf230bc
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/Launch.java
@@ -0,0 +1,185 @@
+/**
+ * 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.reef.examples.retained_eval;
+
+import org.apache.reef.client.ClientConfiguration;
+import org.apache.reef.examples.library.Command;
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.runtime.yarn.client.YarnClientConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.AvroConfigurationSerializer;
+import org.apache.reef.tang.formats.CommandLine;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Retained Evaluators example - main class.
+ */
+public final class Launch {
+
+  /**
+   * Number of REEF worker threads in local mode.
+   */
+  private static final int NUM_LOCAL_THREADS = 4;
+  /**
+   * Standard Java logger
+   */
+  private static final Logger LOG = Logger.getLogger(Launch.class.getName());
+
+  /**
+   * This class should not be instantiated.
+   */
+  private Launch() {
+    throw new RuntimeException("Do not instantiate this class!");
+  }
+
+  /**
+   * Parse the command line arguments.
+   *
+   * @param args command line arguments, as passed to main()
+   * @return Configuration object.
+   * @throws BindException configuration error.
+   * @throws IOException   error reading the configuration.
+   */
+  private static Configuration parseCommandLine(final String[] args)
+      throws BindException, IOException {
+    final JavaConfigurationBuilder confBuilder = Tang.Factory.getTang().newConfigurationBuilder();
+    final CommandLine cl = new CommandLine(confBuilder);
+    cl.registerShortNameOfClass(Local.class);
+    cl.registerShortNameOfClass(Command.class);
+    cl.registerShortNameOfClass(NumRuns.class);
+    cl.registerShortNameOfClass(NumEval.class);
+    cl.processCommandLine(args);
+    return confBuilder.build();
+  }
+
+  private static Configuration cloneCommandLineConfiguration(final Configuration commandLineConf)
+      throws InjectionException, BindException {
+    final Injector injector = Tang.Factory.getTang().newInjector(commandLineConf);
+    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindNamedParameter(Command.class, injector.getNamedInstance(Command.class));
+    cb.bindNamedParameter(NumRuns.class, String.valueOf(injector.getNamedInstance(NumRuns.class)));
+    cb.bindNamedParameter(NumEval.class, String.valueOf(injector.getNamedInstance(NumEval.class)));
+    return cb.build();
+  }
+
+  /**
+   * Parse command line arguments and create TANG configuration ready to be submitted to REEF.
+   *
+   * @param args Command line arguments, as passed into main().
+   * @return (immutable) TANG Configuration object.
+   * @throws BindException      if configuration commandLineInjector fails.
+   * @throws InjectionException if configuration commandLineInjector fails.
+   * @throws IOException        error reading the configuration.
+   */
+  private static Configuration getClientConfiguration(final String[] args)
+      throws BindException, InjectionException, IOException {
+
+    final Configuration commandLineConf = parseCommandLine(args);
+
+    final Configuration clientConfiguration = ClientConfiguration.CONF
+        .set(ClientConfiguration.ON_JOB_RUNNING, JobClient.RunningJobHandler.class)
+        .set(ClientConfiguration.ON_JOB_MESSAGE, JobClient.JobMessageHandler.class)
+        .set(ClientConfiguration.ON_JOB_COMPLETED, JobClient.CompletedJobHandler.class)
+        .set(ClientConfiguration.ON_JOB_FAILED, JobClient.FailedJobHandler.class)
+        .set(ClientConfiguration.ON_RUNTIME_ERROR, JobClient.RuntimeErrorHandler.class)
+        .build();
+
+    // TODO: Remove the injector, have stuff injected.
+    final Injector commandLineInjector = Tang.Factory.getTang().newInjector(commandLineConf);
+    final boolean isLocal = commandLineInjector.getNamedInstance(Local.class);
+    final Configuration runtimeConfiguration;
+    if (isLocal) {
+      LOG.log(Level.INFO, "Running on the local runtime");
+      runtimeConfiguration = LocalRuntimeConfiguration.CONF
+          .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, NUM_LOCAL_THREADS)
+          .build();
+    } else {
+      LOG.log(Level.INFO, "Running on YARN");
+      runtimeConfiguration = YarnClientConfiguration.CONF.build();
+    }
+
+    return Tang.Factory.getTang()
+        .newConfigurationBuilder(runtimeConfiguration, clientConfiguration,
+            cloneCommandLineConfiguration(commandLineConf))
+        .build();
+  }
+
+  /**
+   * Main method that starts the Retained Evaluators job.
+   *
+   * @return a string that contains last results from all evaluators.
+   */
+  public static String run(final Configuration config) throws InjectionException {
+    final Injector injector = Tang.Factory.getTang().newInjector(config);
+    final JobClient client = injector.getInstance(JobClient.class);
+    client.submit();
+    return client.waitForCompletion();
+  }
+
+  /**
+   * Main method that starts the Retained Evaluators job.
+   *
+   * @param args command line parameters.
+   */
+  public static void main(final String[] args) {
+    try {
+      final Configuration config = getClientConfiguration(args);
+      LOG.log(Level.FINEST, "Configuration:\n--\n{0}--",
+          new AvroConfigurationSerializer().toString(config));
+      run(config);
+      LOG.info("Done!");
+    } catch (final BindException | InjectionException | IOException ex) {
+      LOG.log(Level.SEVERE, "Job configuration error", ex);
+    }
+  }
+
+  /**
+   * Command line parameter: number of experiments to run.
+   */
+  @NamedParameter(doc = "Number of times to run the command",
+      short_name = "num_runs", default_value = "1")
+  public static final class NumRuns implements Name<Integer> {
+  }
+
+  /**
+   * Command line parameter: number of evaluators to allocate.
+   */
+  @NamedParameter(doc = "Number of evaluators to request",
+      short_name = "num_eval", default_value = "1")
+  public static final class NumEval implements Name<Integer> {
+  }
+
+  /**
+   * Command line parameter = true to run locally, or false to run on YARN.
+   */
+  @NamedParameter(doc = "Whether or not to run on the local runtime",
+      short_name = "local", default_value = "true")
+  public static final class Local implements Name<Boolean> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/package-info.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/package-info.java
new file mode 100644
index 0000000..842b659
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/retained_eval/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * The Retained Evaluators example.
+ */
+package org.apache.reef.examples.retained_eval;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/Scheduler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/Scheduler.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/Scheduler.java
new file mode 100644
index 0000000..960f297
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/Scheduler.java
@@ -0,0 +1,226 @@
+/**
+ * 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.reef.examples.scheduler;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.examples.library.Command;
+import org.apache.reef.examples.library.ShellTask;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Configurations;
+import org.apache.reef.tang.Tang;
+
+import javax.annotation.concurrent.ThreadSafe;
+import javax.inject.Inject;
+import java.util.*;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * The body of Task scheduler. It owns a task queue
+ * and tracks the record of scheduled tasks.
+ */
+@ThreadSafe
+final class Scheduler {
+  /**
+   * Tasks are waiting to be scheduled in the queue.
+   */
+  private final Queue<TaskEntity> taskQueue;
+
+  /**
+   * Lists of {@link TaskEntity} for different states - Running / Finished / Canceled.
+   */
+  private final List<TaskEntity> runningTasks = new ArrayList<>();
+  private final List<TaskEntity> finishedTasks = new ArrayList<>();
+  private final List<TaskEntity> canceledTasks = new ArrayList<>();
+
+  /**
+   * Counts how many tasks have been scheduled.
+   */
+  private final AtomicInteger taskCount = new AtomicInteger(0);
+
+  @Inject
+  public Scheduler() {
+    taskQueue = new LinkedBlockingQueue<>();
+  }
+
+  /**
+   * Submit a task to the ActiveContext.
+   */
+  public synchronized void submitTask(final ActiveContext context) {
+    final TaskEntity task = taskQueue.poll();
+    final Integer taskId = task.getId();
+    final String command = task.getCommand();
+
+    final Configuration taskConf = TaskConfiguration.CONF
+      .set(TaskConfiguration.TASK, ShellTask.class)
+      .set(TaskConfiguration.IDENTIFIER, taskId.toString())
+      .build();
+    final Configuration commandConf = Tang.Factory.getTang().newConfigurationBuilder()
+      .bindNamedParameter(Command.class, command)
+      .build();
+
+    final Configuration merged = Configurations.merge(taskConf, commandConf);
+    context.submitTask(merged);
+    runningTasks.add(task);
+  }
+
+  /**
+   * Update the record of task to mark it as canceled.
+   */
+  public synchronized SchedulerResponse cancelTask(final int taskId) {
+    if (getTask(taskId, runningTasks) != null) {
+      return SchedulerResponse.FORBIDDEN("The task " + taskId + " is running");
+    } else if (getTask(taskId, finishedTasks) != null) {
+      return SchedulerResponse.FORBIDDEN("The task " + taskId + " has been finished");
+    }
+
+    final TaskEntity task = getTask(taskId, taskQueue);
+    if (task == null) {
+      final String message = new StringBuilder().append("Task with ID ").append(taskId).append(" is not found").toString();
+      return SchedulerResponse.NOT_FOUND(message);
+    } else {
+      taskQueue.remove(task);
+      canceledTasks.add(task);
+      return SchedulerResponse.OK("Canceled " + taskId);
+    }
+  }
+
+  /**
+   * Clear the pending list
+   */
+  public synchronized SchedulerResponse clear() {
+    final int count = taskQueue.size();
+    for (final TaskEntity task : taskQueue) {
+      canceledTasks.add(task);
+    }
+    taskQueue.clear();
+    return SchedulerResponse.OK(count + " tasks removed.");
+  }
+
+  /**
+   * Get the list of Tasks, which are grouped by the states.
+   */
+  public synchronized SchedulerResponse getList() {
+    final StringBuilder sb = new StringBuilder();
+    sb.append("Running :");
+    for (final TaskEntity running : runningTasks) {
+      sb.append(" ").append(running.getId());
+    }
+
+    sb.append("\nWaiting :");
+    for (final TaskEntity waiting : taskQueue) {
+      sb.append(" ").append(waiting.getId());
+    }
+
+    sb.append("\nFinished :");
+    for (final TaskEntity finished : finishedTasks) {
+      sb.append(" ").append(finished.getId());
+    }
+
+    sb.append("\nCanceled :");
+    for (final TaskEntity canceled : canceledTasks) {
+      sb.append(" ").append(canceled.getId());
+    }
+    return SchedulerResponse.OK(sb.toString());
+  }
+
+  /**
+   * Get the status of a Task.
+   */
+  public synchronized SchedulerResponse getTaskStatus(final int taskId) {
+
+    for (final TaskEntity running : runningTasks) {
+      if (taskId == running.getId()) {
+        return SchedulerResponse.OK("Running : " + running.toString());
+      }
+    }
+
+    for (final TaskEntity waiting : taskQueue) {
+      if (taskId == waiting.getId()) {
+        return SchedulerResponse.OK("Waiting : " + waiting.toString());
+      }
+    }
+
+    for (final TaskEntity finished : finishedTasks) {
+      if (taskId == finished.getId()) {
+        return SchedulerResponse.OK("Finished : " + finished.toString());
+      }
+    }
+
+    for (final TaskEntity finished : canceledTasks) {
+      if (taskId == finished.getId()) {
+        return SchedulerResponse.OK("Canceled: " + finished.toString());
+      }
+    }
+    return SchedulerResponse.NOT_FOUND(new StringBuilder().append("Task with ID ").append(taskId).append(" is not found").toString());
+  }
+
+  /**
+   * Assigns a TaskId to submit.
+   */
+  public synchronized int assignTaskId() {
+    return taskCount.incrementAndGet();
+  }
+
+  /**
+   * Add a task to the queue.
+   */
+  public synchronized void addTask(TaskEntity task) {
+    taskQueue.add(task);
+  }
+
+  /**
+   * Check whether there are tasks waiting to be submitted.
+   */
+  public synchronized boolean hasPendingTasks() {
+    return !taskQueue.isEmpty();
+  }
+
+  /**
+   * Get the number of pending tasks in the queue.
+   */
+  public synchronized int getNumPendingTasks() {
+    return taskQueue.size();
+  }
+
+  /**
+   * Update the record of task to mark it as finished.
+   */
+  public synchronized void setFinished(final int taskId) {
+    final TaskEntity task = getTask(taskId, runningTasks);
+    runningTasks.remove(task);
+    finishedTasks.add(task);
+  }
+
+  /**
+   * Iterate over the collection to find a TaskEntity with ID.
+   */
+  private TaskEntity getTask(final int taskId, final Collection<TaskEntity> tasks) {
+    TaskEntity result = null;
+    for (final TaskEntity task : tasks) {
+      if (taskId == task.getId()) {
+        result = task;
+        break;
+      }
+    }
+    return result;
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerDriver.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerDriver.java
new file mode 100644
index 0000000..890d872
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerDriver.java
@@ -0,0 +1,339 @@
+/**
+ * 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.reef.examples.scheduler;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.driver.task.CompletedTask;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.annotation.concurrent.GuardedBy;
+import javax.inject.Inject;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Driver for TaskScheduler. It receives the commands by HttpRequest and
+ * execute them in a FIFO(First In First Out) order.
+ */
+@Unit
+public final class SchedulerDriver {
+
+  public static final ObjectSerializableCodec<String> CODEC = new ObjectSerializableCodec<>();
+  private static final Logger LOG = Logger.getLogger(SchedulerDriver.class.getName());
+
+  /**
+   * Possible states of the job driver. Can be one of:
+   * <dl>
+   * <du><code>INIT</code></du><dd>Initial state. Ready to request an evaluator.</dd>
+   * <du><code>WAIT_EVALUATORS</code></du><dd>Waiting for an evaluator allocated with no active evaluators.</dd>
+   * <du><code>READY</code></du><dd>Wait for the commands. Reactivated when a new Task arrives.</dd>
+   * <du><code>RUNNING</code></du><dd>Run commands in the queue. Go back to READY state when the queue is empty.</dd>
+   * </dl>
+   */
+  private enum State {
+    INIT, WAIT_EVALUATORS, READY, RUNNING
+  }
+
+  /**
+   * If true, it reuses evaluators when Tasks done.
+   */
+  private boolean retainable;
+
+  @GuardedBy("SchedulerDriver.this")
+  private State state = State.INIT;
+
+  @GuardedBy("SchedulerDriver.this")
+  private Scheduler scheduler;
+
+  @GuardedBy("SchedulerDriver.this")
+  private int nMaxEval = 3, nActiveEval = 0, nRequestedEval = 0;
+
+  private final EvaluatorRequestor requestor;
+
+  @Inject
+  public SchedulerDriver(final EvaluatorRequestor requestor,
+                         @Parameter(SchedulerREEF.Retain.class) boolean retainable,
+                         final Scheduler scheduler) {
+    this.requestor = requestor;
+    this.scheduler = scheduler;
+    this.retainable = retainable;
+  }
+
+  /**
+   * The driver is ready to run.
+   */
+  final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime startTime) {
+      LOG.log(Level.INFO, "Driver started at {0}", startTime);
+      assert (state == State.INIT);
+      state = State.WAIT_EVALUATORS;
+
+      requestEvaluator(1); // Allocate an initial evaluator to avoid idle state.
+    }
+  }
+
+  /**
+   * Evaluator is allocated. This occurs every time to run commands in Non-retainable version,
+   * while occurs only once in the Retainable version
+   */
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator evaluator) {
+      LOG.log(Level.INFO, "Evaluator is ready");
+      synchronized (SchedulerDriver.this) {
+        nActiveEval++;
+        nRequestedEval--;
+      }
+
+      evaluator.submitContext(ContextConfiguration.CONF
+        .set(ContextConfiguration.IDENTIFIER, "SchedulerContext")
+        .build());
+    }
+  }
+
+  /**
+   * Now it is ready to schedule tasks. But if the queue is empty,
+   * wait until commands coming up.
+   *
+   * If there is no pending task, having more than 1 evaluators must be redundant.
+   * It may happen, for example, when tasks are canceled during allocation.
+   * In these cases, the new evaluator may be abandoned.
+   */
+  final class ActiveContextHandler implements EventHandler<ActiveContext> {
+    @Override
+    public void onNext(ActiveContext context) {
+      synchronized (SchedulerDriver.this) {
+        LOG.log(Level.INFO, "Context available : {0}", context.getId());
+
+        if (scheduler.hasPendingTasks()) {
+          state = State.RUNNING;
+          scheduler.submitTask(context);
+        } else if (nActiveEval > 1) {
+          nActiveEval--;
+          context.close();
+        } else {
+          state = State.READY;
+          waitForCommands(context);
+        }
+      }
+    }
+  }
+
+  /**
+   * Non-retainable version of CompletedTaskHandler.
+   * When Task completes, it closes the active context to deallocate the evaluator
+   * and if there is outstanding commands, allocate another evaluator.
+   */
+  final class CompletedTaskHandler implements EventHandler<CompletedTask> {
+    @Override
+    public void onNext(final CompletedTask task) {
+      final int taskId = Integer.valueOf(task.getId());
+
+      synchronized (SchedulerDriver.this) {
+        scheduler.setFinished(taskId);
+
+        LOG.log(Level.INFO, "Task completed. Reuse the evaluator : {0}", String.valueOf(retainable));
+        final ActiveContext context = task.getActiveContext();
+
+        if (retainable) {
+          retainEvaluator(context);
+        } else {
+          reallocateEvaluator(context);
+        }
+      }
+    }
+  }
+
+  /**
+   * Get the list of tasks in the scheduler.
+   */
+  public synchronized SchedulerResponse getList() {
+    return scheduler.getList();
+  }
+
+  /**
+   * Clear all the Tasks from the waiting queue.
+   */
+  public synchronized SchedulerResponse clearList() {
+    return scheduler.clear();
+  }
+
+  /**
+   * Get the status of a task.
+   */
+  public SchedulerResponse getTaskStatus(List<String> args) {
+    if (args.size() != 1) {
+      return SchedulerResponse.BAD_REQUEST("Usage : only one ID at a time");
+    }
+
+    final Integer taskId = Integer.valueOf(args.get(0));
+
+    synchronized (SchedulerDriver.this) {
+      return scheduler.getTaskStatus(taskId);
+    }
+  }
+
+  /**
+   * Cancel a Task waiting on the queue. A task cannot be canceled
+   * once it is running.
+   */
+  public SchedulerResponse cancelTask(final List<String> args) {
+    if (args.size() != 1) {
+      return SchedulerResponse.BAD_REQUEST("Usage : only one ID at a time");
+    }
+
+    final Integer taskId = Integer.valueOf(args.get(0));
+
+    synchronized (SchedulerDriver.this) {
+      return scheduler.cancelTask(taskId);
+    }
+  }
+
+  /**
+   * Submit a command to schedule.
+   */
+  public SchedulerResponse submitCommands(final List<String> args) {
+    if (args.size() != 1) {
+      return SchedulerResponse.BAD_REQUEST("Usage : only one command at a time");
+    }
+
+    final String command = args.get(0);
+    final Integer id;
+
+    synchronized (SchedulerDriver.this) {
+      id = scheduler.assignTaskId();
+      scheduler.addTask(new TaskEntity(id, command));
+
+      if (state == State.READY) {
+        SchedulerDriver.this.notify(); // Wake up at {waitForCommands}
+      } else if (state == State.RUNNING && nMaxEval > nActiveEval + nRequestedEval) {
+        requestEvaluator(1);
+      }
+    }
+    return SchedulerResponse.OK("Task ID : " + id);
+  }
+
+  /**
+   * Update the maximum number of evaluators to hold.
+   * Request more evaluators in case there are pending tasks
+   * in the queue and the number of evaluators is less than the limit.
+   */
+  public SchedulerResponse setMaxEvaluators(final List<String> args) {
+    if (args.size() != 1) {
+      return SchedulerResponse.BAD_REQUEST("Usage : Only one value can be used");
+    }
+
+    final int nTarget = Integer.valueOf(args.get(0));
+
+    synchronized (SchedulerDriver.this) {
+      if (nTarget < nActiveEval + nRequestedEval) {
+        return SchedulerResponse.FORBIDDEN(nActiveEval + nRequestedEval +
+          " evaluators are used now. Should be larger than that.");
+      }
+      nMaxEval = nTarget;
+
+      if (scheduler.hasPendingTasks()) {
+        final int nToRequest =
+          Math.min(scheduler.getNumPendingTasks(), nMaxEval - nActiveEval) - nRequestedEval;
+        requestEvaluator(nToRequest);
+      }
+      return SchedulerResponse.OK("You can use evaluators up to " + nMaxEval + " evaluators.");
+    }
+  }
+
+  /**
+   * Request evaluators. Passing a non positive number is illegal,
+   * so it does not make a trial for that situation.
+   */
+  private void requestEvaluator(final int numToRequest) {
+    if (numToRequest <= 0) {
+      throw new IllegalArgumentException("The number of evaluator request should be a positive integer");
+    }
+
+    synchronized (SchedulerDriver.this) {
+      nRequestedEval += numToRequest;
+      requestor.submit(EvaluatorRequest.newBuilder()
+        .setMemory(32)
+        .setNumber(numToRequest)
+        .build());
+    }
+  }
+
+  /**
+   * Pick up a command from the queue and run it. Wait until
+   * any command coming up if no command exists.
+   */
+  private void waitForCommands(final ActiveContext context) {
+    synchronized (SchedulerDriver.this) {
+      while (!scheduler.hasPendingTasks()) {
+        // Wait until any command enters in the queue
+        try {
+          SchedulerDriver.this.wait();
+        } catch (InterruptedException e) {
+          LOG.log(Level.WARNING, "InterruptedException occurred in SchedulerDriver", e);
+        }
+      }
+      // When wakes up, run the first command from the queue.
+      state = State.RUNNING;
+      scheduler.submitTask(context);
+    }
+  }
+
+  /**
+   * Retain the complete evaluators submitting another task
+   * until there is no need to reuse them.
+   */
+  private synchronized void retainEvaluator(final ActiveContext context) {
+    if (scheduler.hasPendingTasks()) {
+      scheduler.submitTask(context);
+    } else if (nActiveEval > 1) {
+      nActiveEval--;
+      context.close();
+    } else {
+      state = State.READY;
+      waitForCommands(context);
+    }
+  }
+
+  /**
+   * Always close the complete evaluators and
+   * allocate a new evaluator if necessary.
+   */
+  private synchronized void reallocateEvaluator(final ActiveContext context) {
+    nActiveEval--;
+    context.close();
+
+    if (scheduler.hasPendingTasks()) {
+      requestEvaluator(1);
+    } else if (nActiveEval <= 0) {
+      state = State.WAIT_EVALUATORS;
+      requestEvaluator(1);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerHttpHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerHttpHandler.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerHttpHandler.java
new file mode 100644
index 0000000..c2f6090
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerHttpHandler.java
@@ -0,0 +1,107 @@
+/**
+ * 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.reef.examples.scheduler;
+
+import org.apache.reef.tang.InjectionFuture;
+import org.apache.reef.webserver.HttpHandler;
+import org.apache.reef.webserver.ParsedHttpRequest;
+
+import javax.inject.Inject;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Receive HttpRequest so that it can handle the command list
+ */
+final class SchedulerHttpHandler implements HttpHandler {
+  final InjectionFuture<SchedulerDriver> schedulerDriver;
+
+  private String uriSpecification = "reef-example-scheduler";
+
+  @Inject
+  public SchedulerHttpHandler(final InjectionFuture<SchedulerDriver> schedulerDriver) {
+    this.schedulerDriver = schedulerDriver;
+  }
+
+  @Override
+  public String getUriSpecification() {
+    return uriSpecification;
+  }
+
+  @Override
+  public void setUriSpecification(String s) {
+    uriSpecification = s;
+  }
+
+  /**
+   * HttpRequest handler. You must specify UriSpecification and REST API version.
+   * The request url is http://{address}:{port}/reef-example-scheduler/v1
+   *
+   * APIs
+   *   /list                to get the status list for all tasks
+   *   /status?id={id}      to query the status of such a task, given id
+   *   /submit?cmd={cmd}    to submit a Task, which returns its id
+   *   /cancel?id={id}      to cancel the task's execution
+   *   /num-eval?num={num}  to set the maximum number of evaluators
+   *   /clear               to clear the waiting queue
+   */
+  @Override
+  public void onHttpRequest(ParsedHttpRequest request, HttpServletResponse response)
+    throws IOException, ServletException {
+    final String target = request.getTargetEntity().toLowerCase();
+    final Map<String, List<String>> queryMap = request.getQueryMap();
+
+    final SchedulerResponse result;
+    switch (target) {
+      case "list":
+        result = schedulerDriver.get().getList();
+        break;
+      case "clear":
+        result = schedulerDriver.get().clearList();
+        break;
+      case "status":
+        result = schedulerDriver.get().getTaskStatus(queryMap.get("id"));
+        break;
+      case "submit":
+        result = schedulerDriver.get().submitCommands(queryMap.get("cmd"));
+        break;
+      case "cancel":
+        result = schedulerDriver.get().cancelTask(queryMap.get("id"));
+        break;
+      case "max-eval":
+        result = schedulerDriver.get().setMaxEvaluators(queryMap.get("num"));
+        break;
+      default:
+        result = SchedulerResponse.NOT_FOUND("Unsupported operation");
+    }
+
+    // Send response to the http client
+    final int status = result.getStatus();
+    final String message= result.getMessage();
+
+    if (result.isOK()) {
+      response.getOutputStream().println(message);
+    } else {
+      response.sendError(status, message);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerREEF.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerREEF.java b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerREEF.java
new file mode 100644
index 0000000..2911905
--- /dev/null
+++ b/lang/java/reef-examples/src/main/java/org/apache/reef/examples/scheduler/SchedulerREEF.java
@@ -0,0 +1,109 @@
+/**
+ * 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.reef.examples.scheduler;
+
+import org.apache.commons.cli.ParseException;
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.REEF;
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Configurations;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.CommandLine;
+import org.apache.reef.util.EnvironmentUtils;
+import org.apache.reef.webserver.HttpHandlerConfiguration;
+
+import java.io.IOException;
+
+/**
+ * REEF TaskScheduler.
+ */
+public final class SchedulerREEF {
+
+  /**
+   * Command line parameter = true to reuse evaluators,
+   * or false to allocate/close for each iteration
+   */
+  @NamedParameter(doc = "Whether or not to reuse evaluators",
+    short_name = "retain", default_value = "true")
+  public static final class Retain implements Name<Boolean> {
+  }
+
+  /**
+   * @return The http configuration to use reef-webserver
+   */
+  private final static Configuration getHttpConf() {
+    final Configuration httpHandlerConf = HttpHandlerConfiguration.CONF
+      .set(HttpHandlerConfiguration.HTTP_HANDLERS, SchedulerHttpHandler.class)
+      .build();
+    return httpHandlerConf;
+  }
+
+  /**
+   * @return The Driver configuration.
+   */
+  private final static Configuration getDriverConf() {
+    final Configuration driverConf = DriverConfiguration.CONF
+      .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(SchedulerDriver.class))
+      .set(DriverConfiguration.DRIVER_IDENTIFIER, "TaskScheduler")
+      .set(DriverConfiguration.ON_DRIVER_STARTED, SchedulerDriver.StartHandler.class)
+      .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, SchedulerDriver.EvaluatorAllocatedHandler.class)
+      .set(DriverConfiguration.ON_CONTEXT_ACTIVE, SchedulerDriver.ActiveContextHandler.class)
+      .set(DriverConfiguration.ON_TASK_COMPLETED, SchedulerDriver.CompletedTaskHandler.class)
+      .build();
+
+    return driverConf;
+  }
+
+  /**
+   * Run the Task scheduler. If '-retain true' option is passed via command line,
+   * the scheduler reuses evaluators to submit new Tasks.
+   * @param runtimeConf The runtime configuration (e.g. Local, YARN, etc)
+   * @param args Command line arguments.
+   * @throws InjectionException
+   * @throws java.io.IOException
+   */
+  public static void runTaskScheduler(final Configuration runtimeConf, final String[] args)
+    throws InjectionException, IOException, ParseException {
+    final Tang tang = Tang.Factory.getTang();
+
+    final Configuration commandLineConf = CommandLine.parseToConfiguration(args, Retain.class);
+
+    // Merge the configurations to run Driver
+    final Configuration driverConf = Configurations.merge(getDriverConf(), getHttpConf(), commandLineConf);
+
+    final REEF reef = tang.newInjector(runtimeConf).getInstance(REEF.class);
+    reef.submit(driverConf);
+  }
+
+  /**
+   * Main program
+   * @param args
+   * @throws InjectionException
+   */
+  public final static void main(String[] args) throws InjectionException, IOException, ParseException {
+    final Configuration runtimeConfiguration = LocalRuntimeConfiguration.CONF
+      .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, 3)
+      .build();
+    runTaskScheduler(runtimeConfiguration, args);
+  }
+}


[28/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataLoadingDriverConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataLoadingDriverConfiguration.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataLoadingDriverConfiguration.java
new file mode 100644
index 0000000..6d5515e
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataLoadingDriverConfiguration.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.io.data.loading.api;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.driver.parameters.EvaluatorAllocatedHandlers;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.wake.time.Clock;
+
+public final class DataLoadingDriverConfiguration extends ConfigurationModuleBuilder {
+  public static final ConfigurationModule CONF = new DataLoadingDriverConfiguration()
+      .merge(DriverConfiguration.CONF)
+      .bindSetEntry(Clock.StartHandler.class, DataLoader.StartHandler.class)
+      .bindSetEntry(EvaluatorAllocatedHandlers.class, DataLoader.EvaluatorAllocatedHandler.class)
+      .build();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataLoadingRequestBuilder.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataLoadingRequestBuilder.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataLoadingRequestBuilder.java
new file mode 100644
index 0000000..be479c6
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataLoadingRequestBuilder.java
@@ -0,0 +1,190 @@
+/**
+ * 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.reef.io.data.loading.api;
+
+import org.apache.hadoop.mapred.InputFormat;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.TextInputFormat;
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.io.data.loading.impl.EvaluatorRequestSerializer;
+import org.apache.reef.io.data.loading.impl.InputFormatExternalConstructor;
+import org.apache.reef.io.data.loading.impl.InputFormatLoadingService;
+import org.apache.reef.io.data.loading.impl.JobConfExternalConstructor;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.formats.ConfigurationModule;
+
+/**
+ * Builder to create a request to the DataLoadingService.
+ */
+public final class DataLoadingRequestBuilder
+    implements org.apache.reef.util.Builder<Configuration> {
+
+  private int memoryMB = -1;
+  private int numberOfCores = -1;
+  private int numberOfDesiredSplits = -1;
+  private EvaluatorRequest computeRequest = null;
+  private boolean inMemory = false;
+  private boolean renewFailedEvaluators = true;
+  private ConfigurationModule driverConfigurationModule = null;
+  private String inputFormatClass;
+  private String inputPath;
+
+  public DataLoadingRequestBuilder setNumberOfDesiredSplits(final int numberOfDesiredSplits) {
+    this.numberOfDesiredSplits = numberOfDesiredSplits;
+    return this;
+  }
+
+  /**
+   * Set the memory to be used for Evaluator allocated.
+   *
+   * @param memoryMB the amount of memory in MB
+   * @return this
+   */
+  public DataLoadingRequestBuilder setMemoryMB(final int memoryMB) {
+    this.memoryMB = memoryMB;
+    return this;
+  }
+
+  /**
+   * Set the core number to be used for Evaluator allocated.
+   *
+   * @param numberOfCores the number of cores
+   * @return this
+   */
+  public DataLoadingRequestBuilder setNumberOfCores(final int numberOfCores) {
+    this.numberOfCores = numberOfCores;
+    return this;
+  }
+
+  public DataLoadingRequestBuilder setComputeRequest(final EvaluatorRequest computeRequest) {
+    this.computeRequest = computeRequest;
+    return this;
+  }
+
+  public DataLoadingRequestBuilder loadIntoMemory(final boolean inMemory) {
+    this.inMemory = inMemory;
+    return this;
+  }
+
+  public DataLoadingRequestBuilder renewFailedEvaluators(final boolean renewFailedEvaluators) {
+    this.renewFailedEvaluators = renewFailedEvaluators;
+    return this;
+  }
+
+  public DataLoadingRequestBuilder setDriverConfigurationModule(
+      final ConfigurationModule driverConfigurationModule) {
+    this.driverConfigurationModule = driverConfigurationModule;
+    return this;
+  }
+
+  public DataLoadingRequestBuilder setInputFormatClass(
+      final Class<? extends InputFormat> inputFormatClass) {
+    this.inputFormatClass = inputFormatClass.getName();
+    return this;
+  }
+
+  public DataLoadingRequestBuilder setInputPath(final String inputPath) {
+    this.inputPath = inputPath;
+    return this;
+  }
+
+  @Override
+  public Configuration build() throws BindException {
+    if (this.driverConfigurationModule == null) {
+      throw new BindException("Driver Configuration Module is a required parameter.");
+    }
+
+    if (this.inputPath == null) {
+      throw new BindException("InputPath is a required parameter.");
+    }
+
+    if (this.inputFormatClass == null) {
+      this.inputFormatClass = TextInputFormat.class.getName();
+    }
+
+    final Configuration driverConfiguration;
+    if (renewFailedEvaluators) {
+      driverConfiguration = this.driverConfigurationModule
+          .set(DriverConfiguration.ON_DRIVER_STARTED, DataLoader.StartHandler.class)
+          .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, DataLoader.EvaluatorAllocatedHandler.class)
+          .set(DriverConfiguration.ON_EVALUATOR_FAILED, DataLoader.EvaluatorFailedHandler.class)
+          .build();
+    } else {
+      driverConfiguration = this.driverConfigurationModule
+          .set(DriverConfiguration.ON_DRIVER_STARTED, DataLoader.StartHandler.class)
+          .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, DataLoader.EvaluatorAllocatedHandler.class)
+          .build();
+    }
+
+    final JavaConfigurationBuilder jcb =
+        Tang.Factory.getTang().newConfigurationBuilder(driverConfiguration);
+
+    if (this.numberOfDesiredSplits > 0) {
+      jcb.bindNamedParameter(NumberOfDesiredSplits.class, "" + this.numberOfDesiredSplits);
+    }
+
+    if (this.memoryMB > 0) {
+      jcb.bindNamedParameter(DataLoadingEvaluatorMemoryMB.class, "" + this.memoryMB);
+    }
+
+    if (this.numberOfCores > 0) {
+      jcb.bindNamedParameter(DataLoadingEvaluatorNumberOfCores.class, "" + this.numberOfCores);
+    }
+
+    if (this.computeRequest != null) {
+      jcb.bindNamedParameter(DataLoadingComputeRequest.class,
+          EvaluatorRequestSerializer.serialize(this.computeRequest));
+    }
+
+    return jcb
+        .bindNamedParameter(LoadDataIntoMemory.class, Boolean.toString(this.inMemory))
+        .bindConstructor(InputFormat.class, InputFormatExternalConstructor.class)
+        .bindConstructor(JobConf.class, JobConfExternalConstructor.class)
+        .bindNamedParameter(JobConfExternalConstructor.InputFormatClass.class, inputFormatClass)
+        .bindNamedParameter(JobConfExternalConstructor.InputPath.class, inputPath)
+        .bindImplementation(DataLoadingService.class, InputFormatLoadingService.class)
+        .build();
+  }
+
+  @NamedParameter(short_name = "num_splits", default_value = "0")
+  public static final class NumberOfDesiredSplits implements Name<Integer> {
+  }
+
+  @NamedParameter(short_name = "dataLoadingEvaluatorMemoryMB", default_value = "4096")
+  public static final class DataLoadingEvaluatorMemoryMB implements Name<Integer> {
+  }
+
+  @NamedParameter(short_name = "dataLoadingEvaluatorCore", default_value = "1")
+  public static final class DataLoadingEvaluatorNumberOfCores implements Name<Integer> {
+  }
+
+  @NamedParameter(default_value = "NULL")
+  public static final class DataLoadingComputeRequest implements Name<String> {
+  }
+
+  @NamedParameter(default_value = "false")
+  public static final class LoadDataIntoMemory implements Name<Boolean> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataLoadingService.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataLoadingService.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataLoadingService.java
new file mode 100644
index 0000000..9461148
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataLoadingService.java
@@ -0,0 +1,68 @@
+/**
+ * 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.reef.io.data.loading.api;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.tang.Configuration;
+
+/**
+ * All data loading services should implement this interface.
+ */
+@DriverSide
+public interface DataLoadingService {
+
+  /**
+   * Access to the number of partitions suggested by this DataSource.
+   *
+   * @return the number of partitions suggested by this DataSource.
+   */
+  int getNumberOfPartitions();
+
+  /**
+   * @return the context configuration for the given Evaluator.
+   */
+  Configuration getContextConfiguration(final AllocatedEvaluator allocatedEvaluator);
+
+  /**
+   * @return the service configuration for the given Evaluator.
+   */
+  Configuration getServiceConfiguration(final AllocatedEvaluator allocatedEvaluator);
+
+  /**
+   * @return Return the prefix to be used to enumerate
+   * context ids for compute requests fired other than
+   * the data load contexts.
+   */
+  String getComputeContextIdPrefix();
+
+  /**
+   * Distinguishes data loaded contexts from compute contexts.
+   *
+   * @return true if this context has been loaded with data.
+   */
+  boolean isDataLoadedContext(ActiveContext context);
+
+  /**
+   * @return true if this is a computation context,
+   * false otherwise. (e.g. this is a data loading context).
+   */
+  boolean isComputeContext(ActiveContext context);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataSet.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataSet.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataSet.java
new file mode 100644
index 0000000..a15764d
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/DataSet.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.io.data.loading.api;
+
+import org.apache.reef.annotations.audience.TaskSide;
+import org.apache.reef.io.network.util.Pair;
+
+/**
+ * A view of the data set to be loaded
+ * at an evaluator as an iterable of
+ * key value pairs.
+ * <p/>
+ * Implementations need not materialize
+ * and clients should not assume that the
+ * data is materialized. Any such thing
+ * is left as a post-processing step.
+ * <p/>
+ * Client also can't assume that the iterator
+ * returned here can be restarted
+ *
+ * @param <K>
+ * @param <V>
+ */
+@TaskSide
+public interface DataSet<K, V> extends Iterable<Pair<K, V>> {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/ResourceRequestHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/ResourceRequestHandler.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/ResourceRequestHandler.java
new file mode 100644
index 0000000..ddf3b15
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/api/ResourceRequestHandler.java
@@ -0,0 +1,64 @@
+/**
+ * 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.reef.io.data.loading.api;
+
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class ResourceRequestHandler implements EventHandler<EvaluatorRequest> {
+
+  private static final Logger LOG = Logger.getLogger(ResourceRequestHandler.class.getName());
+
+  private final EvaluatorRequestor requestor;
+
+  private CountDownLatch resourceRequestGate = new CountDownLatch(1);
+
+  public ResourceRequestHandler(final EvaluatorRequestor requestor) {
+    this.requestor = requestor;
+  }
+
+  public void releaseResourceRequestGate() {
+    LOG.log(Level.FINE, "Releasing Gate");
+    this.resourceRequestGate.countDown();
+  }
+
+  @Override
+  public void onNext(final EvaluatorRequest request) {
+    try {
+
+      LOG.log(Level.FINE,
+          "Processing a request with count: {0} - Waiting for gate to be released",
+          request.getNumber());
+
+      this.resourceRequestGate.await();
+
+      LOG.log(Level.FINE, "Gate released. Submitting request: {0}", request);
+      this.resourceRequestGate = new CountDownLatch(1);
+      this.requestor.submit(request);
+
+    } catch (final InterruptedException ex) {
+      LOG.log(Level.FINEST, "Interrupted", ex);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/EvaluatorRequestSerializer.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/EvaluatorRequestSerializer.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/EvaluatorRequestSerializer.java
new file mode 100644
index 0000000..2f493c6
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/EvaluatorRequestSerializer.java
@@ -0,0 +1,63 @@
+/**
+ * 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.reef.io.data.loading.impl;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+
+import java.io.*;
+
+/**
+ * Serialize and deserialize EvaluatorRequest objects
+ * Currently only supports number & memory
+ * Does not take care of Resource Descriptor
+ */
+public class EvaluatorRequestSerializer {
+  public static String serialize(EvaluatorRequest request) {
+    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+      try (DataOutputStream daos = new DataOutputStream(baos)) {
+
+        daos.writeInt(request.getNumber());
+        daos.writeInt(request.getMegaBytes());
+        daos.writeInt(request.getNumberOfCores());
+
+      } catch (IOException e) {
+        throw e;
+      }
+
+      return Base64.encodeBase64String(baos.toByteArray());
+    } catch (IOException e1) {
+      throw new RuntimeException("Unable to serialize compute request", e1);
+    }
+  }
+
+  public static EvaluatorRequest deserialize(String serializedRequest) {
+    try (ByteArrayInputStream bais = new ByteArrayInputStream(Base64.decodeBase64(serializedRequest))) {
+      try (DataInputStream dais = new DataInputStream(bais)) {
+        return EvaluatorRequest.newBuilder()
+            .setNumber(dais.readInt())
+            .setMemory(dais.readInt())
+            .setNumberOfCores(dais.readInt())
+            .build();
+      }
+    } catch (IOException e) {
+      throw new RuntimeException("Unable to de-serialize compute request", e);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/EvaluatorToPartitionMapper.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/EvaluatorToPartitionMapper.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/EvaluatorToPartitionMapper.java
new file mode 100644
index 0000000..5a5c0ff
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/EvaluatorToPartitionMapper.java
@@ -0,0 +1,154 @@
+/**
+ * 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.reef.io.data.loading.impl;
+
+import org.apache.hadoop.mapred.InputFormat;
+import org.apache.hadoop.mapred.InputSplit;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.io.data.loading.api.DataLoadingService;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Class that tracks the mapping between
+ * evaluators & the data partition assigned
+ * to those evaluators. Its part of the
+ * implementation of a {@link DataLoadingService}
+ * that uses the Hadoop {@link InputFormat} to
+ * partition the data and request resources
+ * accordingly
+ * <p/>
+ * This is an online version which satisfies
+ * requests in a greedy way.
+ *
+ * @param <V>
+ */
+@DriverSide
+public class EvaluatorToPartitionMapper<V extends InputSplit> {
+  private static final Logger LOG = Logger
+      .getLogger(EvaluatorToPartitionMapper.class.getName());
+
+  private final ConcurrentMap<String, BlockingQueue<NumberedSplit<V>>> locationToSplits = new ConcurrentHashMap<>();
+  private final ConcurrentMap<String, NumberedSplit<V>> evaluatorToSplits = new ConcurrentHashMap<>();
+  private final BlockingQueue<NumberedSplit<V>> unallocatedSplits = new LinkedBlockingQueue<>();
+
+  /**
+   * Initializes the locations of splits mapping
+   *
+   * @param splits
+   */
+  public EvaluatorToPartitionMapper(V[] splits) {
+    try {
+      for (int splitNum = 0; splitNum < splits.length; splitNum++) {
+        LOG.log(Level.FINE, "Processing split: " + splitNum);
+        final V split = splits[splitNum];
+        final String[] locations = split.getLocations();
+        final NumberedSplit<V> numberedSplit = new NumberedSplit<V>(split, splitNum);
+        unallocatedSplits.add(numberedSplit);
+        for (final String location : locations) {
+          BlockingQueue<NumberedSplit<V>> newSplitQue = new LinkedBlockingQueue<NumberedSplit<V>>();
+          final BlockingQueue<NumberedSplit<V>> splitQue = locationToSplits.putIfAbsent(location,
+              newSplitQue);
+          if (splitQue != null) {
+            newSplitQue = splitQue;
+          }
+          newSplitQue.add(numberedSplit);
+        }
+      }
+      for (Map.Entry<String, BlockingQueue<NumberedSplit<V>>> locSplit : locationToSplits.entrySet()) {
+        LOG.log(Level.FINE, locSplit.getKey() + ": " + locSplit.getValue().toString());
+      }
+    } catch (IOException e) {
+      throw new RuntimeException(
+          "Unable to get InputSplits using the specified InputFormat", e);
+    }
+  }
+
+  /**
+   * Get an input split to be assigned to this
+   * evaluator
+   * <p/>
+   * Allocates one if its not already allocated
+   *
+   * @param evaluatorId
+   * @return
+   */
+  public NumberedSplit<V> getInputSplit(final String hostName, final String evaluatorId) {
+    synchronized (evaluatorToSplits) {
+      if (evaluatorToSplits.containsKey(evaluatorId)) {
+        LOG.log(Level.FINE, "Found an already allocated partition");
+        LOG.log(Level.FINE, evaluatorToSplits.toString());
+        return evaluatorToSplits.get(evaluatorId);
+      }
+    }
+    LOG.log(Level.FINE, "allocated partition not found");
+    if (locationToSplits.containsKey(hostName)) {
+      LOG.log(Level.FINE, "Found partitions possibly hosted for " + evaluatorId + " at " + hostName);
+      final NumberedSplit<V> split = allocateSplit(evaluatorId, locationToSplits.get(hostName));
+      LOG.log(Level.FINE, evaluatorToSplits.toString());
+      if (split != null) {
+        return split;
+      }
+    }
+    //pick random
+    LOG.log(
+        Level.FINE,
+        hostName
+            + " does not host any partitions or someone else took partitions hosted here. Picking a random one");
+    final NumberedSplit<V> split = allocateSplit(evaluatorId, unallocatedSplits);
+    LOG.log(Level.FINE, evaluatorToSplits.toString());
+    if (split != null) {
+      return split;
+    }
+    throw new RuntimeException("Unable to find an input partition to evaluator " + evaluatorId);
+  }
+
+  private NumberedSplit<V> allocateSplit(final String evaluatorId,
+                                         final BlockingQueue<NumberedSplit<V>> value) {
+    if (value == null) {
+      LOG.log(Level.FINE, "Queue of splits can't be empty. Returning null");
+      return null;
+    }
+    while (true) {
+      final NumberedSplit<V> split = value.poll();
+      if (split == null)
+        return null;
+      if (value == unallocatedSplits || unallocatedSplits.remove(split)) {
+        LOG.log(Level.FINE, "Found split-" + split.getIndex() + " in the queue");
+        final NumberedSplit<V> old = evaluatorToSplits.putIfAbsent(evaluatorId, split);
+        if (old != null) {
+          final String msg = "Trying to assign different partitions to the same evaluator " +
+              "is not supported";
+          LOG.severe(msg);
+          throw new RuntimeException(msg);
+        } else {
+          LOG.log(Level.FINE, "Returning " + split.getIndex());
+          return split;
+        }
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InMemoryInputFormatDataSet.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InMemoryInputFormatDataSet.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InMemoryInputFormatDataSet.java
new file mode 100644
index 0000000..e729aaf
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InMemoryInputFormatDataSet.java
@@ -0,0 +1,53 @@
+/**
+ * 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.reef.io.data.loading.impl;
+
+import org.apache.hadoop.io.Writable;
+import org.apache.hadoop.io.WritableComparable;
+import org.apache.reef.io.data.loading.api.DataSet;
+import org.apache.reef.io.network.util.Pair;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class InMemoryInputFormatDataSet<K extends WritableComparable<K>, V extends Writable>
+    implements DataSet<K, V> {
+
+  private final InputFormatDataSet<K, V> inputFormatDataSet;
+  private List<Pair<K, V>> recordsList = null;
+
+  @Inject
+  public InMemoryInputFormatDataSet(InputFormatDataSet<K, V> inputFormatDataSet) {
+    this.inputFormatDataSet = inputFormatDataSet;
+  }
+
+
+  @Override
+  public synchronized Iterator<Pair<K, V>> iterator() {
+    if (recordsList == null) {
+      recordsList = new ArrayList<>();
+      for (final Pair<K, V> keyValue : inputFormatDataSet) {
+        recordsList.add(keyValue);
+      }
+    }
+    return recordsList.iterator();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InputFormatDataSet.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InputFormatDataSet.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InputFormatDataSet.java
new file mode 100644
index 0000000..a7632f3
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InputFormatDataSet.java
@@ -0,0 +1,156 @@
+/**
+ * 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.reef.io.data.loading.impl;
+
+import org.apache.hadoop.io.Writable;
+import org.apache.hadoop.io.WritableComparable;
+import org.apache.hadoop.mapred.Counters.Counter;
+import org.apache.hadoop.mapred.*;
+import org.apache.reef.annotations.audience.TaskSide;
+import org.apache.reef.io.data.loading.api.DataSet;
+import org.apache.reef.io.network.util.Pair;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.util.Iterator;
+
+/**
+ * An implementation of {@link DataSet} that reads records using a RecordReader
+ * encoded inside an InputSplit.
+ * <p/>
+ * The input split is injected through an external constructor by deserializing
+ * the input split assigned to this evaluator.
+ *
+ * @param <K>
+ * @param <V>
+ */
+@TaskSide
+public final class
+    InputFormatDataSet<K extends WritableComparable<K>, V extends Writable>
+    implements DataSet<K, V> {
+
+  private final DummyReporter dummyReporter = new DummyReporter();
+  private final JobConf jobConf;
+  private final InputFormat<K, V> inputFormat;
+  private final InputSplit split;
+  private RecordReader lastRecordReader = null;
+
+  @Inject
+  public InputFormatDataSet(final InputSplit split, final JobConf jobConf) {
+    this.jobConf = jobConf;
+    this.inputFormat = this.jobConf.getInputFormat();
+    this.split = split;
+  }
+
+  @Override
+  public Iterator<Pair<K, V>> iterator() {
+    try {
+
+      final RecordReader newRecordReader =
+          this.inputFormat.getRecordReader(this.split, this.jobConf, this.dummyReporter);
+
+      if (newRecordReader == this.lastRecordReader) {
+        throw new RuntimeException("Received the same record reader again. This isn't supported.");
+      }
+
+      this.lastRecordReader = newRecordReader;
+      return new RecordReaderIterator(newRecordReader);
+
+    } catch (final IOException ex) {
+      throw new RuntimeException("Can't instantiate iterator.", ex);
+    }
+  }
+
+  private final class RecordReaderIterator implements Iterator<Pair<K, V>> {
+
+    private final RecordReader<K, V> recordReader;
+    private Pair<K, V> recordPair;
+    private boolean hasNext;
+
+    RecordReaderIterator(final RecordReader<K, V> recordReader) {
+      this.recordReader = recordReader;
+      fetchRecord();
+    }
+
+    @Override
+    public boolean hasNext() {
+      return this.hasNext;
+    }
+
+    @Override
+    public Pair<K, V> next() {
+      final Pair<K, V> prevRecordPair = this.recordPair;
+      fetchRecord();
+      return prevRecordPair;
+    }
+
+    @Override
+    public void remove() {
+      throw new UnsupportedOperationException("Remove is not supported on RecordReader iterator");
+    }
+
+    private void fetchRecord() {
+      this.recordPair = new Pair<>(this.recordReader.createKey(), this.recordReader.createValue());
+      try {
+        this.hasNext = this.recordReader.next(this.recordPair.first, this.recordPair.second);
+      } catch (final IOException ex) {
+        throw new RuntimeException("Unable to get InputSplits using the specified InputFormat", ex);
+      }
+    }
+  }
+
+  private final class DummyReporter implements Reporter {
+
+    @Override
+    public void progress() {
+    }
+
+    @Override
+    public Counter getCounter(final Enum<?> key) {
+      return null;
+    }
+
+    @Override
+    public Counter getCounter(final String group, final String name) {
+      return null;
+    }
+
+    @Override
+    public InputSplit getInputSplit() throws UnsupportedOperationException {
+      throw new UnsupportedOperationException("This is a Fake Reporter");
+    }
+
+    @Override
+    public float getProgress() {
+      return 0;
+    }
+
+    @Override
+    public void incrCounter(final Enum<?> key, final long amount) {
+    }
+
+    @Override
+    public void incrCounter(final String group, final String counter, final long amount) {
+    }
+
+    @Override
+    public void setStatus(final String status) {
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InputFormatExternalConstructor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InputFormatExternalConstructor.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InputFormatExternalConstructor.java
new file mode 100644
index 0000000..aef6226
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InputFormatExternalConstructor.java
@@ -0,0 +1,50 @@
+/**
+ * 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.reef.io.data.loading.impl;
+
+import org.apache.hadoop.mapred.InputFormat;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.tang.ExternalConstructor;
+
+import javax.inject.Inject;
+
+
+/**
+ * A Tang External Constructor to inject the required
+ * InputFormat
+ */
+@DriverSide
+public class InputFormatExternalConstructor implements ExternalConstructor<InputFormat<?, ?>> {
+
+  private final JobConf jobConf;
+  private final InputFormat<?, ?> inputFormat;
+
+  @Inject
+  public InputFormatExternalConstructor(final JobConf jobConf) {
+    this.jobConf = jobConf;
+    inputFormat = jobConf.getInputFormat();
+  }
+
+  @Override
+  public InputFormat<?, ?> newInstance() {
+    return inputFormat;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InputFormatLoadingService.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InputFormatLoadingService.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InputFormatLoadingService.java
new file mode 100644
index 0000000..a2c9cb1
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InputFormatLoadingService.java
@@ -0,0 +1,172 @@
+/**
+ * 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.reef.io.data.loading.impl;
+
+import org.apache.hadoop.mapred.InputFormat;
+import org.apache.hadoop.mapred.InputSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.context.ServiceConfiguration;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.io.data.loading.api.DataLoadingRequestBuilder;
+import org.apache.reef.io.data.loading.api.DataLoadingService;
+import org.apache.reef.io.data.loading.api.DataSet;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.exceptions.BindException;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Random;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * An implementation of {@link DataLoadingService}
+ * that uses the Hadoop {@link InputFormat} to find
+ * partitions of data & request resources.
+ * <p/>
+ * The InputFormat is injected using a Tang external constructor
+ * <p/>
+ * It also tries to obtain data locality in a greedy
+ * fashion using {@link EvaluatorToPartitionMapper}
+ */
+@DriverSide
+public class InputFormatLoadingService<K, V> implements DataLoadingService {
+
+  private static final Logger LOG = Logger.getLogger(InputFormatLoadingService.class.getName());
+
+  private static final String DATA_LOAD_CONTEXT_PREFIX = "DataLoadContext-";
+
+  private static final String COMPUTE_CONTEXT_PREFIX =
+      "ComputeContext-" + new Random(3381).nextInt(1 << 20) + "-";
+
+  private final EvaluatorToPartitionMapper<InputSplit> evaluatorToPartitionMapper;
+  private final int numberOfPartitions;
+
+  private final boolean inMemory;
+
+  private final String inputFormatClass;
+
+  private final String inputPath;
+
+  @Inject
+  public InputFormatLoadingService(
+      final InputFormat<K, V> inputFormat,
+      final JobConf jobConf,
+      final @Parameter(DataLoadingRequestBuilder.NumberOfDesiredSplits.class) int numberOfDesiredSplits,
+      final @Parameter(DataLoadingRequestBuilder.LoadDataIntoMemory.class) boolean inMemory,
+      final @Parameter(JobConfExternalConstructor.InputFormatClass.class) String inputFormatClass,
+      final @Parameter(JobConfExternalConstructor.InputPath.class) String inputPath) {
+
+    this.inMemory = inMemory;
+    this.inputFormatClass = inputFormatClass;
+    this.inputPath = inputPath;
+
+
+    try {
+
+      final InputSplit[] inputSplits = inputFormat.getSplits(jobConf, numberOfDesiredSplits);
+      if (LOG.isLoggable(Level.FINEST)) {
+        LOG.log(Level.FINEST, "Splits: {0}", Arrays.toString(inputSplits));
+      }
+
+      this.numberOfPartitions = inputSplits.length;
+      LOG.log(Level.FINE, "Number of partitions: {0}", this.numberOfPartitions);
+
+      this.evaluatorToPartitionMapper = new EvaluatorToPartitionMapper<>(inputSplits);
+
+    } catch (final IOException e) {
+      throw new RuntimeException("Unable to get InputSplits using the specified InputFormat", e);
+    }
+  }
+
+  @Override
+  public int getNumberOfPartitions() {
+    return this.numberOfPartitions;
+  }
+
+  @Override
+  public Configuration getContextConfiguration(final AllocatedEvaluator allocatedEvaluator) {
+
+    final NumberedSplit<InputSplit> numberedSplit =
+        this.evaluatorToPartitionMapper.getInputSplit(
+            allocatedEvaluator.getEvaluatorDescriptor().getNodeDescriptor().getName(),
+            allocatedEvaluator.getId());
+
+    return ContextConfiguration.CONF
+        .set(ContextConfiguration.IDENTIFIER, DATA_LOAD_CONTEXT_PREFIX + numberedSplit.getIndex())
+        .build();
+  }
+
+  @Override
+  public Configuration getServiceConfiguration(final AllocatedEvaluator allocatedEvaluator) {
+
+    try {
+
+      final NumberedSplit<InputSplit> numberedSplit =
+          this.evaluatorToPartitionMapper.getInputSplit(
+              allocatedEvaluator.getEvaluatorDescriptor().getNodeDescriptor().getName(),
+              allocatedEvaluator.getId());
+
+      final Configuration serviceConfiguration = ServiceConfiguration.CONF
+          .set(ServiceConfiguration.SERVICES,
+              this.inMemory ? InMemoryInputFormatDataSet.class : InputFormatDataSet.class)
+          .build();
+
+      return Tang.Factory.getTang().newConfigurationBuilder(serviceConfiguration)
+          .bindImplementation(
+              DataSet.class,
+              this.inMemory ? InMemoryInputFormatDataSet.class : InputFormatDataSet.class)
+          .bindNamedParameter(JobConfExternalConstructor.InputFormatClass.class, inputFormatClass)
+          .bindNamedParameter(JobConfExternalConstructor.InputPath.class, inputPath)
+          .bindNamedParameter(
+              InputSplitExternalConstructor.SerializedInputSplit.class,
+              WritableSerializer.serialize(numberedSplit.getEntry()))
+          .bindConstructor(InputSplit.class, InputSplitExternalConstructor.class)
+          .bindConstructor(JobConf.class, JobConfExternalConstructor.class)
+          .build();
+
+    } catch (final BindException ex) {
+      final String evalId = allocatedEvaluator.getId();
+      final String msg = "Unable to create configuration for evaluator " + evalId;
+      LOG.log(Level.WARNING, msg, ex);
+      throw new RuntimeException(msg, ex);
+    }
+  }
+
+  @Override
+  public String getComputeContextIdPrefix() {
+    return COMPUTE_CONTEXT_PREFIX;
+  }
+
+  @Override
+  public boolean isComputeContext(final ActiveContext context) {
+    return context.getId().startsWith(COMPUTE_CONTEXT_PREFIX);
+  }
+
+  @Override
+  public boolean isDataLoadedContext(final ActiveContext context) {
+    return context.getId().startsWith(DATA_LOAD_CONTEXT_PREFIX);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InputSplitExternalConstructor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InputSplitExternalConstructor.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InputSplitExternalConstructor.java
new file mode 100644
index 0000000..cedad2d
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/InputSplitExternalConstructor.java
@@ -0,0 +1,57 @@
+/**
+ * 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.reef.io.data.loading.impl;
+
+import org.apache.hadoop.mapred.InputSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.reef.annotations.audience.TaskSide;
+import org.apache.reef.tang.ExternalConstructor;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+
+/**
+ * A Tang external constructor to inject an InputSplit
+ * by deserializing the serialized input split assigned
+ * to this evaluator
+ */
+@TaskSide
+public class InputSplitExternalConstructor implements ExternalConstructor<InputSplit> {
+
+  private final InputSplit inputSplit;
+
+  @Inject
+  public InputSplitExternalConstructor(
+      final JobConf jobConf,
+      @Parameter(SerializedInputSplit.class) final String serializedInputSplit) {
+    this.inputSplit = WritableSerializer.deserialize(serializedInputSplit, jobConf);
+  }
+
+  @Override
+  public InputSplit newInstance() {
+    return inputSplit;
+  }
+
+  @NamedParameter
+  public static final class SerializedInputSplit implements Name<String> {
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/JobConfExternalConstructor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/JobConfExternalConstructor.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/JobConfExternalConstructor.java
new file mode 100644
index 0000000..67be9a7
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/JobConfExternalConstructor.java
@@ -0,0 +1,88 @@
+/**
+ * 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.reef.io.data.loading.impl;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.InputFormat;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.reef.tang.ExternalConstructor;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class JobConfExternalConstructor implements ExternalConstructor<JobConf> {
+
+  private static final Logger LOG = Logger.getLogger(JobConfExternalConstructor.class.getName());
+
+  private final String inputFormatClassName;
+  private final String inputPath;
+
+  @Inject
+  public JobConfExternalConstructor(
+      final @Parameter(InputFormatClass.class) String inputFormatClassName,
+      final @Parameter(InputPath.class) String inputPath) {
+    this.inputFormatClassName = inputFormatClassName;
+    this.inputPath = inputPath;
+  }
+
+  @SuppressWarnings({"unchecked", "rawtypes"})
+  @Override
+  public JobConf newInstance() {
+
+    final JobConf jobConf = new JobConf();
+
+    try {
+
+      final Class<? extends InputFormat> inputFormatClass =
+          (Class<? extends InputFormat>) Class.forName(this.inputFormatClassName);
+
+      jobConf.setInputFormat(inputFormatClass);
+
+      final Method addInputPath =
+          inputFormatClass.getMethod("addInputPath", JobConf.class, Path.class);
+
+      addInputPath.invoke(inputFormatClass, jobConf, new Path(this.inputPath));
+
+    } catch (final ClassNotFoundException ex) {
+      throw new RuntimeException("InputFormat: " + this.inputFormatClassName
+          + " ClassNotFoundException while creating newInstance of JobConf", ex);
+    } catch (final InvocationTargetException | IllegalAccessException ex) {
+      throw new RuntimeException("InputFormat: " + this.inputFormatClassName
+          + ".addInputPath() method exists, but cannot be called.", ex);
+    } catch (final NoSuchMethodException ex) {
+      LOG.log(Level.INFO, "{0}.addInputPath() method does not exist", this.inputFormatClassName);
+    }
+
+    return jobConf;
+  }
+
+  @NamedParameter()
+  public static final class InputFormatClass implements Name<String> {
+  }
+
+  @NamedParameter(default_value = "NULL")
+  public static final class InputPath implements Name<String> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/NumberedSplit.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/NumberedSplit.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/NumberedSplit.java
new file mode 100644
index 0000000..6cef3b7
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/NumberedSplit.java
@@ -0,0 +1,65 @@
+/**
+ * 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.reef.io.data.loading.impl;
+
+import org.apache.hadoop.mapred.InputSplit;
+
+/**
+ * A tuple of an object of type E and an integer index
+ * Used inside {@link EvaluatorToPartitionMapper} to
+ * mark the partitions associated with each {@link InputSplit}
+ *
+ * @param <E>
+ */
+final class NumberedSplit<E> implements Comparable<NumberedSplit<E>> {
+  private final E entry;
+  private final int index;
+
+  public NumberedSplit(final E entry, final int index) {
+    super();
+    if (entry == null) {
+      throw new IllegalArgumentException("Entry cannot be null");
+    }
+    this.entry = entry;
+    this.index = index;
+  }
+
+  public E getEntry() {
+    return entry;
+  }
+
+  public int getIndex() {
+    return index;
+  }
+
+  @Override
+  public String toString() {
+    return "InputSplit-" + index;
+  }
+
+  @Override
+  public int compareTo(final NumberedSplit<E> o) {
+    if (this.index == o.index)
+      return 0;
+    if (this.index < o.index)
+      return -1;
+    else
+      return 1;
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/WritableSerializer.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/WritableSerializer.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/WritableSerializer.java
new file mode 100644
index 0000000..80264b1
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/data/loading/impl/WritableSerializer.java
@@ -0,0 +1,93 @@
+/**
+ * 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.reef.io.data.loading.impl;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.hadoop.io.Writable;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.util.ReflectionUtils;
+import org.apache.reef.io.serialization.Codec;
+
+import java.io.*;
+
+/**
+ * A serializer class that serializes {@link Writable}s
+ * into String using the below {@link Codec} that
+ * encodes & decodes {@link Writable}s
+ * By default this stores the class name in the serialized
+ * form so that the specific type can be instantiated on
+ * de-serialization. However, this also needs the jobconf
+ * to passed in while de-serialization
+ */
+public class WritableSerializer {
+  public static <E extends Writable> String serialize(E writable) {
+    final WritableCodec<E> writableCodec = new WritableCodec<>();
+    return Base64.encodeBase64String(writableCodec.encode(writable));
+  }
+
+  public static <E extends Writable> E deserialize(String serializedWritable) {
+    final WritableCodec<E> writableCodec = new WritableCodec<>();
+    return writableCodec.decode(Base64.decodeBase64(serializedWritable));
+  }
+
+  public static <E extends Writable> E deserialize(String serializedWritable, JobConf jobConf) {
+    final WritableCodec<E> writableCodec = new WritableCodec<>(jobConf);
+    return writableCodec.decode(Base64.decodeBase64(serializedWritable));
+  }
+
+  static class WritableCodec<E extends Writable> implements Codec<E> {
+    private final JobConf jobConf;
+
+    public WritableCodec(JobConf jobConf) {
+      this.jobConf = jobConf;
+    }
+
+    public WritableCodec() {
+      this.jobConf = new JobConf();
+    }
+
+    @Override
+    public E decode(byte[] bytes) {
+      final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+      try (DataInputStream dais = new DataInputStream(bais)) {
+        final String className = dais.readUTF();
+        E writable = (E) ReflectionUtils.newInstance(Class.forName(className), jobConf);
+        writable.readFields(dais);
+        return writable;
+      } catch (IOException e) {
+        throw new RuntimeException("Could not de-serialize JobConf", e);
+      } catch (ClassNotFoundException e) {
+        throw new RuntimeException("Could not instantiate specific writable class", e);
+      }
+    }
+
+    @Override
+    public byte[] encode(E writable) {
+      final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      try (final DataOutputStream daos = new DataOutputStream(baos)) {
+        daos.writeUTF(writable.getClass().getName());
+        writable.write(daos);
+        return baos.toByteArray();
+      } catch (IOException e) {
+        throw new RuntimeException("Could not serialize JobConf", e);
+      }
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/Cache.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/Cache.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/Cache.java
new file mode 100644
index 0000000..718a576
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/Cache.java
@@ -0,0 +1,53 @@
+/**
+ * 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.reef.io.network;
+
+import org.apache.reef.exception.evaluator.NetworkException;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+
+/**
+ * Cache for network and naming services
+ */
+public interface Cache<K, V> {
+  /**
+   *  Constructs with timeout
+   *  key is evicted when it's not used for timeout milli-seconds
+   */
+
+  /**
+   * Returns a value for the key if cached; otherwise creates, caches and returns
+   * When it creates a value for a key, only one callable for the key is executed
+   *
+   * @param key      a key
+   * @param callable a value fetcher
+   * @return a value
+   * @throws NetworkException
+   */
+  public V get(K key, Callable<V> valueFetcher) throws ExecutionException;
+
+  /**
+   * Invalidates a key from the cache
+   *
+   * @param key a key
+   */
+  public void invalidate(K key);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/Connection.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/Connection.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/Connection.java
new file mode 100644
index 0000000..42d05f9
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/Connection.java
@@ -0,0 +1,52 @@
+/**
+ * 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.reef.io.network;
+
+import org.apache.reef.exception.evaluator.NetworkException;
+
+/**
+ * Connection between two end-points named by identifiers.
+ *
+ * @param <T> type
+ */
+public interface Connection<T> extends AutoCloseable {
+
+  /**
+   * Opens the connection.
+   *
+   * @throws NetworkException
+   */
+  void open() throws NetworkException;
+
+  /**
+   * Writes an object to the connection.
+   *
+   * @param obj
+   * @throws NetworkException
+   */
+  void write(T obj) throws NetworkException;
+
+  /**
+   * Closes the connection.
+   *
+   * @throws NetworkException
+   */
+  @Override
+  void close() throws NetworkException;
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/ConnectionFactory.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/ConnectionFactory.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/ConnectionFactory.java
new file mode 100644
index 0000000..40b28b0
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/ConnectionFactory.java
@@ -0,0 +1,37 @@
+/**
+ * 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.reef.io.network;
+
+import org.apache.reef.wake.Identifier;
+
+/**
+ * Factory that creates a new connection
+ *
+ * @param <T> type
+ */
+public interface ConnectionFactory<T> {
+
+  /**
+   * Creates a new connection
+   *
+   * @param destId a destination identifier
+   * @return a connection
+   */
+  public Connection<T> newConnection(Identifier destId);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/Message.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/Message.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/Message.java
new file mode 100644
index 0000000..1aaa7e0
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/Message.java
@@ -0,0 +1,50 @@
+/**
+ * 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.reef.io.network;
+
+import org.apache.reef.wake.Identifier;
+
+/**
+ * Network message
+ *
+ * @param <T>
+ */
+public interface Message<T> {
+
+  /**
+   * Gets a source identifier
+   *
+   * @return an identifier
+   */
+  Identifier getSrcId();
+
+  /**
+   * Gets a destination identifier
+   *
+   * @return an identifier
+   */
+  Identifier getDestId();
+
+  /**
+   * Gets data
+   *
+   * @return an iterable of data objects
+   */
+  Iterable<T> getData();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/TransportFactory.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/TransportFactory.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/TransportFactory.java
new file mode 100644
index 0000000..1443a46
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/TransportFactory.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.io.network;
+
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.TransportEvent;
+import org.apache.reef.wake.remote.transport.Transport;
+
+/**
+ * Factory that creates a transport
+ */
+public interface TransportFactory {
+
+  /**
+   * Creates a transport
+   *
+   * @param port          a listening port
+   * @param clientHandler a transport client-side handler
+   * @param serverHandler a transport server-side handler
+   * @param exHandler     an exception handler
+   * @return
+   */
+  public Transport create(int port,
+                          EventHandler<TransportEvent> clientHandler,
+                          EventHandler<TransportEvent> serverHandler,
+                          EventHandler<Exception> exHandler);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/exception/NetworkRuntimeException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/exception/NetworkRuntimeException.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/exception/NetworkRuntimeException.java
new file mode 100644
index 0000000..4424e8d
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/exception/NetworkRuntimeException.java
@@ -0,0 +1,54 @@
+/**
+ * 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.reef.io.network.exception;
+
+/**
+ * Network service resourcemanager exception
+ */
+public class NetworkRuntimeException extends RuntimeException {
+  private static final long serialVersionUID = 1L;
+
+  /**
+   * Constructs a new network resourcemanager exception with the specified detail message and cause
+   *
+   * @param s the detailed message
+   * @param e the cause
+   */
+  public NetworkRuntimeException(String s, Throwable e) {
+    super(s, e);
+  }
+
+  /**
+   * Constructs a new network resourcemanager exception with the specified detail message
+   *
+   * @param s the detailed message
+   */
+  public NetworkRuntimeException(String s) {
+    super(s);
+  }
+
+  /**
+   * Constructs a new network resourcemanager exception with the specified cause
+   *
+   * @param e the cause
+   */
+  public NetworkRuntimeException(Throwable e) {
+    super(e);
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/exception/ParentDeadException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/exception/ParentDeadException.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/exception/ParentDeadException.java
new file mode 100644
index 0000000..6e406d3
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/exception/ParentDeadException.java
@@ -0,0 +1,48 @@
+/**
+ * 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.reef.io.network.exception;
+
+/**
+ * This exception is thrown by a child task
+ * when it is told that its Parent died
+ */
+public class ParentDeadException extends Exception {
+
+  private static final long serialVersionUID = 7636542209271151579L;
+
+  public ParentDeadException() {
+  }
+
+  public ParentDeadException(final String message) {
+    super(message);
+  }
+
+  public ParentDeadException(final Throwable cause) {
+    super(cause);
+  }
+
+  public ParentDeadException(final String message, final Throwable cause) {
+    super(message, cause);
+  }
+
+  public ParentDeadException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) {
+    super(message, cause, enableSuppression, writableStackTrace);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/exception/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/exception/package-info.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/exception/package-info.java
new file mode 100644
index 0000000..df0d392
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/exception/package-info.java
@@ -0,0 +1,19 @@
+/**
+ * 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.reef.io.network.exception;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/BindNSToTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/BindNSToTask.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/BindNSToTask.java
new file mode 100644
index 0000000..e8c7842
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/BindNSToTask.java
@@ -0,0 +1,45 @@
+/**
+ * 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.reef.io.network.impl;
+
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.task.events.TaskStart;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.IdentifierFactory;
+
+import javax.inject.Inject;
+
+public class BindNSToTask implements EventHandler<TaskStart> {
+
+  private final NetworkService<?> ns;
+  private final IdentifierFactory idFac;
+
+  @Inject
+  public BindNSToTask(
+      final NetworkService<?> ns,
+      final @Parameter(NetworkServiceParameters.NetworkServiceIdentifierFactory.class) IdentifierFactory idFac) {
+    this.ns = ns;
+    this.idFac = idFac;
+  }
+
+  @Override
+  public void onNext(final TaskStart task) {
+    this.ns.registerId(this.idFac.getNewInstance(task.getId()));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/MessagingTransportFactory.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/MessagingTransportFactory.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/MessagingTransportFactory.java
new file mode 100644
index 0000000..e169624
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/MessagingTransportFactory.java
@@ -0,0 +1,60 @@
+/**
+ * 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.reef.io.network.impl;
+
+import org.apache.reef.io.network.TransportFactory;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.impl.SyncStage;
+import org.apache.reef.wake.remote.NetUtils;
+import org.apache.reef.wake.remote.impl.TransportEvent;
+import org.apache.reef.wake.remote.transport.Transport;
+import org.apache.reef.wake.remote.transport.netty.NettyMessagingTransport;
+
+import javax.inject.Inject;
+
+/**
+ * Factory that creates a messaging transport
+ */
+public class MessagingTransportFactory implements TransportFactory {
+
+  @Inject
+  public MessagingTransportFactory() {
+  }
+
+  /**
+   * Creates a transport
+   *
+   * @param port          a listening port
+   * @param clientHandler a transport client side handler
+   * @param serverHandler a transport server side handler
+   * @param exHandler     a exception handler
+   */
+  @Override
+  public Transport create(final int port,
+                          final EventHandler<TransportEvent> clientHandler,
+                          final EventHandler<TransportEvent> serverHandler,
+                          final EventHandler<Exception> exHandler) {
+
+    final Transport transport = new NettyMessagingTransport(NetUtils.getLocalAddress(),
+        port, new SyncStage<>(clientHandler), new SyncStage<>(serverHandler), 3, 10000);
+
+    transport.registerErrorHandler(exHandler);
+    return transport;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NSConnection.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NSConnection.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NSConnection.java
new file mode 100644
index 0000000..a4b4538
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NSConnection.java
@@ -0,0 +1,134 @@
+/**
+ * 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.reef.io.network.impl;
+
+import org.apache.reef.exception.evaluator.NetworkException;
+import org.apache.reef.io.network.Connection;
+import org.apache.reef.io.network.naming.exception.NamingException;
+import org.apache.reef.wake.Identifier;
+import org.apache.reef.wake.remote.Codec;
+import org.apache.reef.wake.remote.transport.Link;
+import org.apache.reef.wake.remote.transport.LinkListener;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A connection from the network service
+ */
+class NSConnection<T> implements Connection<T> {
+
+  private static final Logger LOG = Logger.getLogger(NSConnection.class.getName());
+
+  private final Identifier srcId;
+  private final Identifier destId;
+  private final LinkListener<NSMessage<T>> listener;
+  private final NetworkService<T> service;
+  private final Codec<NSMessage<T>> codec;
+
+  // link can change when an endpoint physical address changes
+  private Link<NSMessage<T>> link;
+
+  /**
+   * Constructs a connection
+   *
+   * @param srcId    a source identifier
+   * @param destId   a destination identifier
+   * @param listener a link listener
+   * @param service  a network service
+   */
+  NSConnection(final Identifier srcId, final Identifier destId,
+               final LinkListener<T> listener, final NetworkService<T> service) {
+    this.srcId = srcId;
+    this.destId = destId;
+    this.listener = new NSMessageLinkListener<>(listener);
+    this.service = service;
+    this.codec = new NSMessageCodec<>(service.getCodec(), service.getIdentifierFactory());
+  }
+
+  /**
+   * Opens the connection.
+   */
+  @Override
+  public void open() throws NetworkException {
+
+    LOG.log(Level.FINE, "looking up {0}", this.destId);
+
+    try {
+      // naming lookup
+      final InetSocketAddress addr = this.service.getNameClient().lookup(this.destId);
+      if (addr == null) {
+        final NetworkException ex = new NamingException("Cannot resolve " + this.destId);
+        LOG.log(Level.WARNING, "Cannot resolve " + this.destId, ex);
+        throw ex;
+      }
+
+      LOG.log(Level.FINE, "Resolved {0} to {1}", new Object[]{this.destId, addr});
+
+      // connect to a remote address
+      this.link = this.service.getTransport().open(addr, this.codec, this.listener);
+      LOG.log(Level.FINE, "Transport returned a link {0}", this.link);
+
+    } catch (final Exception ex) {
+      LOG.log(Level.WARNING, "Could not open " + this.destId, ex);
+      throw new NetworkException(ex);
+    }
+  }
+
+  /**
+   * Writes an object to the connection
+   *
+   * @param obj an object of type T
+   * @throws a network exception
+   */
+  @Override
+  public void write(final T obj) throws NetworkException {
+    try {
+      this.link.write(new NSMessage<T>(this.srcId, this.destId, obj));
+    } catch (final IOException ex) {
+      LOG.log(Level.WARNING, "Could not write to " + this.destId, ex);
+      throw new NetworkException(ex);
+    }
+  }
+
+  /**
+   * Closes the connection and unregisters it from the service
+   */
+  @Override
+  public void close() throws NetworkException {
+    this.service.remove(this.destId);
+  }
+}
+
+/**
+ * No-op link listener
+ *
+ * @param <T>
+ */
+final class NSMessageLinkListener<T> implements LinkListener<NSMessage<T>> {
+
+  NSMessageLinkListener(final LinkListener<T> listener) {
+  }
+
+  @Override
+  public void messageReceived(final NSMessage<T> message) {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NSMessage.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NSMessage.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NSMessage.java
new file mode 100644
index 0000000..063b9e3
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NSMessage.java
@@ -0,0 +1,90 @@
+/**
+ * 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.reef.io.network.impl;
+
+import org.apache.reef.io.network.Message;
+import org.apache.reef.wake.Identifier;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Network service message that implements the Message interface
+ *
+ * @param <T> type
+ */
+public class NSMessage<T> implements Message<T> {
+  private final Identifier srcId;
+  private final Identifier destId;
+  private final List<T> data;
+
+  /**
+   * Constructs a network service message
+   *
+   * @param srcId  a source identifier
+   * @param destId a destination identifier
+   * @param data   data of type T
+   */
+  public NSMessage(final Identifier srcId, final Identifier destId, final T data) {
+    this.srcId = srcId;
+    this.destId = destId;
+    this.data = new ArrayList<T>(1);
+    this.data.add(data);
+  }
+
+  /**
+   * Constructs a network service message
+   *
+   * @param srcId  a source identifier
+   * @param destId a destination identifier
+   * @param data   a list of data of type T
+   */
+  public NSMessage(final Identifier srcId, final Identifier destId, final List<T> data) {
+    this.srcId = srcId;
+    this.destId = destId;
+    this.data = data;
+  }
+
+  /**
+   * Gets a source identifier
+   *
+   * @return an identifier
+   */
+  public Identifier getSrcId() {
+    return srcId;
+  }
+
+  /**
+   * Gets a destination identifier
+   *
+   * @return an identifier
+   */
+  public Identifier getDestId() {
+    return destId;
+  }
+
+  /**
+   * Gets data
+   *
+   * @return data
+   */
+  public List<T> getData() {
+    return data;
+  }
+}


[05/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/main/java/org/apache/reef/tests/yarn/failure/FailureREEF.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/main/java/org/apache/reef/tests/yarn/failure/FailureREEF.java b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/yarn/failure/FailureREEF.java
new file mode 100644
index 0000000..aa4b5fd
--- /dev/null
+++ b/lang/java/reef-tests/src/main/java/org/apache/reef/tests/yarn/failure/FailureREEF.java
@@ -0,0 +1,120 @@
+/**
+ * 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.reef.tests.yarn.failure;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.runtime.yarn.client.YarnClientConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.CommandLine;
+import org.apache.reef.util.EnvironmentUtils;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public final class FailureREEF {
+
+  public static final int NUM_LOCAL_THREADS = 16;
+
+  private static final Logger LOG = Logger.getLogger(FailureREEF.class.getName());
+
+  private static Configuration parseCommandLine(final String[] aArgs) {
+    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    try {
+      new CommandLine(cb)
+          .registerShortNameOfClass(Local.class)
+          .registerShortNameOfClass(TimeOut.class)
+          .processCommandLine(aArgs);
+      return cb.build();
+    } catch (final BindException | IOException ex) {
+      final String msg = "Unable to parse command line";
+      LOG.log(Level.SEVERE, msg, ex);
+      throw new RuntimeException(msg, ex);
+    }
+  }
+
+  /**
+   * @return (immutable) TANG Configuration object.
+   * @throws BindException      if configuration injector fails.
+   * @throws InjectionException if the Local.class parameter is not injected.
+   */
+  private static Configuration getRunTimeConfiguration(final boolean isLocal) throws BindException {
+
+    final Configuration runtimeConfiguration;
+
+    if (isLocal) {
+      LOG.log(Level.INFO, "Running Failure demo on the local runtime");
+      runtimeConfiguration = LocalRuntimeConfiguration.CONF
+          .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, NUM_LOCAL_THREADS)
+          .build();
+    } else {
+      LOG.log(Level.INFO, "Running Failure demo on YARN");
+      runtimeConfiguration = YarnClientConfiguration.CONF.build();
+    }
+
+    return runtimeConfiguration;
+  }
+
+  public static LauncherStatus runFailureReef(
+      final Configuration runtimeConfig, final int timeout) throws InjectionException {
+
+    final Configuration driverConf = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(FailureDriver.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "FailureREEF")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, FailureDriver.StartHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, FailureDriver.EvaluatorAllocatedHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_FAILED, FailureDriver.EvaluatorFailedHandler.class)
+        .build();
+
+    final LauncherStatus state = DriverLauncher.getLauncher(runtimeConfig).run(driverConf, timeout);
+    LOG.log(Level.INFO, "REEF job completed: {0}", state);
+    return state;
+  }
+
+  public static void main(final String[] args) throws InjectionException {
+    final Configuration commandLineConf = parseCommandLine(args);
+    final Injector injector = Tang.Factory.getTang().newInjector(commandLineConf);
+    final boolean isLocal = injector.getNamedInstance(Local.class);
+    final int jobTimeout = injector.getNamedInstance(TimeOut.class) * 60 * 1000;
+    runFailureReef(getRunTimeConfiguration(isLocal), jobTimeout);
+  }
+
+  /**
+   * Command line parameter = true to run locally, or false to run on YARN.
+   */
+  @NamedParameter(doc = "Whether or not to run on the local runtime",
+      short_name = "local", default_value = "true")
+  public static final class Local implements Name<Boolean> {
+  }
+
+  @NamedParameter(doc = "Number of minutes before timeout",
+      short_name = "timeout", default_value = "2")
+  public static final class TimeOut implements Name<Integer> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/AllTestsSuite.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/AllTestsSuite.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/AllTestsSuite.java
new file mode 100644
index 0000000..36db2d3
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/AllTestsSuite.java
@@ -0,0 +1,54 @@
+/**
+ * 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.reef.tests;
+
+import org.apache.reef.tests.close_eval.CloseEvaluatorTest;
+import org.apache.reef.tests.driver.DriverTest;
+import org.apache.reef.tests.evaluatorfailure.EvaluatorFailureTest;
+import org.apache.reef.tests.evaluatorreuse.EvaluatorReuseTest;
+import org.apache.reef.tests.evaluatorsize.EvaluatorSizeTest;
+import org.apache.reef.tests.examples.ExamplesTestSuite;
+import org.apache.reef.tests.fail.FailTestSuite;
+import org.apache.reef.tests.files.FileResourceTest;
+import org.apache.reef.tests.messaging.driver.DriverMessagingTest;
+import org.apache.reef.tests.messaging.task.TaskMessagingTest;
+import org.apache.reef.tests.statepassing.StatePassingTest;
+import org.apache.reef.tests.subcontexts.SubContextTest;
+import org.apache.reef.tests.taskresubmit.TaskResubmitTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+    DriverTest.class,
+    EvaluatorReuseTest.class,
+    EvaluatorSizeTest.class,
+    FailTestSuite.class,
+    FileResourceTest.class,
+    DriverMessagingTest.class,
+    TaskMessagingTest.class,
+    StatePassingTest.class,
+    SubContextTest.class,
+    TaskResubmitTest.class,
+    CloseEvaluatorTest.class,
+    EvaluatorFailureTest.class,
+    ExamplesTestSuite.class
+})
+public final class AllTestsSuite {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/FailureTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/FailureTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/FailureTest.java
new file mode 100644
index 0000000..2c02d93
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/FailureTest.java
@@ -0,0 +1,54 @@
+/**
+ * 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.reef.tests;
+
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.yarn.failure.FailureREEF;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class FailureTest {
+
+  private static final int JOB_TIMEOUT = 2 * 60 * 1000;
+
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  @Test
+  public void testFailureRestart() throws InjectionException {
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    final LauncherStatus status = FailureREEF.runFailureReef(runtimeConfiguration, this.testEnvironment.getTestTimeout());
+
+    Assert.assertTrue("FailureReef failed: " + status, status.isSuccess());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/LocalTestEnvironment.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/LocalTestEnvironment.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/LocalTestEnvironment.java
new file mode 100644
index 0000000..345b49c
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/LocalTestEnvironment.java
@@ -0,0 +1,68 @@
+/**
+ * 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.reef.tests;
+
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.tang.Configuration;
+
+/**
+ * A TestEnvironment for the local resourcemanager.
+ */
+public final class LocalTestEnvironment extends TestEnvironmentBase implements TestEnvironment {
+
+  /**
+   * The number of threads allocated to the local runtime.
+   */
+  public static final int NUMBER_OF_THREADS = 4;
+  // Used to make sure the tests call the methods in the right order.
+  private boolean ready = false;
+
+  @Override
+  public synchronized final void setUp() {
+    this.ready = true;
+  }
+
+  @Override
+  public synchronized final Configuration getRuntimeConfiguration() {
+    assert (this.ready);
+    final String rootFolder = System.getProperty("org.apache.reef.runtime.local.folder");
+    if (null == rootFolder) {
+      return LocalRuntimeConfiguration.CONF
+          .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, NUMBER_OF_THREADS)
+          .build();
+    } else {
+      return LocalRuntimeConfiguration.CONF
+          .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, NUMBER_OF_THREADS)
+          .set(LocalRuntimeConfiguration.RUNTIME_ROOT_FOLDER, rootFolder)
+          .build();
+
+    }
+  }
+
+  @Override
+  public synchronized final void tearDown() {
+    assert (this.ready);
+    this.ready = false;
+  }
+
+  @Override
+  public int getTestTimeout() {
+    return 60000; // 1 min.
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/MesosTestEnvironment.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/MesosTestEnvironment.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/MesosTestEnvironment.java
new file mode 100644
index 0000000..557c8b8
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/MesosTestEnvironment.java
@@ -0,0 +1,68 @@
+/**
+ * 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.reef.tests;
+
+import org.apache.reef.runtime.mesos.client.MesosClientConfiguration;
+import org.apache.reef.runtime.yarn.client.YarnClientConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+
+/**
+ * A TestEnvironment for the Mesos resourcemanager.
+ */
+public final class MesosTestEnvironment extends TestEnvironmentBase implements TestEnvironment {
+
+  // Used to make sure the tests call the methods in the right order.
+  private boolean ready = false;
+
+  @Override
+  public synchronized final void setUp() {
+    this.ready = true;
+  }
+
+  @Override
+  public synchronized final Configuration getRuntimeConfiguration() {
+    assert (this.ready);
+    try {
+      if (System.getenv("REEF_TEST_MESOS_MASTER_IP").equals("")) {
+        throw new RuntimeException("REEF_TEST_MESOS_MASTER_IP unspecified");
+      }
+
+      final String masterIp = System.getenv("REEF_TEST_MESOS_MASTER_IP");
+      return MesosClientConfiguration.CONF
+          .set(MesosClientConfiguration.MASTER_IP, masterIp)
+          .build();
+    } catch (final BindException ex) {
+      throw new RuntimeException(ex);
+    }
+  }
+
+  @Override
+  public synchronized final void tearDown() {
+    assert (this.ready);
+    this.ready = false;
+  }
+
+  @Override
+  public int getTestTimeout() {
+    return 300000; // 5 minutes
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/ProbabilisticTests.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/ProbabilisticTests.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/ProbabilisticTests.java
new file mode 100644
index 0000000..e9001f2
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/ProbabilisticTests.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.tests;
+
+import org.apache.reef.tests.taskcounting.TaskCountingTest;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * A test suite for probabilistic tests: Tests that run man, many times in order to check for HeisenBugs.
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+    TaskCountingTest.class
+})
+public final class ProbabilisticTests {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironment.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironment.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironment.java
new file mode 100644
index 0000000..664b526
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironment.java
@@ -0,0 +1,58 @@
+/**
+ * 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.reef.tests;
+
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+
+/**
+ * Environment for REEF unit tests.
+ * <p/>
+ * The idea is to use an instance of this class to gain access
+ * to a REEF resource manager environment in order to make the tests
+ * portable amongst REEF runtimes (e.g. YARN, Local, ...)
+ */
+public interface TestEnvironment {
+
+  /**
+   * Setup the test environment. This is typically called in a method @Before the actual test.
+   */
+  void setUp();
+
+  /**
+   * @return a Configuration used to obtain a REEF resourcemanager for the tests.
+   * E.g. the local or YARN resource manager.
+   */
+  Configuration getRuntimeConfiguration();
+
+  /**
+   * Cleanup the test environment. This is typically called in a method @After the actual test.
+   */
+  void tearDown();
+
+  /**
+   * Return test timeout in milliseconds
+   * (we need longer timeouts on YARN comparing than in local mode).
+   *
+   * @return test timeout in milliseconds.
+   */
+  int getTestTimeout();
+
+  LauncherStatus run(final Configuration driverConfiguration);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironmentBase.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironmentBase.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironmentBase.java
new file mode 100644
index 0000000..1f925b0
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironmentBase.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.tests;
+
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.InjectionException;
+
+/**
+ * Abstract base class for TestEnvironments
+ */
+public abstract class TestEnvironmentBase implements TestEnvironment {
+
+  @Override
+  public LauncherStatus run(final Configuration driverConfiguration) {
+    try {
+      return DriverLauncher.getLauncher(getRuntimeConfiguration()).run(driverConfiguration, getTestTimeout());
+    } catch (final InjectionException e) {
+      throw new RuntimeException(e);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironmentFactory.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironmentFactory.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironmentFactory.java
new file mode 100644
index 0000000..58f2072
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestEnvironmentFactory.java
@@ -0,0 +1,54 @@
+/**
+ * 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.reef.tests;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Factory for the TestEnvironment.
+ */
+public final class TestEnvironmentFactory {
+
+  private final static Logger LOG = Logger.getLogger(TestEnvironmentFactory.class.getName());
+
+  /**
+   * If $REEF_TEST_YARN environment variable is not set or is set to false,
+   * return the local test environment; otherwise, return the one for YARN.
+   *
+   * @return a new TestEnvironment instance.
+   */
+  public static TestEnvironment getNewTestEnvironment() {
+    final boolean isYarn = Boolean.parseBoolean(System.getenv("REEF_TEST_YARN"));
+    final boolean isMesos = Boolean.parseBoolean(System.getenv("REEF_TEST_MESOS"));
+
+    if (isYarn && isMesos) {
+      throw new RuntimeException("Cannot test on two runtimes at once");
+    } else if (isYarn) {
+      LOG.log(Level.INFO, "Running tests on YARN");
+      return new YarnTestEnvironment();
+    } else if (isMesos) {
+      LOG.log(Level.INFO, "Running tests on Mesos");
+      return new MesosTestEnvironment();
+    } else {
+      LOG.log(Level.INFO, "Running tests on Local");
+      return new LocalTestEnvironment();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestUtils.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestUtils.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestUtils.java
new file mode 100644
index 0000000..c901ec2
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/TestUtils.java
@@ -0,0 +1,63 @@
+/**
+ * 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.reef.tests;
+
+import org.apache.reef.client.LauncherStatus;
+import org.junit.Assert;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public final class TestUtils {
+
+  private static final Logger LOG = Logger.getLogger(TestUtils.class.getName());
+
+  /**
+   * Make sure the launcher status is FAILED and it has the specified exception in the stack.
+   *
+   * @param status launcher status. Must be FAILED for test to pass.
+   * @param clazz  resourcemanager exception that should be in the stack of exceptions of the launcher status.
+   */
+  public static void assertLauncherFailure(
+      final LauncherStatus status, final Class<? extends Throwable> clazz) {
+    Assert.assertEquals(LauncherStatus.FAILED, status);
+    final Throwable ex = status.getError().orElse(null);
+    if (!hasCause(ex, clazz)) {
+      LOG.log(Level.WARNING, "Unexpected Error: " + status, status.getError().get());
+      Assert.fail("Unexpected error: " + status.getError().orElse(null));
+    }
+  }
+
+  /**
+   * Return True if cause chain of exception ex contains
+   * exception of class clazz (or one inherited from it).
+   *
+   * @param ex    exception to analyze (can be null)
+   * @param clazz class inherited from type Throwable.
+   * @return True if ex or any other exception in its cause chain is instance of class clazz.
+   */
+  public static boolean hasCause(Throwable ex, final Class<? extends Throwable> clazz) {
+    for (; ex != null; ex = ex.getCause()) {
+      if (clazz.isInstance(ex)) {
+        return true;
+      }
+    }
+    return false;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/YarnTestEnvironment.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/YarnTestEnvironment.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/YarnTestEnvironment.java
new file mode 100644
index 0000000..409f091
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/YarnTestEnvironment.java
@@ -0,0 +1,60 @@
+/**
+ * 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.reef.tests;
+
+import org.apache.reef.runtime.yarn.client.YarnClientConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+
+/**
+ * A TestEnvironment for the YARN resourcemanager.
+ */
+public final class YarnTestEnvironment extends TestEnvironmentBase implements TestEnvironment {
+
+  // Used to make sure the tests call the methods in the right order.
+  private boolean ready = false;
+
+  @Override
+  public synchronized final void setUp() {
+    this.ready = true;
+  }
+
+  @Override
+  public synchronized final Configuration getRuntimeConfiguration() {
+    assert (this.ready);
+    try {
+      return YarnClientConfiguration.CONF.build();
+    } catch (final BindException ex) {
+      throw new RuntimeException(ex);
+    }
+  }
+
+  @Override
+  public synchronized final void tearDown() {
+    assert (this.ready);
+    this.ready = false;
+  }
+
+  @Override
+  public int getTestTimeout() {
+    return 300000; // 5 minutes
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/close_eval/CloseEvaluatorDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/close_eval/CloseEvaluatorDriver.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/close_eval/CloseEvaluatorDriver.java
new file mode 100644
index 0000000..30821b6
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/close_eval/CloseEvaluatorDriver.java
@@ -0,0 +1,65 @@
+/**
+ * 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.reef.tests.close_eval;
+
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+final class CloseEvaluatorDriver {
+
+  private static final Logger LOG = Logger.getLogger(CloseEvaluatorDriver.class.getName());
+
+  private static final int NUM_EVALUATORS = 16;
+
+  private final EvaluatorRequestor requestor;
+
+  @Inject
+  CloseEvaluatorDriver(final EvaluatorRequestor requestor) {
+    this.requestor = requestor;
+  }
+
+  final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime time) {
+
+      LOG.log(Level.FINE, "StartTime: {0} :: request {1} evaluators",
+          new Object[]{time, NUM_EVALUATORS});
+
+      requestor.submit(EvaluatorRequest.newBuilder()
+          .setNumber(NUM_EVALUATORS).setMemory(256).setNumberOfCores(1).build());
+    }
+  }
+
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator eval) {
+      LOG.log(Level.FINE, "Allocated Evaluator: {0} :: closing", eval);
+      eval.close();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/close_eval/CloseEvaluatorTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/close_eval/CloseEvaluatorTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/close_eval/CloseEvaluatorTest.java
new file mode 100644
index 0000000..7766f50
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/close_eval/CloseEvaluatorTest.java
@@ -0,0 +1,68 @@
+/**
+ * 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.reef.tests.close_eval;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests evaluator allocation by asking for allocations that it immediately closes.
+ */
+public class CloseEvaluatorTest {
+
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @Test
+  public void testCloseEvaluator() throws BindException, InjectionException {
+
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    final Configuration driverConfiguration = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(CloseEvaluatorDriver.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_CloseEvaluatorTest")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, CloseEvaluatorDriver.StartHandler.class)
+        .build();
+
+    final LauncherStatus status = DriverLauncher.getLauncher(runtimeConfiguration)
+        .run(driverConfiguration, this.testEnvironment.getTestTimeout());
+
+    Assert.assertTrue("Job state after execution: " + status, status.isSuccess());
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/driver/DriverTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/driver/DriverTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/driver/DriverTest.java
new file mode 100644
index 0000000..9a56c80
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/driver/DriverTest.java
@@ -0,0 +1,68 @@
+/**
+ * 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.reef.tests.driver;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * This tests whether the noop driver gets shutdown properly.
+ */
+public class DriverTest {
+
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @Test
+  public void testSimpleDriver() throws BindException, InjectionException {
+
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    final Configuration driverConfiguration = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(DriverTestStartHandler.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_DriverTest")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, DriverTestStartHandler.class)
+        .build();
+
+    final LauncherStatus status = DriverLauncher.getLauncher(runtimeConfiguration)
+        .run(driverConfiguration, this.testEnvironment.getTestTimeout());
+
+    Assert.assertTrue("Job state after execution: " + status, status.isSuccess());
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTest.java
new file mode 100644
index 0000000..a2dcc4b
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTest.java
@@ -0,0 +1,66 @@
+/**
+ * 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.reef.tests.evaluatorexit;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.tests.library.driver.OnDriverStartedAllocateOne;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.logging.Logger;
+
+/**
+ * Tests whether an unexpected Evaluator exit (via System.exit()) is reported as a FailedEvaluator to the Driver.
+ */
+public final class EvaluatorExitTest {
+  private static final Logger LOG = Logger.getLogger(EvaluatorExitTest.class.getName());
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  @Test
+  public void testEvaluatorExit() {
+    final Configuration driverConfiguration = DriverConfiguration.CONF
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_EvaluatorExit")
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(EvaluatorExitTestDriver.class))
+        .set(DriverConfiguration.ON_DRIVER_STARTED, OnDriverStartedAllocateOne.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, EvaluatorExitTestDriver.EvaluatorAllocatedHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_FAILED, EvaluatorExitTestDriver.EvaluatorFailureHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_STOP, EvaluatorExitTestDriver.StopHandler.class)
+        .build();
+    final LauncherStatus status = this.testEnvironment.run(driverConfiguration);
+    Assert.assertTrue("Job state after execution: " + status, status.isSuccess());
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTestDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTestDriver.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTestDriver.java
new file mode 100644
index 0000000..86a7be5
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTestDriver.java
@@ -0,0 +1,79 @@
+/**
+ * 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.reef.tests.evaluatorexit;
+
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.FailedEvaluator;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StopTime;
+
+import javax.inject.Inject;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+final class EvaluatorExitTestDriver {
+  private static final Logger LOG = Logger.getLogger(EvaluatorExitTestDriver.class.getName());
+  private final AtomicBoolean failedEvaluatorReceived = new AtomicBoolean(false);
+
+  @Inject
+  EvaluatorExitTestDriver() {
+  }
+
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+
+    @Override
+    public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+      final Configuration taskConfiguration = TaskConfiguration.CONF
+          .set(TaskConfiguration.IDENTIFIER, "EvaluatorExitTestTask")
+          .set(TaskConfiguration.TASK, EvaluatorExitTestTask.class)
+          .build();
+      allocatedEvaluator.submitTask(taskConfiguration);
+    }
+  }
+
+  final class EvaluatorFailureHandler implements EventHandler<FailedEvaluator> {
+
+    @Override
+    public void onNext(final FailedEvaluator failedEvaluator) {
+      LOG.log(Level.FINEST, "Received a FailedEvaluator for Evaluator {0}", failedEvaluator.getId());
+      failedEvaluatorReceived.set(true);
+    }
+  }
+
+  final class StopHandler implements EventHandler<StopTime> {
+
+    @Override
+    public void onNext(final StopTime stopTime) {
+      synchronized (failedEvaluatorReceived) {
+        if (failedEvaluatorReceived.get()) {
+          LOG.log(Level.FINE, "Received an expected FailedEvaluator before exit. All good.");
+        } else {
+          throw new DriverSideFailure("Did not receive an expected FailedEvaluator.");
+        }
+      }
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTestTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTestTask.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTestTask.java
new file mode 100644
index 0000000..b19bec0
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/EvaluatorExitTestTask.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.tests.evaluatorexit;
+
+import org.apache.reef.task.Task;
+
+import javax.inject.Inject;
+
+/**
+ * Merely calls System.exit()
+ */
+final class EvaluatorExitTestTask implements Task {
+
+  @Inject
+  EvaluatorExitTestTask() {
+  }
+
+  @Override
+  public byte[] call(final byte[] memento) throws Exception {
+    System.exit(0);
+    return null;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/package-info.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/package-info.java
new file mode 100644
index 0000000..fb4fe07
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorexit/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * This tests whether an unexpected Evaluator exit (via System.exit()) is reported as a FailedEvaluator to the Driver.
+ */
+package org.apache.reef.tests.evaluatorexit;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/EvaluatorFailureDuringAlarmDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/EvaluatorFailureDuringAlarmDriver.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/EvaluatorFailureDuringAlarmDriver.java
new file mode 100644
index 0000000..2845601
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/EvaluatorFailureDuringAlarmDriver.java
@@ -0,0 +1,106 @@
+/**
+ * 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.reef.tests.evaluatorfailure;
+
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.FailedEvaluator;
+import org.apache.reef.driver.task.FailedTask;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tests.TestUtils;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StopTime;
+
+import javax.inject.Inject;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+final class EvaluatorFailureDuringAlarmDriver {
+  private static final Logger LOG = Logger.getLogger(EvaluatorFailureDuringAlarmDriver.class.getName());
+  private final AtomicBoolean failedEvaluatorReceived = new AtomicBoolean(false);
+  private final AtomicBoolean otherFailuresReceived = new AtomicBoolean(false);
+
+  @Inject
+  EvaluatorFailureDuringAlarmDriver() {
+  }
+
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+
+    @Override
+    public void onNext(AllocatedEvaluator allocatedEvaluator) {
+      final Configuration contextConfiguration = ContextConfiguration.CONF
+          .set(ContextConfiguration.IDENTIFIER, "FailingEvaluator")
+          .set(ContextConfiguration.ON_CONTEXT_STARTED, FailureSchedulingContextStartHandler.class)
+          .build();
+      allocatedEvaluator.submitContext(contextConfiguration);
+    }
+  }
+
+  final class EvaluatorFailureHandler implements EventHandler<FailedEvaluator> {
+
+    @Override
+    public void onNext(final FailedEvaluator failedEvaluator) {
+      if (TestUtils.hasCause(failedEvaluator.getEvaluatorException(), ExpectedException.class)) {
+        failedEvaluatorReceived.set(true);
+        LOG.log(Level.FINEST, "Received an expected exception. All good.");
+      } else {
+        throw new DriverSideFailure("Received an unexpected exception", failedEvaluator.getEvaluatorException());
+      }
+    }
+  }
+
+  final class ContextFailureHandler implements EventHandler<FailedContext> {
+    @Override
+    public void onNext(final FailedContext failedContext) {
+      LOG.log(Level.SEVERE, "Received FailedContext: {0}", failedContext);
+      otherFailuresReceived.set(true);
+    }
+  }
+
+  final class TaskFailureHandler implements EventHandler<FailedTask> {
+
+    @Override
+    public void onNext(final FailedTask failedTask) {
+      LOG.log(Level.SEVERE, "Received FailedTask: {0}", failedTask);
+      otherFailuresReceived.set(true);
+
+    }
+  }
+
+  final class StopHandler implements EventHandler<StopTime> {
+
+    @Override
+    public void onNext(final StopTime stopTime) {
+      if (failedEvaluatorReceived.get()) {
+        LOG.log(Level.FINEST, "Received FailedEvaluator.");
+      } else {
+        throw new DriverSideFailure("Never Received the FailedEvaluator.");
+      }
+
+      if (otherFailuresReceived.get()) {
+        throw new DriverSideFailure("Received more events than the FailedEvaluator.");
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/EvaluatorFailureTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/EvaluatorFailureTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/EvaluatorFailureTest.java
new file mode 100644
index 0000000..5aa1893
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/EvaluatorFailureTest.java
@@ -0,0 +1,75 @@
+/**
+ * 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.reef.tests.evaluatorfailure;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.tests.library.driver.OnDriverStartedAllocateOne;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests whether evaluator failures are generated properly.
+ */
+public class EvaluatorFailureTest {
+
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  /**
+   * Tests that only an EvaluatorFailure is generated by exceptions thrown on by an Alarm handler.
+   */
+  @Test
+  public void testEvaluatorFailureByAlarmHandler() throws InjectionException {
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    final Configuration driverConfiguration = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(EvaluatorFailureDuringAlarmDriver.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_EvaluatorFailureTest")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, OnDriverStartedAllocateOne.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, EvaluatorFailureDuringAlarmDriver.EvaluatorAllocatedHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_FAILED, EvaluatorFailureDuringAlarmDriver.EvaluatorFailureHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_FAILED, EvaluatorFailureDuringAlarmDriver.ContextFailureHandler.class)
+        .set(DriverConfiguration.ON_TASK_FAILED, EvaluatorFailureDuringAlarmDriver.TaskFailureHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_STOP, EvaluatorFailureDuringAlarmDriver.StopHandler.class)
+        .build();
+
+    final LauncherStatus status = DriverLauncher.getLauncher(runtimeConfiguration)
+        .run(driverConfiguration, this.testEnvironment.getTestTimeout());
+
+    Assert.assertTrue("EvaluatorFailureTest.testEvaluatorFailureByAlarmHandler() state = " + status, status.isSuccess());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/ExpectedException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/ExpectedException.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/ExpectedException.java
new file mode 100644
index 0000000..6c9c6a2
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/ExpectedException.java
@@ -0,0 +1,25 @@
+/**
+ * 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.reef.tests.evaluatorfailure;
+
+/**
+ * Exception thrown when one is expected.
+ */
+final class ExpectedException extends RuntimeException {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/FailureSchedulingContextStartHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/FailureSchedulingContextStartHandler.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/FailureSchedulingContextStartHandler.java
new file mode 100644
index 0000000..fc631da
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/FailureSchedulingContextStartHandler.java
@@ -0,0 +1,52 @@
+/**
+ * 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.reef.tests.evaluatorfailure;
+
+import org.apache.reef.evaluator.context.events.ContextStart;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.event.Alarm;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A handler for ContextStart that schedules an Alarm handler that throws an Exception.
+ */
+final class FailureSchedulingContextStartHandler implements EventHandler<ContextStart> {
+  private static final Logger LOG = Logger.getLogger(FailureSchedulingContextStartHandler.class.getName());
+  private final Clock clock;
+
+  @Inject
+  FailureSchedulingContextStartHandler(final Clock clock) {
+    this.clock = clock;
+  }
+
+  @Override
+  public void onNext(final ContextStart contextStart) {
+    this.clock.scheduleAlarm(0, new EventHandler<Alarm>() {
+      @Override
+      public void onNext(Alarm alarm) {
+        LOG.log(Level.INFO, "Invoked for {0}, throwing an Exception now.", alarm);
+        throw new ExpectedException();
+      }
+    });
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/package-info.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/package-info.java
new file mode 100644
index 0000000..7d1ae13
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorfailure/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Tests of evaluator failure generation.
+ */
+package org.apache.reef.tests.evaluatorfailure;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorreuse/EvaluatorReuseTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorreuse/EvaluatorReuseTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorreuse/EvaluatorReuseTest.java
new file mode 100644
index 0000000..aca50f7
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorreuse/EvaluatorReuseTest.java
@@ -0,0 +1,72 @@
+/**
+ * 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.reef.tests.evaluatorreuse;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.tests.library.driver.OnDriverStartedAllocateOne;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests the reuse of Evaluators across Tasks by submitting the EchoTask for a number of times.
+ */
+public class EvaluatorReuseTest {
+
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  @Test
+  public void testEvaluatorReuse() throws BindException, InjectionException {
+
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    final Configuration driverConfiguration = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(EvaluatorReuseTestDriver.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_EvaluatorReuseTest")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, OnDriverStartedAllocateOne.class)
+        .set(DriverConfiguration.ON_TASK_COMPLETED, EvaluatorReuseTestDriver.TaskCompletedHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, EvaluatorReuseTestDriver.EvaluatorAllocatedHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_ACTIVE, EvaluatorReuseTestDriver.ContextActiveHandler.class)
+        .build();
+
+    final LauncherStatus status = DriverLauncher.getLauncher(runtimeConfiguration)
+        .run(driverConfiguration, this.testEnvironment.getTestTimeout());
+
+    Assert.assertTrue("EvaluatorReuse state = " + status, status.isSuccess());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTest.java
new file mode 100644
index 0000000..b7422d0
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTest.java
@@ -0,0 +1,79 @@
+/**
+ * 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.reef.tests.evaluatorsize;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests whether Evaluator allocations requested with a given amount of memory are (over-)fullfilled.
+ */
+public class EvaluatorSizeTest {
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    this.testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  private LauncherStatus runEvaluatorSizeTest(final int megaBytes) throws BindException, InjectionException {
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    final Configuration testConfiguration = EvaluatorSizeTestConfiguration.CONF
+        .set(EvaluatorSizeTestConfiguration.MEMORY_SIZE, 777)
+        .build();
+
+    final Configuration driverConfiguration = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(this.getClass()))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_EvaluatorSizeTest-" + megaBytes)
+        .set(DriverConfiguration.ON_DRIVER_STARTED, EvaluatorSizeTestDriver.StartHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, EvaluatorSizeTestDriver.EvaluatorAllocatedHandler.class).build();
+
+    final Configuration mergedDriverConfiguration = Tang.Factory.getTang()
+        .newConfigurationBuilder(driverConfiguration, testConfiguration).build();
+
+    final LauncherStatus state = DriverLauncher.getLauncher(runtimeConfiguration)
+        .run(mergedDriverConfiguration, this.testEnvironment.getTestTimeout());
+    return state;
+  }
+
+
+  @Test
+  public void testEvaluatorSize() throws BindException, InjectionException {
+    final LauncherStatus state = runEvaluatorSizeTest(777);
+    Assert.assertTrue("Job state after execution: " + state, state.isSuccess());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTestConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTestConfiguration.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTestConfiguration.java
new file mode 100644
index 0000000..97719eb
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTestConfiguration.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.tests.evaluatorsize;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.RequiredParameter;
+
+public final class EvaluatorSizeTestConfiguration extends ConfigurationModuleBuilder {
+
+  public static final RequiredParameter<Integer> MEMORY_SIZE = new RequiredParameter<>();
+  public static final ConfigurationModule CONF = new EvaluatorSizeTestConfiguration()
+      .bindNamedParameter(MemorySize.class, MEMORY_SIZE)
+      .build();
+
+  @NamedParameter(doc = "The size of the Evaluator to test for")
+  public static class MemorySize implements Name<Integer> {
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTestDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTestDriver.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTestDriver.java
new file mode 100644
index 0000000..e91f8fc
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/EvaluatorSizeTestDriver.java
@@ -0,0 +1,97 @@
+/**
+ * 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.reef.tests.evaluatorsize;
+
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.util.logging.Logger;
+
+@Unit
+final class EvaluatorSizeTestDriver {
+  private static final Logger LOG = Logger.getLogger(EvaluatorSizeTestDriver.class.getName());
+
+  private final EvaluatorRequestor evaluatorRequestor;
+
+  private final int memorySize;
+
+  @Inject
+  public EvaluatorSizeTestDriver(final EvaluatorRequestor evaluatorRequestor,
+                                 final @Parameter(EvaluatorSizeTestConfiguration.MemorySize.class) int memorySize) {
+    this.evaluatorRequestor = evaluatorRequestor;
+    this.memorySize = memorySize;
+  }
+
+  final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime startTime) {
+      EvaluatorSizeTestDriver.this.evaluatorRequestor.submit(EvaluatorRequest.newBuilder()
+          .setNumber(1)
+          .setMemory(EvaluatorSizeTestDriver.this.memorySize)
+          .setNumberOfCores(1)
+          .build());
+    }
+  }
+
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+
+    @Override
+    public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+
+      final int evaluatorMemory = allocatedEvaluator.getEvaluatorDescriptor().getMemory();
+
+      if (evaluatorMemory < EvaluatorSizeTestDriver.this.memorySize) {
+        throw new DriverSideFailure(
+            "Got an Evaluator with too little RAM. Asked for " + EvaluatorSizeTestDriver.this.memorySize
+                + "MB, but got " + evaluatorMemory + "MB.");
+      }
+
+      // ALL good on the Driver side. Let's move on to the Task
+      try {
+        final Configuration taskConfiguration = TaskConfiguration.CONF
+            .set(TaskConfiguration.TASK, MemorySizeTask.class)
+            .set(TaskConfiguration.IDENTIFIER, "EvaluatorSizeTestTask")
+            .build();
+
+        final Configuration testConfiguration = EvaluatorSizeTestConfiguration.CONF
+            .set(EvaluatorSizeTestConfiguration.MEMORY_SIZE, EvaluatorSizeTestDriver.this.memorySize)
+            .build();
+
+        final Configuration mergedTaskConfiguration = Tang.Factory.getTang()
+            .newConfigurationBuilder(taskConfiguration, testConfiguration).build();
+
+        allocatedEvaluator.submitTask(mergedTaskConfiguration);
+
+      } catch (final BindException e) {
+        throw new DriverSideFailure("Unable to launch Task", e);
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/MemorySizeTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/MemorySizeTask.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/MemorySizeTask.java
new file mode 100644
index 0000000..3f64c46
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/MemorySizeTask.java
@@ -0,0 +1,49 @@
+/**
+ * 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.reef.tests.evaluatorsize;
+
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.task.Task;
+import org.apache.reef.tests.library.exceptions.TaskSideFailure;
+
+import javax.inject.Inject;
+
+final class MemorySizeTask implements Task {
+
+  private static final int MEGA = 1048576;
+  private static final int allowedDelta = 128; // TODO: This should'nt be necessary. Could be the perm size we set.
+  private final int memorySize;
+
+  @Inject
+  public MemorySizeTask(final @Parameter(EvaluatorSizeTestConfiguration.MemorySize.class) int memorySize) {
+    this.memorySize = memorySize;
+  }
+
+  @Override
+  public byte[] call(final byte[] memento) throws Exception {
+    final long maxHeapSizeInBytes = Runtime.getRuntime().maxMemory();
+
+    final long maxHeapSizeMB = maxHeapSizeInBytes / MEGA;
+    if (maxHeapSizeMB < (this.memorySize - allowedDelta)) {
+      throw new TaskSideFailure("Got an Evaluator with too little RAM. Asked for " + this.memorySize
+          + "MB, but got " + maxHeapSizeMB + "MB.");
+    }
+    return new byte[0];
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/package-info.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/package-info.java
new file mode 100644
index 0000000..e796438
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/evaluatorsize/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Test for the evaluator size request: Is it being honored by the resourcemanager?
+ */
+package org.apache.reef.tests.evaluatorsize;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/ExamplesTestSuite.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/ExamplesTestSuite.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/ExamplesTestSuite.java
new file mode 100644
index 0000000..4c48159
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/ExamplesTestSuite.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.tests.examples;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * A Test suite that runs the REEF example tests.
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+    TestHelloREEF.class,
+    TestRetainedEvaluators.class
+})
+public final class ExamplesTestSuite {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestHelloREEF.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestHelloREEF.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestHelloREEF.java
new file mode 100644
index 0000000..2eae5d4
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/examples/TestHelloREEF.java
@@ -0,0 +1,61 @@
+/**
+ * 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.reef.tests.examples;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.examples.hello.HelloDriver;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests whether the HelloREEF example runs sucesfully.
+ */
+public class TestHelloREEF {
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    this.testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  @Test
+  public void testHelloREEF() {
+    final Configuration driverConf = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(this.getClass()))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_HelloREEF")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, HelloDriver.StartHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HelloDriver.EvaluatorAllocatedHandler.class)
+        .build();
+    final LauncherStatus state = this.testEnvironment.run(driverConf);
+    Assert.assertTrue("Job state after execution: " + state, state.isSuccess());
+  }
+
+}


[26/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/package-info.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/package-info.java
new file mode 100644
index 0000000..f16facd
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/package-info.java
@@ -0,0 +1,19 @@
+/**
+ * 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.reef.io.network.naming;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/AvroUtils.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/AvroUtils.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/AvroUtils.java
new file mode 100644
index 0000000..73a1cd4
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/AvroUtils.java
@@ -0,0 +1,68 @@
+/**
+ * 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.reef.io.network.naming.serialization;
+
+import org.apache.avro.io.*;
+import org.apache.avro.specific.SpecificDatumReader;
+import org.apache.avro.specific.SpecificDatumWriter;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+/**
+ * Utilities for AVRO.
+ */
+final class AvroUtils {
+
+  private AvroUtils() {
+  }
+
+  /**
+   * Serializes the given avro object to a byte[]
+   *
+   * @param avroObject
+   * @param theClass
+   * @param <T>
+   * @return
+   */
+  static final <T> byte[] toBytes(T avroObject, Class<T> theClass) {
+    final DatumWriter<T> datumWriter = new SpecificDatumWriter<>(theClass);
+    final byte[] theBytes;
+    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+      final BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(out, null);
+      datumWriter.write(avroObject, encoder);
+      encoder.flush();
+      out.flush();
+      theBytes = out.toByteArray();
+    } catch (final IOException e) {
+      throw new RuntimeException("Unable to serialize an avro object", e);
+    }
+    return theBytes;
+  }
+
+  static <T> T fromBytes(final byte[] theBytes, final Class<T> theClass) {
+    final BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(theBytes, null);
+    final SpecificDatumReader<T> reader = new SpecificDatumReader<>(theClass);
+    try {
+      return reader.read(null, decoder);
+    } catch (final IOException e) {
+      throw new RuntimeException("Failed to deserialize an avro object", e);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingLookupRequest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingLookupRequest.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingLookupRequest.java
new file mode 100644
index 0000000..eda5f15
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingLookupRequest.java
@@ -0,0 +1,46 @@
+/**
+ * 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.reef.io.network.naming.serialization;
+
+import org.apache.reef.wake.Identifier;
+
+/**
+ * Naming lookup request
+ */
+public class NamingLookupRequest extends NamingMessage {
+  private Iterable<Identifier> ids;
+
+  /**
+   * Constructs a naming lookup request
+   *
+   * @param ids the iterable of identifiers
+   */
+  public NamingLookupRequest(Iterable<Identifier> ids) {
+    this.ids = ids;
+  }
+
+  /**
+   * Gets identifiers
+   *
+   * @return an iterable of identifiers
+   */
+  public Iterable<Identifier> getIdentifiers() {
+    return ids;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingLookupRequestCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingLookupRequestCodec.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingLookupRequestCodec.java
new file mode 100644
index 0000000..b388ba6
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingLookupRequestCodec.java
@@ -0,0 +1,79 @@
+/**
+ * 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.reef.io.network.naming.serialization;
+
+import org.apache.reef.io.network.naming.avro.AvroNamingLookupRequest;
+import org.apache.reef.wake.Identifier;
+import org.apache.reef.wake.IdentifierFactory;
+import org.apache.reef.wake.remote.Codec;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Naming lookup request codec
+ */
+public final class NamingLookupRequestCodec implements Codec<NamingLookupRequest> {
+
+  private final IdentifierFactory factory;
+
+  /**
+   * Constructs a naming lookup request codec
+   *
+   * @param factory the identifier factory
+   */
+  @Inject
+  public NamingLookupRequestCodec(final IdentifierFactory factory) {
+    this.factory = factory;
+  }
+
+  /**
+   * Encodes the identifiers to bytes
+   *
+   * @param obj the naming lookup request
+   * @return a byte array
+   */
+  @Override
+  public byte[] encode(final NamingLookupRequest obj) {
+    final List<CharSequence> ids = new ArrayList<>();
+    for (final Identifier id : obj.getIdentifiers()) {
+      ids.add(id.toString());
+    }
+    return AvroUtils.toBytes(AvroNamingLookupRequest.newBuilder().setIds(ids).build(), AvroNamingLookupRequest.class);
+  }
+
+  /**
+   * Decodes the bytes to a naming lookup request
+   *
+   * @param buf the byte array
+   * @return a naming lookup request
+   */
+  @Override
+  public NamingLookupRequest decode(final byte[] buf) {
+    final AvroNamingLookupRequest req = AvroUtils.fromBytes(buf, AvroNamingLookupRequest.class);
+
+    final List<Identifier> ids = new ArrayList<Identifier>(req.getIds().size());
+    for (final CharSequence s : req.getIds()) {
+      ids.add(factory.getNewInstance(s.toString()));
+    }
+    return new NamingLookupRequest(ids);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingLookupResponse.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingLookupResponse.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingLookupResponse.java
new file mode 100644
index 0000000..822f170
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingLookupResponse.java
@@ -0,0 +1,48 @@
+/**
+ * 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.reef.io.network.naming.serialization;
+
+import org.apache.reef.io.naming.NameAssignment;
+
+import java.util.List;
+
+/**
+ * Naming lookup response
+ */
+public class NamingLookupResponse extends NamingMessage {
+  private final List<NameAssignment> nas;
+
+  /**
+   * Constructs a naming lookup response
+   *
+   * @param nas the list of name assignments
+   */
+  public NamingLookupResponse(List<NameAssignment> nas) {
+    this.nas = nas;
+  }
+
+  /**
+   * Gets name assignments
+   *
+   * @return a list of name assignments
+   */
+  public List<NameAssignment> getNameAssignments() {
+    return nas;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingLookupResponseCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingLookupResponseCodec.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingLookupResponseCodec.java
new file mode 100644
index 0000000..affe3b6
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingLookupResponseCodec.java
@@ -0,0 +1,94 @@
+/**
+ * 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.reef.io.network.naming.serialization;
+
+import org.apache.reef.io.naming.NameAssignment;
+import org.apache.reef.io.network.naming.NameAssignmentTuple;
+import org.apache.reef.io.network.naming.avro.AvroNamingAssignment;
+import org.apache.reef.io.network.naming.avro.AvroNamingLookupResponse;
+import org.apache.reef.io.network.naming.exception.NamingRuntimeException;
+import org.apache.reef.wake.IdentifierFactory;
+import org.apache.reef.wake.remote.Codec;
+
+import javax.inject.Inject;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Naming lookup response codec
+ */
+public final class NamingLookupResponseCodec implements Codec<NamingLookupResponse> {
+
+  private final IdentifierFactory factory;
+
+  /**
+   * Constructs a naming lookup response codec
+   *
+   * @param factory the identifier factory
+   */
+  @Inject
+  public NamingLookupResponseCodec(final IdentifierFactory factory) {
+    this.factory = factory;
+  }
+
+  /**
+   * Encodes name assignments to bytes
+   *
+   * @param obj the naming lookup response
+   * @return a byte array
+   */
+  @Override
+  public byte[] encode(NamingLookupResponse obj) {
+    final List<AvroNamingAssignment> assignments = new ArrayList<>(obj.getNameAssignments().size());
+    for (final NameAssignment nameAssignment : obj.getNameAssignments()) {
+      assignments.add(AvroNamingAssignment.newBuilder()
+          .setId(nameAssignment.getIdentifier().toString())
+          .setHost(nameAssignment.getAddress().getHostName())
+          .setPort(nameAssignment.getAddress().getPort())
+          .build());
+    }
+    return AvroUtils.toBytes(
+        AvroNamingLookupResponse.newBuilder().setTuples(assignments).build(), AvroNamingLookupResponse.class
+    );
+  }
+
+  /**
+   * Decodes bytes to an iterable of name assignments
+   *
+   * @param buf the byte array
+   * @return a naming lookup response
+   * @throws NamingRuntimeException
+   */
+  @Override
+  public NamingLookupResponse decode(final byte[] buf) {
+    final AvroNamingLookupResponse avroResponse = AvroUtils.fromBytes(buf, AvroNamingLookupResponse.class);
+    final List<NameAssignment> nas = new ArrayList<NameAssignment>(avroResponse.getTuples().size());
+    for (final AvroNamingAssignment tuple : avroResponse.getTuples()) {
+      nas.add(
+          new NameAssignmentTuple(
+              factory.getNewInstance(tuple.getId().toString()),
+              new InetSocketAddress(tuple.getHost().toString(), tuple.getPort())
+          )
+      );
+    }
+    return new NamingLookupResponse(nas);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingMessage.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingMessage.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingMessage.java
new file mode 100644
index 0000000..3152854
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingMessage.java
@@ -0,0 +1,46 @@
+/**
+ * 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.reef.io.network.naming.serialization;
+
+import org.apache.reef.wake.remote.transport.Link;
+
+/**
+ * An abstract base class for naming messages
+ */
+public abstract class NamingMessage {
+  private transient Link<byte[]> link;
+
+  /**
+   * Gets a link
+   *
+   * @return a link
+   */
+  public Link<byte[]> getLink() {
+    return link;
+  }
+
+  /**
+   * Sets the link
+   *
+   * @param link the link
+   */
+  public void setLink(Link<byte[]> link) {
+    this.link = link;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingRegisterRequest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingRegisterRequest.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingRegisterRequest.java
new file mode 100644
index 0000000..e6e1e9c
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingRegisterRequest.java
@@ -0,0 +1,46 @@
+/**
+ * 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.reef.io.network.naming.serialization;
+
+import org.apache.reef.io.naming.NameAssignment;
+
+/**
+ * naming registration request
+ */
+public class NamingRegisterRequest extends NamingMessage {
+  private final NameAssignment na;
+
+  /**
+   * Constructs a naming registration request
+   *
+   * @param na the name assignment
+   */
+  public NamingRegisterRequest(NameAssignment na) {
+    this.na = na;
+  }
+
+  /**
+   * Gets a name assignment
+   *
+   * @return a name assignment
+   */
+  public NameAssignment getNameAssignment() {
+    return na;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingRegisterRequestCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingRegisterRequestCodec.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingRegisterRequestCodec.java
new file mode 100644
index 0000000..c32d888
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingRegisterRequestCodec.java
@@ -0,0 +1,76 @@
+/**
+ * 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.reef.io.network.naming.serialization;
+
+import org.apache.reef.io.network.naming.NameAssignmentTuple;
+import org.apache.reef.io.network.naming.avro.AvroNamingRegisterRequest;
+import org.apache.reef.io.network.naming.exception.NamingRuntimeException;
+import org.apache.reef.wake.IdentifierFactory;
+import org.apache.reef.wake.remote.Codec;
+
+import java.net.InetSocketAddress;
+
+/**
+ * Naming registration request codec
+ */
+public class NamingRegisterRequestCodec implements Codec<NamingRegisterRequest> {
+
+  private final IdentifierFactory factory;
+
+  /**
+   * Constructs a naming registration request codec
+   *
+   * @param factory the identifier factory
+   */
+  public NamingRegisterRequestCodec(IdentifierFactory factory) {
+    this.factory = factory;
+  }
+
+  /**
+   * Encodes the name assignment to bytes
+   *
+   * @param obj the naming registration request
+   * @return a byte array
+   */
+  @Override
+  public byte[] encode(NamingRegisterRequest obj) {
+    final AvroNamingRegisterRequest result = AvroNamingRegisterRequest.newBuilder()
+        .setId(obj.getNameAssignment().getIdentifier().toString())
+        .setHost(obj.getNameAssignment().getAddress().getHostName())
+        .setPort(obj.getNameAssignment().getAddress().getPort())
+        .build();
+    return AvroUtils.toBytes(result, AvroNamingRegisterRequest.class);
+  }
+
+  /**
+   * Decodes the bytes to a name assignment
+   *
+   * @param buf the byte array
+   * @return a naming registration request
+   * @throws NamingRuntimeException
+   */
+  @Override
+  public NamingRegisterRequest decode(byte[] buf) {
+    final AvroNamingRegisterRequest avroNamingRegisterRequest = AvroUtils.fromBytes(buf, AvroNamingRegisterRequest.class);
+    return new NamingRegisterRequest(
+        new NameAssignmentTuple(factory.getNewInstance(avroNamingRegisterRequest.getId().toString()),
+            new InetSocketAddress(avroNamingRegisterRequest.getHost().toString(), avroNamingRegisterRequest.getPort()))
+    );
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingRegisterResponse.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingRegisterResponse.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingRegisterResponse.java
new file mode 100644
index 0000000..b8c416f
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingRegisterResponse.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.io.network.naming.serialization;
+
+/**
+ * naming registration response
+ */
+public class NamingRegisterResponse extends NamingMessage {
+  private final NamingRegisterRequest request;
+
+  /**
+   * Constructs a naming register response
+   *
+   * @param request the naming register request
+   */
+  public NamingRegisterResponse(NamingRegisterRequest request) {
+    this.request = request;
+  }
+
+  /**
+   * Gets a naming register request
+   *
+   * @return a naming register request
+   */
+  public NamingRegisterRequest getRequest() {
+    return request;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingRegisterResponseCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingRegisterResponseCodec.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingRegisterResponseCodec.java
new file mode 100644
index 0000000..f95a90e
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingRegisterResponseCodec.java
@@ -0,0 +1,60 @@
+/**
+ * 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.reef.io.network.naming.serialization;
+
+import org.apache.reef.wake.remote.Codec;
+
+/**
+ * naming registration response codec
+ */
+public class NamingRegisterResponseCodec implements Codec<NamingRegisterResponse> {
+  private final NamingRegisterRequestCodec codec;
+
+  /**
+   * Constructs a naming register response codec
+   *
+   * @param codec the naming register request codec
+   */
+  public NamingRegisterResponseCodec(NamingRegisterRequestCodec codec) {
+    this.codec = codec;
+  }
+
+  /**
+   * Encodes a naming register response to bytes
+   *
+   * @param obj the naming register response
+   * @return bytes a byte array
+   */
+  @Override
+  public byte[] encode(NamingRegisterResponse obj) {
+    return codec.encode(obj.getRequest());
+  }
+
+  /**
+   * Decodes a naming register response from the bytes
+   *
+   * @param buf the byte array
+   * @return a naming register response
+   */
+  @Override
+  public NamingRegisterResponse decode(byte[] buf) {
+    return new NamingRegisterResponse(codec.decode(buf));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingUnregisterRequest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingUnregisterRequest.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingUnregisterRequest.java
new file mode 100644
index 0000000..770b7c9
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingUnregisterRequest.java
@@ -0,0 +1,46 @@
+/**
+ * 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.reef.io.network.naming.serialization;
+
+import org.apache.reef.wake.Identifier;
+
+/**
+ * Naming un-registration request
+ */
+public class NamingUnregisterRequest extends NamingMessage {
+  private final Identifier id;
+
+  /**
+   * Constructs a naming un-registration request
+   *
+   * @param id the identifier
+   */
+  public NamingUnregisterRequest(Identifier id) {
+    this.id = id;
+  }
+
+  /**
+   * Gets an identifier
+   *
+   * @return an identifier
+   */
+  public Identifier getIdentifier() {
+    return id;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingUnregisterRequestCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingUnregisterRequestCodec.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingUnregisterRequestCodec.java
new file mode 100644
index 0000000..ea505c3
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/NamingUnregisterRequestCodec.java
@@ -0,0 +1,72 @@
+/**
+ * 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.reef.io.network.naming.serialization;
+
+import org.apache.reef.io.network.naming.avro.AvroNamingUnRegisterRequest;
+import org.apache.reef.io.network.naming.exception.NamingRuntimeException;
+import org.apache.reef.wake.IdentifierFactory;
+import org.apache.reef.wake.remote.Codec;
+
+import javax.inject.Inject;
+
+/**
+ * Naming un-registration request codec
+ */
+public final class NamingUnregisterRequestCodec implements Codec<NamingUnregisterRequest> {
+
+  private final IdentifierFactory factory;
+
+  /**
+   * Constructs a naming un-registration request codec
+   *
+   * @param factory the identifier factory
+   */
+  @Inject
+  public NamingUnregisterRequestCodec(final IdentifierFactory factory) {
+    this.factory = factory;
+  }
+
+  /**
+   * Encodes the naming un-registration request to bytes
+   *
+   * @param obj the naming un-registration request
+   * @return a byte array
+   */
+  @Override
+  public byte[] encode(NamingUnregisterRequest obj) {
+    final AvroNamingUnRegisterRequest result = AvroNamingUnRegisterRequest.newBuilder()
+        .setId(obj.getIdentifier().toString())
+        .build();
+    return AvroUtils.toBytes(result, AvroNamingUnRegisterRequest.class);
+  }
+
+  /**
+   * Decodes the bytes to a naming un-registration request
+   *
+   * @param buf the byte array
+   * @return a naming un-registration request
+   * @throws NamingRuntimeException
+   */
+  @Override
+  public NamingUnregisterRequest decode(byte[] buf) {
+    final AvroNamingUnRegisterRequest result = AvroUtils.fromBytes(buf, AvroNamingUnRegisterRequest.class);
+    return new NamingUnregisterRequest(factory.getNewInstance(result.getId().toString()));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/package-info.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/package-info.java
new file mode 100644
index 0000000..d4ff9d3
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/serialization/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Contains naming serialization codecs
+ */
+package org.apache.reef.io.network.naming.serialization;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/package-info.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/package-info.java
new file mode 100644
index 0000000..4c53530
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/package-info.java
@@ -0,0 +1,19 @@
+/**
+ * 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.reef.io.network;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/ListCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/ListCodec.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/ListCodec.java
new file mode 100644
index 0000000..5e68871
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/ListCodec.java
@@ -0,0 +1,83 @@
+/**
+ * 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.reef.io.network.util;
+
+import org.apache.reef.wake.remote.Codec;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public final class ListCodec<T> implements Codec<List<T>> {
+
+  private static final Logger LOG = Logger.getLogger(ListCodec.class.getName());
+
+  private final Codec<T> codec;
+
+  public ListCodec(final Codec<T> codec) {
+    super();
+    this.codec = codec;
+  }
+
+  public static void main(final String[] args) {
+    final List<String> arrList = Arrays.asList(
+        new String[]{"One", "Two", "Three", "Four", "Five"});
+    LOG.log(Level.FINEST, "Input: {0}", arrList);
+    final ListCodec<String> lstCodec = new ListCodec<>(new StringCodec());
+    final byte[] bytes = lstCodec.encode(arrList);
+    LOG.log(Level.FINEST, "Output: {0}", lstCodec.decode(bytes));
+  }
+
+  @Override
+  public byte[] encode(final List<T> list) {
+    try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+         final DataOutputStream daos = new DataOutputStream(baos)) {
+      for (final T t : list) {
+        final byte[] tBytes = this.codec.encode(t);
+        daos.writeInt(tBytes.length);
+        daos.write(tBytes);
+      }
+      return baos.toByteArray();
+    } catch (final IOException ex) {
+      LOG.log(Level.WARNING, "Error in list encoding", ex);
+      throw new RuntimeException(ex);
+    }
+  }
+
+  @Override
+  public List<T> decode(final byte[] list) {
+    final List<T> result = new ArrayList<>();
+    try (final DataInputStream dais = new DataInputStream(new ByteArrayInputStream(list))) {
+      while (dais.available() > 0) {
+        final int length = dais.readInt();
+        final byte[] tBytes = new byte[length];
+        dais.readFully(tBytes);
+        final T t = this.codec.decode(tBytes);
+        result.add(t);
+      }
+      return result;
+    } catch (final IOException ex) {
+      LOG.log(Level.WARNING, "Error in list decoding", ex);
+      throw new RuntimeException(ex);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/Pair.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/Pair.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/Pair.java
new file mode 100644
index 0000000..f1a3a07
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/Pair.java
@@ -0,0 +1,42 @@
+/**
+ * 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.reef.io.network.util;
+
+import java.io.Serializable;
+
+public final class Pair<T1, T2> implements Serializable {
+
+  public final T1 first;
+  public final T2 second;
+
+  private String pairStr = null;
+
+  public Pair(final T1 first, final T2 second) {
+    this.first = first;
+    this.second = second;
+  }
+
+  @Override
+  public String toString() {
+    if (this.pairStr == null) {
+      this.pairStr = "(" + this.first + "," + this.second + ")";
+    }
+    return this.pairStr;
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/StringCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/StringCodec.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/StringCodec.java
new file mode 100644
index 0000000..e4013bf
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/StringCodec.java
@@ -0,0 +1,42 @@
+/**
+ * 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.reef.io.network.util;
+
+import org.apache.reef.wake.remote.Codec;
+
+import javax.inject.Inject;
+
+
+public class StringCodec implements Codec<String> {
+
+  @Inject
+  public StringCodec() {
+    // Intentionally blank
+  }
+
+  @Override
+  public byte[] encode(String obj) {
+    return obj.getBytes();
+  }
+
+  @Override
+  public String decode(byte[] buf) {
+    return new String(buf);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/StringIdentifier.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/StringIdentifier.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/StringIdentifier.java
new file mode 100644
index 0000000..5d6454b
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/StringIdentifier.java
@@ -0,0 +1,80 @@
+/**
+ * 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.reef.io.network.util;
+
+import org.apache.reef.wake.ComparableIdentifier;
+import org.apache.reef.wake.Identifier;
+
+/**
+ * String identifier
+ */
+public class StringIdentifier implements ComparableIdentifier {
+
+  private final String str;
+
+  /**
+   * Constructs a string identifier
+   *
+   * @param str a string
+   */
+  StringIdentifier(String str) {
+    this.str = str;
+  }
+
+  /**
+   * Returns a hash code for the object
+   *
+   * @return a hash code value for this object
+   */
+  public int hashCode() {
+    return str.hashCode();
+  }
+
+  /**
+   * Checks that another object is equal to this object
+   *
+   * @param o another object
+   * @return true if the object is the same as the object argument; false, otherwise
+   */
+  public boolean equals(Object o) {
+    return str.equals(((StringIdentifier) o).toString());
+  }
+
+  /**
+   * Returns a string representation of the object
+   *
+   * @return a string representation of the object
+   */
+  public String toString() {
+    return str;
+  }
+
+  @Override
+  public int compareTo(Identifier o) {
+    if (o == null) {
+      if (str == null)
+        return 0;
+      return 1;
+    } else {
+      if (str == null)
+        return -1;
+      return str.compareTo(o.toString());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/StringIdentifierFactory.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/StringIdentifierFactory.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/StringIdentifierFactory.java
new file mode 100644
index 0000000..9886a01
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/StringIdentifierFactory.java
@@ -0,0 +1,46 @@
+/**
+ * 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.reef.io.network.util;
+
+import org.apache.reef.wake.Identifier;
+import org.apache.reef.wake.IdentifierFactory;
+
+import javax.inject.Inject;
+
+/**
+ * Factory that creates StringIdentifier
+ */
+public class StringIdentifierFactory implements IdentifierFactory {
+
+  @Inject
+  public StringIdentifierFactory() {
+  }
+
+  /**
+   * Creates a StringIdentifier object
+   *
+   * @param s a string
+   * @return a string identifier
+   */
+  @Override
+  public Identifier getNewInstance(String s) {
+    return new StringIdentifier(s);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/package-info.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/package-info.java
new file mode 100644
index 0000000..4335f8f
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/util/package-info.java
@@ -0,0 +1,19 @@
+/**
+ * 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.reef.io.network.util;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/FramingInputStream.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/FramingInputStream.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/FramingInputStream.java
new file mode 100644
index 0000000..a40222b
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/FramingInputStream.java
@@ -0,0 +1,76 @@
+/**
+ * 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.reef.io.storage;
+
+import org.apache.reef.exception.evaluator.ServiceRuntimeException;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+
+public class FramingInputStream extends DataInputStream implements Iterable<byte[]> {
+
+  public FramingInputStream(InputStream in) {
+    super(in);
+  }
+
+  public byte[] readFrame() throws IOException {
+    int i = readInt();
+    if (i == -1) {
+      return null;
+    }
+    byte[] b = new byte[i];
+    readFully(b);
+    return b;
+  }
+
+  @Override
+  public Iterator<byte[]> iterator() {
+    try {
+      return new Iterator<byte[]>() {
+        byte[] cur = readFrame();
+
+        @Override
+        public boolean hasNext() {
+          return cur != null;
+        }
+
+        @Override
+        public byte[] next() {
+          byte[] ret = cur;
+          try {
+            cur = readFrame();
+          } catch (IOException e) {
+            throw new ServiceRuntimeException(e);
+          }
+          return ret;
+        }
+
+        @Override
+        public void remove() {
+          throw new UnsupportedOperationException();
+        }
+      };
+    } catch (IOException e) {
+      throw new ServiceRuntimeException(e);
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/FramingOutputStream.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/FramingOutputStream.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/FramingOutputStream.java
new file mode 100644
index 0000000..11547a6
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/FramingOutputStream.java
@@ -0,0 +1,134 @@
+/**
+ * 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.reef.io.storage;
+
+import org.apache.reef.exception.evaluator.ServiceException;
+import org.apache.reef.exception.evaluator.StorageException;
+import org.apache.reef.io.Accumulable;
+import org.apache.reef.io.Accumulator;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class FramingOutputStream extends OutputStream implements Accumulable<byte[]> {
+
+  private final ByteArrayOutputStream baos;
+  private final DataOutputStream o;
+  private long offset;
+  private boolean closed;
+
+  public FramingOutputStream(OutputStream o) {
+    if (!(o instanceof DataOutputStream)) {
+      this.o = new DataOutputStream(o);
+    } else {
+      this.o = (DataOutputStream) o;
+    }
+    this.baos = new ByteArrayOutputStream();
+  }
+
+  public void nextFrame() throws StorageException {
+    try {
+      o.writeInt(baos.size());
+      offset += 4;
+      baos.writeTo(o);
+      baos.reset();
+    } catch (IOException e) {
+      throw new StorageException(e);
+    }
+  }
+
+  public long getCurrentOffset() {
+    return offset;
+  }
+
+  @Override
+  public void write(int b) throws IOException {
+    baos.write(b);
+    offset++;
+    ;
+  }
+
+  @Override
+  public void write(byte[] b) throws IOException {
+    baos.write(b);
+    offset += b.length;
+  }
+
+  @Override
+  public void write(byte[] b, int offset, int length) throws IOException {
+    baos.write(b, offset, length);
+    offset += length;
+  }
+
+  @Override
+  public void flush() {
+    // no-op.
+  }
+
+  @Override
+  public void close() throws IOException {
+    if (!closed) {
+      try {
+        if (this.offset > 0) nextFrame();
+      } catch (StorageException e) {
+        throw (IOException) e.getCause();
+      }
+      o.writeInt(-1);
+      o.close();
+      closed = true;
+    }
+  }
+
+  @Override
+  public Accumulator<byte[]> accumulator() throws StorageException {
+    @SuppressWarnings("resource")
+    final FramingOutputStream fos = this;
+    return new Accumulator<byte[]>() {
+
+      @Override
+      public void add(byte[] datum) throws ServiceException {
+        try {
+          o.writeInt(datum.length);
+          offset += 4;
+          o.write(datum);
+          offset += datum.length;
+        } catch (IOException e) {
+          throw new ServiceException(e);
+        }
+
+      }
+
+      @Override
+      public void close() throws ServiceException {
+        try {
+          o.writeInt(-1);
+          offset += 4;
+          o.close();
+          fos.closed = true;
+        } catch (IOException e) {
+          throw new ServiceException(e);
+        }
+      }
+
+    };
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/FramingTupleDeserializer.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/FramingTupleDeserializer.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/FramingTupleDeserializer.java
new file mode 100644
index 0000000..80affdf
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/FramingTupleDeserializer.java
@@ -0,0 +1,100 @@
+/**
+ * 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.reef.io.storage;
+
+import org.apache.reef.exception.evaluator.ServiceException;
+import org.apache.reef.exception.evaluator.ServiceRuntimeException;
+import org.apache.reef.io.Tuple;
+import org.apache.reef.io.serialization.Deserializer;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+public class FramingTupleDeserializer<K, V> implements
+    Deserializer<Tuple<K, V>, InputStream> {
+
+  private final Deserializer<K, InputStream> keyDeserializer;
+  private final Deserializer<V, InputStream> valDeserializer;
+
+  public FramingTupleDeserializer(Deserializer<K, InputStream> keyDeserializer,
+                                  Deserializer<V, InputStream> valDeserializer) {
+    this.keyDeserializer = keyDeserializer;
+    this.valDeserializer = valDeserializer;
+  }
+
+  @Override
+  public Iterable<Tuple<K, V>> create(InputStream ins) {
+    final DataInputStream in = new DataInputStream(ins);
+    final Iterable<K> keyItbl = keyDeserializer.create(in);
+    final Iterable<V> valItbl = valDeserializer.create(in);
+    return new Iterable<Tuple<K, V>>() {
+      @Override
+      public Iterator<Tuple<K, V>> iterator() {
+        final Iterator<K> keyIt = keyItbl.iterator();
+        final Iterator<V> valIt = valItbl.iterator();
+        try {
+          return new Iterator<Tuple<K, V>>() {
+
+            private int readFrameLength() throws ServiceException {
+              try {
+                return in.readInt();
+              } catch (IOException e) {
+                throw new ServiceRuntimeException(e);
+              }
+            }
+
+            int nextFrameLength = readFrameLength();
+
+            @Override
+            public boolean hasNext() {
+              return nextFrameLength != -1;
+            }
+
+            @Override
+            public Tuple<K, V> next() {
+              try {
+                if (nextFrameLength == -1) {
+                  throw new NoSuchElementException();
+                }
+                K k = keyIt.next();
+                readFrameLength();
+                V v = valIt.next();
+                nextFrameLength = readFrameLength();
+                return new Tuple<>(k, v);
+              } catch (ServiceException e) {
+                throw new ServiceRuntimeException(e);
+              }
+            }
+
+            @Override
+            public void remove() {
+              throw new UnsupportedOperationException();
+            }
+          };
+        } catch (ServiceException e) {
+          throw new ServiceRuntimeException(e);
+        }
+      }
+    };
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/FramingTupleSerializer.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/FramingTupleSerializer.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/FramingTupleSerializer.java
new file mode 100644
index 0000000..a98babd
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/FramingTupleSerializer.java
@@ -0,0 +1,86 @@
+/**
+ * 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.reef.io.storage;
+
+import org.apache.reef.exception.evaluator.ServiceException;
+import org.apache.reef.exception.evaluator.StorageException;
+import org.apache.reef.io.Accumulable;
+import org.apache.reef.io.Accumulator;
+import org.apache.reef.io.Tuple;
+import org.apache.reef.io.serialization.Serializer;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class FramingTupleSerializer<K, V> implements
+    Serializer<Tuple<K, V>, OutputStream> {
+
+  private final Serializer<K, OutputStream> keySerializer;
+  private final Serializer<V, OutputStream> valSerializer;
+
+  public FramingTupleSerializer(
+      final Serializer<K, OutputStream> keySerializer,
+      final Serializer<V, OutputStream> valSerializer) {
+    this.keySerializer = keySerializer;
+    this.valSerializer = valSerializer;
+  }
+
+  @Override
+  public Accumulable<Tuple<K, V>> create(final OutputStream os) {
+    final FramingOutputStream faos = new FramingOutputStream(os);
+
+    return new Accumulable<Tuple<K, V>>() {
+
+      @Override
+      public Accumulator<Tuple<K, V>> accumulator() throws ServiceException {
+
+        final Accumulator<K> keyAccumulator = keySerializer.create(faos)
+            .accumulator();
+        final Accumulator<V> valAccumulator = valSerializer.create(faos)
+            .accumulator();
+        return new Accumulator<Tuple<K, V>>() {
+          boolean first = true;
+
+          @Override
+          public void add(Tuple<K, V> datum) throws ServiceException {
+            if (!first) {
+              faos.nextFrame();
+            }
+            first = false;
+            keyAccumulator.add(datum.getKey());
+            faos.nextFrame();
+            valAccumulator.add(datum.getValue());
+          }
+
+          @Override
+          public void close() throws ServiceException {
+            try {
+              keyAccumulator.close();
+              valAccumulator.close();
+              faos.close();
+            } catch (IOException e) {
+              throw new StorageException(e);
+            }
+          }
+        };
+      }
+    };
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/MergingIterator.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/MergingIterator.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/MergingIterator.java
new file mode 100644
index 0000000..2dfcc18
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/MergingIterator.java
@@ -0,0 +1,62 @@
+/**
+ * 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.reef.io.storage;
+
+import org.apache.reef.io.Tuple;
+import org.apache.reef.io.storage.util.TupleKeyComparator;
+
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.PriorityQueue;
+
+public class MergingIterator<T> implements Iterator<T> {
+  private final PriorityQueue<Tuple<T, Iterator<T>>> heap;
+
+  public MergingIterator(final Comparator<T> c, Iterator<T>[] its) {
+    this.heap = new PriorityQueue<Tuple<T, Iterator<T>>>(11,
+        new TupleKeyComparator<T, Iterator<T>>(c));
+
+    for (Iterator<T> it : its) {
+      T b = it.hasNext() ? it.next() : null;
+      if (b != null) {
+        heap.add(new Tuple<>(b, it));
+      }
+    }
+  }
+
+  @Override
+  public boolean hasNext() {
+    return heap.size() != 0;
+  }
+
+  @Override
+  public T next() {
+    Tuple<T, Iterator<T>> ret = heap.remove();
+    if (ret.getValue().hasNext()) {
+      heap.add(new Tuple<>(ret.getValue().next(), ret.getValue()));
+    }
+    return ret.getKey();
+  }
+
+  @Override
+  public void remove() {
+    throw new UnsupportedOperationException(
+        "Cannot remove entires from MergingIterator!");
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ScratchSpace.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ScratchSpace.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ScratchSpace.java
new file mode 100644
index 0000000..0d7353a
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ScratchSpace.java
@@ -0,0 +1,27 @@
+/**
+ * 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.reef.io.storage;
+
+public interface ScratchSpace {
+  long availableSpace();
+
+  long usedSpace();
+
+  void delete();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/StorageService.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/StorageService.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/StorageService.java
new file mode 100644
index 0000000..1002b76
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/StorageService.java
@@ -0,0 +1,25 @@
+/**
+ * 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.reef.io.storage;
+
+public interface StorageService {
+
+  ScratchSpace getScratchSpace();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/CodecFileAccumulable.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/CodecFileAccumulable.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/CodecFileAccumulable.java
new file mode 100644
index 0000000..c5413e6
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/CodecFileAccumulable.java
@@ -0,0 +1,52 @@
+/**
+ * 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.reef.io.storage.local;
+
+import org.apache.reef.exception.evaluator.StorageException;
+import org.apache.reef.io.Accumulable;
+import org.apache.reef.io.Accumulator;
+import org.apache.reef.io.serialization.Codec;
+
+import java.io.File;
+import java.io.IOException;
+
+public final class CodecFileAccumulable<T, C extends Codec<T>> implements Accumulable<T> {
+
+  private final File filename;
+  private final C codec;
+
+  public CodecFileAccumulable(final LocalStorageService s, final C codec) {
+    this.filename = s.getScratchSpace().newFile();
+    this.codec = codec;
+  }
+
+  public String getName() {
+    return this.filename.toString();
+  }
+
+  @Override
+  public Accumulator<T> accumulator() throws StorageException {
+    try {
+      return new CodecFileAccumulator<>(this.codec, this.filename);
+    } catch (final IOException e) {
+      throw new StorageException(e);
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/CodecFileAccumulator.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/CodecFileAccumulator.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/CodecFileAccumulator.java
new file mode 100644
index 0000000..3d6d7cb
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/CodecFileAccumulator.java
@@ -0,0 +1,58 @@
+/**
+ * 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.reef.io.storage.local;
+
+import org.apache.reef.exception.evaluator.ServiceException;
+import org.apache.reef.exception.evaluator.StorageException;
+import org.apache.reef.io.Accumulator;
+import org.apache.reef.io.serialization.Codec;
+
+import java.io.*;
+
+final class CodecFileAccumulator<T> implements Accumulator<T> {
+
+  private final Codec<T> codec;
+  private final ObjectOutputStream out;
+
+  public CodecFileAccumulator(final Codec<T> codec, final File file) throws IOException {
+    this.codec = codec;
+    this.out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
+  }
+
+  @Override
+  public void add(final T datum) throws ServiceException {
+    final byte[] buf = codec.encode(datum);
+    try {
+      this.out.writeInt(buf.length);
+      this.out.write(buf);
+    } catch (final IOException e) {
+      throw new StorageException(e);
+    }
+  }
+
+  @Override
+  public void close() throws ServiceException {
+    try {
+      this.out.writeInt(-1);
+      this.out.close();
+    } catch (final IOException e) {
+      throw new ServiceException(e);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/CodecFileIterable.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/CodecFileIterable.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/CodecFileIterable.java
new file mode 100644
index 0000000..9545d19
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/CodecFileIterable.java
@@ -0,0 +1,53 @@
+/**
+ * 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.reef.io.storage.local;
+
+import org.apache.reef.exception.evaluator.ServiceRuntimeException;
+import org.apache.reef.exception.evaluator.StorageException;
+import org.apache.reef.io.serialization.Codec;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Iterator;
+
+/**
+ * A read-only spool implementation, based on files. Some other process needs to
+ * create the spool file for us.
+ */
+public class CodecFileIterable<T, C extends Codec<T>> implements Iterable<T> {
+  private final File filename;
+  private final C codec;
+
+  public CodecFileIterable(final File filename, final C codec) {
+    this.filename = filename;
+    this.codec = codec;
+  }
+
+  @SuppressWarnings("resource")
+  @Override
+  public Iterator<T> iterator() {
+    try {
+      return new CodecFileIterator<>(this.codec, this.filename);
+    } catch (final IOException e) {
+      throw new ServiceRuntimeException(new StorageException(e));
+    }
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/CodecFileIterator.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/CodecFileIterator.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/CodecFileIterator.java
new file mode 100644
index 0000000..69538e0
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/CodecFileIterator.java
@@ -0,0 +1,82 @@
+/**
+ * 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.reef.io.storage.local;
+
+import org.apache.reef.exception.evaluator.ServiceRuntimeException;
+import org.apache.reef.exception.evaluator.StorageException;
+import org.apache.reef.io.serialization.Codec;
+
+import java.io.*;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+final class CodecFileIterator<T> implements Iterator<T> {
+
+  private final Codec<T> codec;
+  private final ObjectInputStream in;
+  private int sz = 0;
+
+  CodecFileIterator(final Codec<T> codec, final File file) throws IOException {
+    this.in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file)));
+    this.codec = codec;
+    this.readNextSize();
+  }
+
+  private void readNextSize() throws IOException {
+    if (this.hasNext()) {
+      try {
+        this.sz = this.in.readInt();
+        if (this.sz == -1) {
+          this.in.close();
+        }
+      } catch (final IOException ex) {
+        this.sz = -1; // Don't read from that file again.
+        this.in.close();
+        throw ex;
+      }
+    }
+  }
+
+  @Override
+  public boolean hasNext() {
+    return this.sz != -1;
+  }
+
+  @Override
+  public T next() {
+    if (!this.hasNext()) {
+      throw new NoSuchElementException("Moving past the end of the file.");
+    }
+    try {
+      final byte[] buf = new byte[this.sz];
+      for (int rem = buf.length; rem > 0; ) {
+        rem -= this.in.read(buf, buf.length - rem, rem);
+      }
+      this.readNextSize();
+      return this.codec.decode(buf);
+    } catch (final IOException e) {
+      throw new ServiceRuntimeException(new StorageException(e));
+    }
+  }
+
+  @Override
+  public void remove() {
+    throw new UnsupportedOperationException("Attempt to remove value from read-only input file!");
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/LocalScratchSpace.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/LocalScratchSpace.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/LocalScratchSpace.java
new file mode 100644
index 0000000..34f0f5c
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/LocalScratchSpace.java
@@ -0,0 +1,87 @@
+/**
+ * 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.reef.io.storage.local;
+
+import org.apache.reef.io.storage.ScratchSpace;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Set;
+import java.util.concurrent.ConcurrentSkipListSet;
+
+public class LocalScratchSpace implements ScratchSpace {
+
+  private final String jobName;
+  private final String evaluatorName;
+  private final Set<File> tempFiles = new ConcurrentSkipListSet<File>();
+  /**
+   * Zero denotes "unlimited"
+   */
+  private long quota;
+
+  public LocalScratchSpace(String jobName, String evaluatorName) {
+    this.jobName = jobName;
+    this.evaluatorName = evaluatorName;
+    this.quota = 0;
+  }
+
+  public LocalScratchSpace(String jobName, String evaluatorName, long quota) {
+    this.jobName = jobName;
+    this.evaluatorName = evaluatorName;
+    this.quota = quota;
+  }
+
+  public File newFile() {
+    final File ret;
+    try {
+      ret = File.createTempFile("reef-" + jobName + "-" + evaluatorName,
+          "tmp");
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+    tempFiles.add(ret);
+    return ret;
+  }
+
+  @Override
+  public long availableSpace() {
+    return quota;
+  }
+
+  @Override
+  public long usedSpace() {
+    long ret = 0;
+    for (File f : tempFiles) {
+      // TODO: Error handling...
+      ret += f.length();
+    }
+    return ret;
+  }
+
+  @Override
+  public void delete() {
+    // TODO: Error handling. Files.delete() would give us an exception. We
+    // should pass a set of Exceptions into a ReefRuntimeException.
+    for (File f : tempFiles) {
+      f.delete();
+    }
+    tempFiles.clear();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/LocalStorageService.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/LocalStorageService.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/LocalStorageService.java
new file mode 100644
index 0000000..daae6cd
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/LocalStorageService.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.io.storage.local;
+
+import org.apache.reef.io.storage.StorageService;
+
+
+public class LocalStorageService implements StorageService {
+  @SuppressWarnings("unused")
+  private final String jobName;
+  @SuppressWarnings("unused")
+  private final String evaluatorName;
+
+  private final LocalScratchSpace scratchSpace;
+
+  public LocalStorageService(String jobName, String evaluatorName) {
+    this.jobName = jobName;
+    this.evaluatorName = evaluatorName;
+    this.scratchSpace = new LocalScratchSpace(jobName, evaluatorName);
+  }
+
+  @Override
+  public LocalScratchSpace getScratchSpace() {
+    return scratchSpace;
+  }
+
+  ;
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/SerializerFileSpool.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/SerializerFileSpool.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/SerializerFileSpool.java
new file mode 100644
index 0000000..e9a4f41
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/local/SerializerFileSpool.java
@@ -0,0 +1,101 @@
+/**
+ * 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.reef.io.storage.local;
+
+import org.apache.reef.exception.evaluator.ServiceException;
+import org.apache.reef.exception.evaluator.ServiceRuntimeException;
+import org.apache.reef.io.Accumulable;
+import org.apache.reef.io.Accumulator;
+import org.apache.reef.io.Spool;
+import org.apache.reef.io.serialization.Deserializer;
+import org.apache.reef.io.serialization.Serializer;
+
+import java.io.*;
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+
+/**
+ * A SpoolFile backed by the filesystem.
+ *
+ * @param <T>
+ */
+public final class SerializerFileSpool<T> implements Spool<T> {
+
+  private final File file;
+  private final Accumulator<T> accumulator;
+  private final Deserializer<T, InputStream> deserializer;
+  private boolean canAppend = true;
+  private boolean canGetAccumulator = true;
+
+  public SerializerFileSpool(final LocalStorageService service,
+                             final Serializer<T, OutputStream> out, final Deserializer<T, InputStream> in)
+      throws ServiceException {
+    this.file = service.getScratchSpace().newFile();
+    Accumulable<T> accumulable;
+    try {
+      accumulable = out.create(new BufferedOutputStream(new FileOutputStream(
+          file)));
+    } catch (final FileNotFoundException e) {
+      throw new IllegalStateException(
+          "Unable to create temporary file:" + file, e);
+    }
+    this.deserializer = in;
+
+    final Accumulator<T> acc = accumulable.accumulator();
+    this.accumulator = new Accumulator<T>() {
+      @Override
+      public void add(final T datum) throws ServiceException {
+        if (!canAppend) {
+          throw new ConcurrentModificationException(
+              "Attempt to append after creating iterator!");
+        }
+        acc.add(datum);
+      }
+
+      @Override
+      public void close() throws ServiceException {
+        canAppend = false;
+        acc.close();
+      }
+    };
+  }
+
+  @Override
+  public Iterator<T> iterator() {
+    try {
+      if (canAppend) {
+        throw new IllegalStateException(
+            "Need to call close() on accumulator before calling iterator()!");
+      }
+      return deserializer.create(
+          new BufferedInputStream(new FileInputStream(file))).iterator();
+    } catch (final IOException e) {
+      throw new ServiceRuntimeException(e);
+    }
+  }
+
+  @Override
+  public Accumulator<T> accumulator() {
+    if (!canGetAccumulator) {
+      throw new UnsupportedOperationException("Can only getAccumulator() once!");
+    }
+    canGetAccumulator = false;
+    return this.accumulator;
+  }
+}


[03/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/statepassing/StatePassingTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/statepassing/StatePassingTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/statepassing/StatePassingTest.java
new file mode 100644
index 0000000..0a9bce5
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/statepassing/StatePassingTest.java
@@ -0,0 +1,71 @@
+/**
+ * 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.reef.tests.statepassing;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.tests.library.driver.OnDriverStartedAllocateOne;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests whether subsequent tasks can pass state from one to the other.
+ */
+public final class StatePassingTest {
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  @Test
+  public void testStatePassing() throws BindException, InjectionException {
+
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    final Configuration driverConfiguration = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(this.getClass()))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "StatePassingTest")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, OnDriverStartedAllocateOne.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, StatePassingDriver.EvaluatorAllocatedHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_ACTIVE, StatePassingDriver.ContextActiveHandler.class)
+        .set(DriverConfiguration.ON_TASK_COMPLETED, StatePassingDriver.TaskCompletedHandler.class)
+        .build();
+
+    final LauncherStatus status = DriverLauncher.getLauncher(runtimeConfiguration)
+        .run(driverConfiguration, this.testEnvironment.getTestTimeout());
+
+    Assert.assertTrue("Job state after execution: " + status, status.isSuccess());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/statepassing/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/statepassing/package-info.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/statepassing/package-info.java
new file mode 100644
index 0000000..7189809
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/statepassing/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Tests whether subsequent tasks can pass state from one to the other.
+ */
+package org.apache.reef.tests.statepassing;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/ContextStartHandler1.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/ContextStartHandler1.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/ContextStartHandler1.java
new file mode 100644
index 0000000..9ca1bfb
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/ContextStartHandler1.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.tests.subcontexts;
+
+import org.apache.reef.evaluator.context.events.ContextStart;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+
+final class ContextStartHandler1 implements EventHandler<ContextStart> {
+
+  @Inject
+  ContextStartHandler1() {
+  }
+
+  @Override
+  public void onNext(final ContextStart contextStart) {
+    Logger.getLogger(this.getClass().getName()).log(Level.INFO, "ContextStart: " + contextStart);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/ContextStartHandler2.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/ContextStartHandler2.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/ContextStartHandler2.java
new file mode 100644
index 0000000..a298ad0
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/ContextStartHandler2.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.tests.subcontexts;
+
+import org.apache.reef.evaluator.context.events.ContextStart;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+final class ContextStartHandler2 implements EventHandler<ContextStart> {
+
+  @Inject
+  ContextStartHandler2() {
+  }
+
+  @Override
+  public void onNext(final ContextStart contextStart) {
+    Logger.getLogger(this.getClass().getName()).log(Level.INFO, "ContextStart: " + contextStart);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/ContextStopHandler1.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/ContextStopHandler1.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/ContextStopHandler1.java
new file mode 100644
index 0000000..7d12bd2
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/ContextStopHandler1.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.tests.subcontexts;
+
+import org.apache.reef.evaluator.context.events.ContextStop;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+final class ContextStopHandler1 implements EventHandler<ContextStop> {
+
+  @Inject
+  ContextStopHandler1() {
+  }
+
+  @Override
+  public void onNext(final ContextStop contextStop) {
+    Logger.getLogger(this.getClass().getName()).log(Level.INFO, "ContextStop: " + contextStop);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/ContextStopHandler2.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/ContextStopHandler2.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/ContextStopHandler2.java
new file mode 100644
index 0000000..d4ebd89
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/ContextStopHandler2.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.tests.subcontexts;
+
+import org.apache.reef.evaluator.context.events.ContextStop;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+final class ContextStopHandler2 implements EventHandler<ContextStop> {
+
+  @Inject
+  ContextStopHandler2() {
+  }
+
+  @Override
+  public void onNext(final ContextStop contextStop) {
+    Logger.getLogger(this.getClass().getName()).log(Level.INFO, "ContextStop: " + contextStop);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/SubContextDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/SubContextDriver.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/SubContextDriver.java
new file mode 100644
index 0000000..01eb271
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/SubContextDriver.java
@@ -0,0 +1,143 @@
+/**
+ * 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.reef.tests.subcontexts;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ClosedContext;
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+final class SubContextDriver {
+
+  private static final Logger LOG = Logger.getLogger(SubContextDriver.class.getName());
+
+  private static String CONTEXT_1_IDENTIFIER = "CONTEXT_1";
+  private static String CONTEXT_2_IDENTIFIER = "CONTEXT_2";
+
+  private State state = State.INIT; // lock: this
+
+  @Inject
+  SubContextDriver() {
+  }
+
+  private enum State {
+    INIT,
+    CONTEXT_1_SUBMITTED,
+    CONTEXT_2_SUBMITTED,
+    CONTEXT_2_CLOSED,
+  }
+
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+
+    @Override
+    public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+
+      LOG.log(Level.FINE, "Submitting root context");
+
+      try {
+
+        final Configuration contextConfiguration = ContextConfiguration.CONF
+            .set(ContextConfiguration.ON_CONTEXT_STARTED, ContextStartHandler1.class)
+            .set(ContextConfiguration.ON_CONTEXT_STOP, ContextStopHandler1.class)
+            .set(ContextConfiguration.IDENTIFIER, CONTEXT_1_IDENTIFIER)
+            .build();
+
+        allocatedEvaluator.submitContext(contextConfiguration);
+
+        synchronized (SubContextDriver.this) {
+          SubContextDriver.this.state = State.CONTEXT_1_SUBMITTED;
+        }
+
+      } catch (final BindException e) {
+        throw new RuntimeException(e);
+      }
+    }
+  }
+
+  final class ContextActiveHandler implements EventHandler<ActiveContext> {
+
+    @Override
+    public void onNext(final ActiveContext activeContext) {
+
+      LOG.log(Level.FINE, "Received ActiveContext: {0}", activeContext);
+
+      if (activeContext.getId().equals(CONTEXT_1_IDENTIFIER)) {
+
+        synchronized (SubContextDriver.this) {
+          assert (SubContextDriver.this.state == State.CONTEXT_1_SUBMITTED);
+        }
+
+        LOG.log(Level.FINE, "Submitting sub context");
+
+        final Configuration contextConfiguration = ContextConfiguration.CONF
+            .set(ContextConfiguration.ON_CONTEXT_STARTED, ContextStartHandler2.class)
+            .set(ContextConfiguration.ON_CONTEXT_STOP, ContextStopHandler2.class)
+            .set(ContextConfiguration.IDENTIFIER, CONTEXT_2_IDENTIFIER)
+            .build();
+
+        activeContext.submitContext(contextConfiguration);
+
+        synchronized (SubContextDriver.this) {
+          SubContextDriver.this.state = State.CONTEXT_2_SUBMITTED;
+        }
+
+
+      } else if (activeContext.getId().equals(CONTEXT_2_IDENTIFIER)) {
+        LOG.log(Level.INFO, "Received sub context. Closing");
+        activeContext.close();
+      }
+    }
+  }
+
+  final class ContextClosedHandler implements EventHandler<ClosedContext> {
+
+    @Override
+    public void onNext(final ClosedContext closedContext) {
+
+      LOG.log(Level.FINE, "Received ClosedContext: {0}", closedContext);
+
+      if (closedContext.getId().equals(CONTEXT_2_IDENTIFIER)) {
+
+        synchronized (SubContextDriver.this) {
+          assert (SubContextDriver.this.state == State.CONTEXT_2_SUBMITTED);
+        }
+
+        closedContext.getParentContext().close();
+        SubContextDriver.this.state = State.CONTEXT_2_CLOSED;
+
+      } else if (closedContext.getId().equals(CONTEXT_1_IDENTIFIER)) {
+
+        synchronized (SubContextDriver.this) {
+          assert (SubContextDriver.this.state == State.CONTEXT_2_CLOSED);
+        }
+
+        throw new IllegalStateException("Received a closed context for the root context");
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/SubContextTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/SubContextTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/SubContextTest.java
new file mode 100644
index 0000000..53d2735
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/SubContextTest.java
@@ -0,0 +1,93 @@
+/**
+ * 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.reef.tests.subcontexts;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.tests.library.driver.OnDriverStartedAllocateOne;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests the creation of context stacks on an Evaluator.
+ */
+public final class SubContextTest {
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  @Test
+  public void testSubContexts() throws BindException, InjectionException {
+
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    final Configuration driverConfiguration = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(this.getClass()))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_SubContextTest_testSubContexts")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, OnDriverStartedAllocateOne.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, SubContextDriver.EvaluatorAllocatedHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_ACTIVE, SubContextDriver.ContextActiveHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_CLOSED, SubContextDriver.ContextClosedHandler.class)
+        .build();
+
+    final LauncherStatus status = DriverLauncher.getLauncher(runtimeConfiguration)
+        .run(driverConfiguration, this.testEnvironment.getTestTimeout());
+
+    Assert.assertTrue("Job state after execution: " + status, status.isSuccess());
+  }
+
+  /**
+   * Same as testSubContexts(), but using default ClosedContext handler.
+   */
+  @Test
+  public void testChainClose() throws BindException, InjectionException {
+
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    final Configuration driverConfiguration = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(this.getClass()))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_SubContextTest_testChainClose")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, OnDriverStartedAllocateOne.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, SubContextDriver.EvaluatorAllocatedHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_ACTIVE, SubContextDriver.ContextActiveHandler.class)
+        .build();
+
+    final LauncherStatus status = DriverLauncher.getLauncher(runtimeConfiguration)
+        .run(driverConfiguration, this.testEnvironment.getTestTimeout());
+
+    Assert.assertTrue("Job state after execution: " + status, status.isSuccess());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/package-info.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/package-info.java
new file mode 100644
index 0000000..4382e15
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/subcontexts/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Tests the creation of context stacks on an Evaluator.
+ */
+package org.apache.reef.tests.subcontexts;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskcounting/TaskCountingDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskcounting/TaskCountingDriver.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskcounting/TaskCountingDriver.java
new file mode 100644
index 0000000..947416b
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskcounting/TaskCountingDriver.java
@@ -0,0 +1,109 @@
+/**
+ * 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.reef.tests.taskcounting;
+
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.task.CompletedTask;
+import org.apache.reef.driver.task.RunningTask;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tests.library.exceptions.DriverSideFailure;
+import org.apache.reef.tests.library.tasks.NoopTask;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StopTime;
+
+import javax.inject.Inject;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+
+@Unit
+final class TaskCountingDriver {
+
+  private final Set<String> expectedRunningTaskIds = new HashSet<>();
+  private AtomicInteger numberOfTaskSubmissions = new AtomicInteger(1000);
+
+  @Inject
+  TaskCountingDriver() {
+  }
+
+  private final Configuration getTaskConfiguration(final String taskId) {
+    return TaskConfiguration.CONF
+        .set(TaskConfiguration.IDENTIFIER, taskId)
+        .set(TaskConfiguration.TASK, NoopTask.class)
+        .build();
+  }
+
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+
+    @Override
+    public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+      synchronized (expectedRunningTaskIds) {
+        final String taskId = "Task-" + numberOfTaskSubmissions.getAndDecrement();
+        final Configuration taskConfiguration = getTaskConfiguration(taskId);
+        allocatedEvaluator.submitTask(taskConfiguration);
+        expectedRunningTaskIds.add(taskId);
+      }
+    }
+  }
+
+  final class TaskRunningHandler implements EventHandler<RunningTask> {
+
+    @Override
+    public void onNext(final RunningTask runningTask) {
+      synchronized (expectedRunningTaskIds) {
+        final boolean isExpected = expectedRunningTaskIds.remove(runningTask.getId());
+        if (!isExpected) {
+          throw new DriverSideFailure("Unexpected RunningTask: " + runningTask.getId());
+        }
+      }
+    }
+  }
+
+  final class TaskCompletedHandler implements EventHandler<CompletedTask> {
+
+    @Override
+    public void onNext(final CompletedTask completedTask) {
+      synchronized (expectedRunningTaskIds) {
+        final int nextTaskNumber = numberOfTaskSubmissions.getAndDecrement();
+        if (nextTaskNumber > 0) {
+          final String taskId = "Task-" + nextTaskNumber;
+          completedTask.getActiveContext().submitTask(getTaskConfiguration(taskId));
+          expectedRunningTaskIds.add(taskId);
+        } else {
+          completedTask.getActiveContext().close();
+        }
+      }
+    }
+  }
+
+  final class DriverStopHandler implements EventHandler<StopTime> {
+
+    @Override
+    public void onNext(final StopTime stopTime) {
+      synchronized (expectedRunningTaskIds) {
+        if (!expectedRunningTaskIds.isEmpty()) {
+          throw new DriverSideFailure("Still expecting RunningTasks");
+        }
+      }
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskcounting/TaskCountingTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskcounting/TaskCountingTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskcounting/TaskCountingTest.java
new file mode 100644
index 0000000..0509185
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskcounting/TaskCountingTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.reef.tests.taskcounting;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.tests.library.driver.OnDriverStartedAllocateOne;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests the submission of multiple tasks to an Evaluator in sequence.
+ */
+public final class TaskCountingTest {
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    this.testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  private Configuration getDriverConfiguration() {
+    return DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(this.getClass()))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TaskCounting")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, OnDriverStartedAllocateOne.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, TaskCountingDriver.EvaluatorAllocatedHandler.class)
+        .set(DriverConfiguration.ON_TASK_RUNNING, TaskCountingDriver.TaskRunningHandler.class)
+        .set(DriverConfiguration.ON_TASK_COMPLETED, TaskCountingDriver.TaskCompletedHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_STOP, TaskCountingDriver.DriverStopHandler.class)
+        .build();
+  }
+
+  @Test
+  public void testTaskCounting() throws InjectionException {
+    final LauncherStatus state = DriverLauncher.getLauncher(this.testEnvironment.getRuntimeConfiguration())
+        .run(getDriverConfiguration());
+
+    Assert.assertTrue("Job state after execution: " + state, state.isSuccess());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskcounting/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskcounting/package-info.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskcounting/package-info.java
new file mode 100644
index 0000000..c552fbd
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskcounting/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Tests the submission of multiple tasks to an Evaluator in sequence.
+ */
+package org.apache.reef.tests.taskcounting;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskresubmit/TaskResubmitDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskresubmit/TaskResubmitDriver.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskresubmit/TaskResubmitDriver.java
new file mode 100644
index 0000000..35ee102
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskresubmit/TaskResubmitDriver.java
@@ -0,0 +1,85 @@
+/**
+ * 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.reef.tests.taskresubmit;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.task.FailedTask;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tests.TestUtils;
+import org.apache.reef.tests.fail.task.FailTaskCall;
+import org.apache.reef.tests.library.exceptions.SimulatedTaskFailure;
+import org.apache.reef.tests.library.exceptions.TaskSideFailure;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+class TaskResubmitDriver {
+
+  private static final Logger LOG = Logger.getLogger(TaskResubmitDriver.class.getName());
+
+  private int failuresSeen = 0;
+
+  @Inject
+  TaskResubmitDriver() {
+  }
+
+  private static Configuration getTaskConfiguration() {
+    return TaskConfiguration.CONF
+        .set(TaskConfiguration.TASK, FailTaskCall.class)
+        .set(TaskConfiguration.IDENTIFIER, "FailTask")
+        .build();
+  }
+
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+
+    @Override
+    public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+      allocatedEvaluator.submitTask(getTaskConfiguration());
+    }
+  }
+
+  final class TaskFailedHandler implements EventHandler<FailedTask> {
+
+    @Override
+    public void onNext(final FailedTask failedTask) {
+
+      LOG.log(Level.INFO, "FailedTask: {0}", failedTask);
+
+      final Throwable ex = failedTask.getReason().get();
+      if (!TestUtils.hasCause(ex, SimulatedTaskFailure.class)) {
+        final String msg = "Expected SimulatedTaskFailure from " + failedTask.getId();
+        LOG.log(Level.SEVERE, msg, ex);
+        throw new TaskSideFailure(msg, ex);
+      }
+
+      final ActiveContext activeContext = failedTask.getActiveContext().get();
+      if (++TaskResubmitDriver.this.failuresSeen <= 1) { // resubmit the task
+        activeContext.submitTask(getTaskConfiguration());
+      } else { // Close the context
+        activeContext.close();
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskresubmit/TaskResubmitTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskresubmit/TaskResubmitTest.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskresubmit/TaskResubmitTest.java
new file mode 100644
index 0000000..d53ea46
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskresubmit/TaskResubmitTest.java
@@ -0,0 +1,72 @@
+/**
+ * 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.reef.tests.taskresubmit;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tests.TestEnvironment;
+import org.apache.reef.tests.TestEnvironmentFactory;
+import org.apache.reef.tests.library.driver.OnDriverStartedAllocateOne;
+import org.apache.reef.util.EnvironmentUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Tests whether (failed) tasks can be resubmitted with identical Configurations, including Task Ids.
+ */
+public final class TaskResubmitTest {
+
+  private final TestEnvironment testEnvironment = TestEnvironmentFactory.getNewTestEnvironment();
+
+  @Before
+  public void setUp() throws Exception {
+    this.testEnvironment.setUp();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    this.testEnvironment.tearDown();
+  }
+
+  @Test
+  public void testTaskResubmission() throws BindException, InjectionException {
+
+    final Configuration runtimeConfiguration = this.testEnvironment.getRuntimeConfiguration();
+
+    final Configuration driverConfiguration = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(this.getClass()))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "TEST_TaskResubmitTest")
+        .set(DriverConfiguration.ON_DRIVER_STARTED, OnDriverStartedAllocateOne.class)
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, TaskResubmitDriver.EvaluatorAllocatedHandler.class)
+        .set(DriverConfiguration.ON_TASK_FAILED, TaskResubmitDriver.TaskFailedHandler.class)
+        .build();
+
+    final LauncherStatus state = DriverLauncher.getLauncher(runtimeConfiguration)
+        .run(driverConfiguration, this.testEnvironment.getTestTimeout());
+
+    Assert.assertTrue("Job state after execution: " + state, state.isSuccess());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskresubmit/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskresubmit/package-info.java b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskresubmit/package-info.java
new file mode 100644
index 0000000..a37cc1d
--- /dev/null
+++ b/lang/java/reef-tests/src/test/java/org/apache/reef/tests/taskresubmit/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Tests whether (failed) tasks can be resubmitted with identical Configurations, including Task Ids.
+ */
+package org.apache.reef.tests.taskresubmit;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-utils-hadoop/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-utils-hadoop/pom.xml b/lang/java/reef-utils-hadoop/pom.xml
new file mode 100644
index 0000000..d1e4375
--- /dev/null
+++ b/lang/java/reef-utils-hadoop/pom.xml
@@ -0,0 +1,45 @@
+<?xml version="1.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.
+-->
+<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.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>reef-utils-hadoop</artifactId>
+    <name>REEF Utils for Hadoop</name>
+    <description>Utilities for using REEF on Hadoop.</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-common</artifactId>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-utils-hadoop/src/main/java/org/apache/reef/util/HadoopEnvironment.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-utils-hadoop/src/main/java/org/apache/reef/util/HadoopEnvironment.java b/lang/java/reef-utils-hadoop/src/main/java/org/apache/reef/util/HadoopEnvironment.java
new file mode 100644
index 0000000..513a10a
--- /dev/null
+++ b/lang/java/reef-utils-hadoop/src/main/java/org/apache/reef/util/HadoopEnvironment.java
@@ -0,0 +1,37 @@
+/**
+ * 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.reef.util;
+
+/**
+ * Constants for the various Hadoop environment variables.
+ */
+public class HadoopEnvironment {
+
+  public static final String HADOOP_CONF_DIR = "HADOOP_CONF_DIR";
+  public static final String HADOOP_HOME = "HADOOP_HOME";
+  public static final String HADOOP_COMMON_HOME = "HADOOP_COMMON_HOME";
+  public static final String HADOOP_YARN_HOME = "HADOOP_YARN_HOME";
+  public static final String HADOOP_HDFS_HOME = "HADOOP_HDFS_HOME";
+  public static final String HADOOP_MAPRED_HOME = "HADOOP_MAPRED_HOME";
+
+  private HadoopEnvironment() {
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-utils-hadoop/src/main/java/org/apache/reef/util/logging/DFSHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-utils-hadoop/src/main/java/org/apache/reef/util/logging/DFSHandler.java b/lang/java/reef-utils-hadoop/src/main/java/org/apache/reef/util/logging/DFSHandler.java
new file mode 100644
index 0000000..64f024c
--- /dev/null
+++ b/lang/java/reef-utils-hadoop/src/main/java/org/apache/reef/util/logging/DFSHandler.java
@@ -0,0 +1,146 @@
+/**
+ * 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.reef.util.logging;
+
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.logging.*;
+
+/**
+ * A java.util.logging.Handler that logs to (H)DFS.
+ */
+public final class DFSHandler extends Handler {
+
+  private static final String CLASS_NAME = DFSHandler.class.getName();
+  public static final String DFS_PATH_OPTION = CLASS_NAME + ".folder";
+  public static final String FORMATTER_OPTION = CLASS_NAME + ".formatter";
+  private final StreamHandler streamHandler;
+  private final OutputStream logOutputStream;
+
+  @Inject
+  public DFSHandler() throws IOException {
+    final LogManager logManager = LogManager.getLogManager();
+    final String fileName = logManager.getProperty(DFS_PATH_OPTION) + "/log.txt";
+    logOutputStream = FileSystem.get(new Configuration()).create(new Path(fileName), true);
+    final Formatter logFormatter = getInstance(logManager.getProperty(FORMATTER_OPTION), new SimpleFormatter());
+    this.streamHandler = new StreamHandler(logOutputStream, logFormatter);
+  }
+
+  private static final <T> T getInstance(final String className, final T defaultValue) {
+    try {
+      final Class aClass = ClassLoader.getSystemClassLoader().loadClass(className);
+      return (T) aClass.newInstance();
+    } catch (final Exception e) {
+      return defaultValue;
+    }
+
+  }
+
+  @Override
+  public Formatter getFormatter() {
+    return this.streamHandler.getFormatter();
+  }
+
+  @Override
+  public void setFormatter(final Formatter formatter) throws SecurityException {
+    this.streamHandler.setFormatter(formatter);
+  }
+
+  @Override
+  public String getEncoding() {
+    return this.streamHandler.getEncoding();
+  }
+
+  @Override
+  public void setEncoding(final String s) throws SecurityException, UnsupportedEncodingException {
+    this.streamHandler.setEncoding(s);
+  }
+
+  @Override
+  public Filter getFilter() {
+    return this.streamHandler.getFilter();
+  }
+
+  @Override
+  public void setFilter(final Filter filter) throws SecurityException {
+    this.streamHandler.setFilter(filter);
+  }
+
+  @Override
+  public ErrorManager getErrorManager() {
+    return this.streamHandler.getErrorManager();
+  }
+
+  @Override
+  public void setErrorManager(final ErrorManager errorManager) {
+    this.streamHandler.setErrorManager(errorManager);
+  }
+
+  @Override
+  protected void reportError(final String s, final Exception e, final int i) {
+    super.reportError(s, e, i);
+  }
+
+  @Override
+  public synchronized Level getLevel() {
+    return this.streamHandler.getLevel();
+  }
+
+  @Override
+  public synchronized void setLevel(final Level level) throws SecurityException {
+    this.streamHandler.setLevel(level);
+  }
+
+  @Override
+  public boolean isLoggable(final LogRecord logRecord) {
+    return this.streamHandler.isLoggable(logRecord);
+  }
+
+  @Override
+  public void publish(final LogRecord logRecord) {
+    this.streamHandler.publish(logRecord);
+  }
+
+  @Override
+  public void flush() {
+    this.streamHandler.flush();
+    try {
+      this.logOutputStream.flush();
+    } catch (final IOException e) {
+      // Eating it as it has nowhere to go.
+    }
+  }
+
+  @Override
+  public void close() throws SecurityException {
+    this.streamHandler.close();
+    try {
+      this.logOutputStream.close();
+    } catch (final IOException e) {
+      // Eating it as it has nowhere to go.
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-utils/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-utils/pom.xml b/lang/java/reef-utils/pom.xml
new file mode 100644
index 0000000..62f4530
--- /dev/null
+++ b/lang/java/reef-utils/pom.xml
@@ -0,0 +1,45 @@
+<?xml version="1.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.
+-->
+<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.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>reef-utils</artifactId>
+    <name>REEF Utils</name>
+    <description>Utilities used across REEF modules.</description>
+
+    <!-- This module shouldn't have many dependencies to make sure it is broadly usable across reef subprojects -->
+    <dependencies>
+        <dependency>
+            <groupId>net.jcip</groupId>
+            <artifactId>jcip-annotations</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-utils/src/main/java/org/apache/reef/util/Optional.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-utils/src/main/java/org/apache/reef/util/Optional.java b/lang/java/reef-utils/src/main/java/org/apache/reef/util/Optional.java
new file mode 100644
index 0000000..6dc1a6e
--- /dev/null
+++ b/lang/java/reef-utils/src/main/java/org/apache/reef/util/Optional.java
@@ -0,0 +1,128 @@
+/**
+ * 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.reef.util;
+
+import net.jcip.annotations.Immutable;
+import net.jcip.annotations.ThreadSafe;
+
+import java.io.Serializable;
+
+/**
+ * Represents an optional value. Loosely based on
+ * <a href="http://download.java.net/jdk8/docs/api/java/util/Optional.html"></a>The Java 8 version</a>, but filtered for
+ * Java 7 compatibility.
+ */
+@Immutable
+@ThreadSafe
+public final class Optional<T> implements Serializable {
+
+  private static final long serialVersionUID = 42L;
+
+  private final T value;
+  private final String valueStr;
+  private final int valueHash;
+
+  private Optional(final T value) {
+    this.value = value;
+    this.valueStr = "Optional:{" + value + '}';
+    this.valueHash = value.hashCode();
+  }
+
+  private Optional() {
+    this.value = null;
+    this.valueStr = "OptionalvNothing";
+    this.valueHash = 0;
+  }
+
+  /**
+   * @return An Optional with the given value.
+   * @throws NullPointerException if the value is null
+   */
+  public static <T> Optional<T> of(final T value) throws NullPointerException {
+    if (null == value) {
+      throw new NullPointerException("Passed a null value. Use ofNullable() instead");
+    }
+    return new Optional<>(value);
+  }
+
+  /**
+   * @return an Optional with no value.
+   */
+  public static <T> Optional<T> empty() {
+    return new Optional<>();
+  }
+
+  /**
+   * @return An optional representing the given value, or an empty Optional.
+   */
+  public static <T> Optional<T> ofNullable(final T value) {
+    if (null == value) {
+      return Optional.empty();
+    } else {
+      return Optional.of(value);
+    }
+  }
+
+  /**
+   * @return the value represented or null, if isPresent() is false.
+   */
+  public T get() {
+    return this.value;
+  }
+
+  /**
+   * @param other
+   * @return the value of this Optional or other, if no value exists.
+   */
+  public T orElse(final T other) {
+    if (isPresent()) {
+      return this.get();
+    } else {
+      return other;
+    }
+  }
+
+  /**
+   * @return true if there is a value, false otherwise.
+   */
+  public boolean isPresent() {
+    return null != this.value;
+  }
+
+  @Override
+  public boolean equals(final Object obj) {
+
+    if (this == obj) return true;
+
+    if (obj == null || getClass() != obj.getClass()) return false;
+
+    final Optional that = (Optional) obj;
+    return this.value == that.value || (this.value != null && this.value.equals(that.value));
+  }
+
+  @Override
+  public int hashCode() {
+    return this.valueHash;
+  }
+
+  @Override
+  public String toString() {
+    return this.valueStr;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-utils/src/main/java/org/apache/reef/util/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-utils/src/main/java/org/apache/reef/util/package-info.java b/lang/java/reef-utils/src/main/java/org/apache/reef/util/package-info.java
new file mode 100644
index 0000000..1058756
--- /dev/null
+++ b/lang/java/reef-utils/src/main/java/org/apache/reef/util/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Utilities used across reef modules. Subpackages are structred following the java.utils package.
+ */
+package org.apache.reef.util;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-utils/src/test/java/org/apache/reef/util/OptionalTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-utils/src/test/java/org/apache/reef/util/OptionalTest.java b/lang/java/reef-utils/src/test/java/org/apache/reef/util/OptionalTest.java
new file mode 100644
index 0000000..f643ab0
--- /dev/null
+++ b/lang/java/reef-utils/src/test/java/org/apache/reef/util/OptionalTest.java
@@ -0,0 +1,99 @@
+/**
+ * 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.reef.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+
+/**
+ * Tests for Optional.
+ */
+public class OptionalTest {
+
+  @Test
+  public void testEmpty() {
+    Assert.assertFalse("An empty Optional should return false to isPresent()",
+        Optional.empty().isPresent());
+  }
+
+  @Test
+  public void testOf() {
+    Assert.assertTrue("Optional.of() needs to return an Optional where isPresent() returns true",
+        Optional.of(2).isPresent());
+  }
+
+  @Test(expected = NullPointerException.class)
+  public void testOfNull() {
+    final Optional<Integer> o = Optional.of(null);
+  }
+
+  @Test
+  public void testOfRandom() {
+    final double value = Math.random();
+    final Optional<Double> o = Optional.of(value);
+    Assert.assertEquals(value, (double) o.get(), 1e-12);
+  }
+
+  @Test
+  public void testOfNullable() {
+    Assert.assertFalse(Optional.ofNullable(null).isPresent());
+    Assert.assertTrue(Optional.ofNullable(1).isPresent());
+    Assert.assertEquals(Optional.ofNullable(1).get(), Integer.valueOf(1));
+  }
+
+  @Test
+  public void testOrElse() {
+    Assert.assertEquals(Optional.empty().orElse(2), 2);
+    Assert.assertEquals(Optional.of(1).orElse(2), Integer.valueOf(1));
+  }
+
+  @Test
+  public void testEquals() {
+    Assert.assertEquals(Optional.empty(), Optional.empty());
+    Assert.assertEquals(Optional.empty(), Optional.ofNullable(null));
+    Assert.assertEquals(Optional.of(1), Optional.of(1));
+    Assert.assertEquals(Optional.of("one"), Optional.of("one"));
+    Assert.assertFalse(Optional.of("one").equals(Optional.of("two")));
+  }
+
+  @Test
+  public void testEqualsCornerCases() {
+
+    // We lose type coercion:
+    Assert.assertFalse(Optional.of(1L).equals(Optional.of(1)));
+    Assert.assertTrue(1L == 1);
+    Assert.assertTrue(new Integer(1) == 1L);
+
+    // .equals() isn't typesafe, so we lose compile-time type checking:
+    Assert.assertFalse(Optional.of(1L).equals(1));
+
+    Assert.assertFalse(Optional.empty().equals(null));
+    Assert.assertFalse(Optional.of(3).equals(3));
+    Assert.assertFalse(Optional.of("one").equals(1));
+
+    // Assert.assertFalse("one" == 1); // incompatible operands; does not compile.
+
+    Assert.assertFalse(Optional.of(new ArrayList<>()).equals(Optional.of(new Object[]{})));
+
+    // Incompatible operands; does not compile, though == between objects is almost always a typo:
+    // Assert.assertFalse(new java.util.ArrayList() == new java.awt.List());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/.gitattributes
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/.gitattributes b/lang/java/reef-wake/.gitattributes
new file mode 100644
index 0000000..db5b15f
--- /dev/null
+++ b/lang/java/reef-wake/.gitattributes
@@ -0,0 +1,3 @@
+# Commit text files using LF endings
+*.java text eol=lf whitespace=trailing-space,space-before-tab,tab-in-indent,blank-at-eof
+* text=auto

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/.gitignore
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/.gitignore b/lang/java/reef-wake/.gitignore
new file mode 100644
index 0000000..a7927e6
--- /dev/null
+++ b/lang/java/reef-wake/.gitignore
@@ -0,0 +1,16 @@
+tmp
+bin
+tang.conf
+.DS_Store
+target
+generated
+.settings
+.classpath
+.project
+.sw[op]
+*.sw[op]
+.externalToolBuilders
+nbactions.xml
+.idea
+*.iml
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/README.md
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/README.md b/lang/java/reef-wake/README.md
new file mode 100644
index 0000000..0b56cf0
--- /dev/null
+++ b/lang/java/reef-wake/README.md
@@ -0,0 +1,94 @@
+Wake
+====
+Wake is an event-driven framework based on ideas from SEDA, Click, Akka and Rx.  It is *general purpose* in the sense that it is designed to support computationally intensive applications as well as high performance networking, storage, and legacy I/O systems.  We implemented Wake to support high-performance, scalable analytical processing systems ("big data" applications), and have used it to implement control plane logic (which requires high fanout and low latency) and the data plane (which requires high-throughput processing as well).
+
+
+Background
+----------
+Wake applications consist of asynchronous *event handlers* that run inside of *stages*.  Stages provide scheduling primitives such as thread pool sizing and performance isolation between event handlers.  In addition to event handler and stage APIs, Wake includes profiling tools and a rich standard library of primitives for system builders.
+
+Event driven processing frameworks improve upon the performance of threaded architectures in two ways: (1) Event handlers often have lower memory and context switching overhead than threaded solutions, and (2) event driven systems allow applications to allocate and monitor computational and I/O resources in an extremely fine-grained fashion.  Modern threading packages have done much to address the first concern, and have significantly lowered concurrency control and other implementation overheads in recent years.  However, fine grained resource allocation remains a challenge in threaded systems, and is Wake's primary advantage over threading.
+
+Early event driven systems such as SEDA executed each event handler in a dedicated thread pool called a stage.  This isolated low-latency event handlers (such as cache lookups) from expensive high-latency operations, such as disk I/O.  With a single thread pool, high-latency I/O operations can easily monopolize the thread pool, causing all of the CPUs to block on disk I/O, even when there is computation to be scheduled.  With separate thread pools, the operating system schedules I/O requests and computation separately, guaranteeing that runnable computations will not block on I/O requests.
+
+This is in contrast to event-driven systems such as the Click modular router that were designed to maximize throughput for predictable, low latency event-handlers.  When possible, Click aggressively chains event handlers together, reducing the cost of an event dispatch to that of a function call, and allowing the compiler to perform optimizations such as inlining and constant propagation across event handlers.
+
+Wake allows developers to trade off between these two extremes by explicitly partitioning their event handlers into stages.  Within a stage, event handlers engage in *thread-sharing* by simply calling each other directly.  When an event crosses a stage boundary, it is placed in a queue of similar events.  The queue is then drained by the threads managed by the receiving stage.
+
+Although event handling systems improve upon threaded performance in theory, they are notoriously difficult to reason about.  We kept this in mind while designing Wake, and have gone to great pains to ensure that its APIs are simple and easy to implement without sacrificing our performance goals.
+
+Other event driven systems provide support for so-called *push-based* and *pull-based* event handlers.  In push-based systems, event sources invoke event handlers that are exposed by the events' destinations, while pull-based APIs have the destination code invoke iterators to obtain the next available event from the source.
+
+Wake is completely push based.  This eliminates the need for push and pull based variants of event handling logic, and also allowed us to unify all error handling in Wake into a single API.  It is always possible to convert between push and pull based APIs by inserting a queue and a thread boundary between the push and pull based code.  Wake supports libraries and applications that use this trick, since operating systems and legacy code sometimes expose pull-based APIs.
+
+Systems such as Rx allow event handlers to be dynamically registered and torn down at runtime, allowing applications to evolve over time.  This leads to complicated setup and teardown protocols, where event handlers need to reason about the state of upstream and downstream handlers, both during setup and teardown, but also when routing messages at runtime.  It also encourages design patterns such as dynamic event dispatching that break standard compiler optimizations.  In contrast, Wake applications consist of immutable graphs of event handlers that are built up from sink to source.  This ensures that, once an event handler has been instantiated, all downstream handlers are ready to receive messages.
+
+Wake is designed to work with Tang, a dependency injection system that focuses on configuration and debuggability.  This makes it extremely easy to wire up complicated graphs of event handling logic.  In addition to making it easy to build up event-driven applications, Tang provides a range of static analysis tools and provides a simple aspect-style programming facility that supports Wake's latency and throughput profilers.
+
+
+Core API
+--------
+
+### Event Handlers
+
+Wake provides two APIs for event handler implementations.  The first is the [EventHandler](wake/src/main/java/org/apache/reef/wake/EventHandler.java) interface:
+```java
+public interface EventHandler<T> {
+  void onNext(T value);
+}
+```
+Callers of `onNext()` should assume that it is asynchronous, and that it always succeeds.  Unrecoverable errors should be reported by throwing a runtime exception (which should not be caught, and will instead take down the process).  Recoverable errors are reported by invoking an event handler that contains the appropriate error handling logic.
+
+The latter approach can be implemented by registering separate event handlers for each type of error.  However, for convenience, it is formalized in Wake's simplified version of the Rx [Observer](wake/src/main/java/org/apache/reef/wake/rx/Observer.java) interface:
+```java
+public interface Observer<T> {
+  void onNext(final T value);
+  void onError(final Exception error);
+  void onCompleted();
+}
+```
+The `Observer` is designed for stateful event handlers that need to be explicitly torn down at exit, or when errors occor.  Such event handlers may maintain open network sockets, write to disk, buffer output, and so on.  As with `onNext()`, neither `onError()` nor `onCompleted()` throw exceptions.  Instead, callers should assume that they are asynchronously invoked.
+
+`EventHandler` and `Observer` implementations should be threadsafe and handle concurrent invocations of `onNext()`.  However, it is illegal to call `onCompleted()` or `onError()` in race with any calls to `onNext()`, and the call to `onCompleted()` or `onError()` must be the last call made to the object.  Therefore, implementations of `onCompleted()` and `onError()` can assume they have a lock on `this`, and that `this` has not been torn down and is still in a valid state.
+
+We chose these invariants because they are simple and easy to enforce.  In most cases, application logic simply limits calls to `onCompleted()` and `onError()` to other implementations of `onError()` and `onCompleted()`, and relies upon Wake (and any intervening application logic) to obey the same protocol.
+
+### Stages
+
+Wake Stages are responsible for resource management.  The base [Stage](wake/src/main/java/org/apache/reef/wake/Stage.java) interface is fairly simple:
+
+```java
+public interface Stage extends AutoCloseable { }
+```
+
+The only method it contains is `close()` from auto-closable.  This reflects the fact that Wake stages can either contain `EventHandler`s, as [EStage](wake/src/main/java/org/apache/reef/wake/EStage.java) implementations do:
+```java
+public interface EStage<T> extends EventHandler<T>, Stage { }
+```
+or they can contain `Observable`s, as [RxStage](wake/src/main/java/org/apache/reef/wake/rx/RxStage.java) implementations do:
+```java
+public interface RxStage<T> extends Observer<T>, Stage { }
+```
+In both cases, the stage simply exposes the same API as the event handler that it manages.  This allows code that produces events to treat downstream stages and raw `EventHandlers` / `Observers` interchangebly.   Recall that Wake implements thread sharing by allowing EventHandlers and Observers to directly invoke each other.  Since Stages implement the same interface as raw EventHandlers and Observers, this pushes the placement of thread boundaries and other scheduling tradeoffs to the code that is instantiating the application.  In turn, this simplifies testing and improves the reusability of code written on top of Wake.
+
+#### `close()` vs. `onCompleted()`
+
+It may seem strange that Wake RxStage exposes two shutdown methods: `close()` and `onCompleted()`.  Since `onCompleted()` is part of the Observer API, it may be implemented in an asynchronous fashion.  This makes it difficult for applications to cleanly shut down, since, even after `onCompleted()` has returned, resources may still be held by the downstream code.
+
+In contrast, `close()` is synchronous, and is not allowed to return until all queued events have been processed, and any resources held by the Stage implementation have been released.  The upshot is that shutdown sequences in Wake work as follows:  Once the upstream event sources are done calling `onNext()` (and all calls to `onNext()` have returned), `onCompleted()` or `onError()` is called exactly once per stage.  After the `onCompleted()` or `onError()` call to a given stage has returned, `close()` must be called.  Once `close()` returns, all resources have been released, and the JVM may safely exit, or the code that is invoking Wake may proceed under the assumption that no resources or memory have been leaked.  Note that, depending on the implementation of the downstream Stage, there may be a delay between the return of calls such as `onNext()` or `onCompleted()` and their execution.  Therefore, it is possible that the stage will continue to schedule `onNext()` calls after `clos
 e()` has been invoked.  It is illegal for stages to drop events on shutdown, so the stage will execute the requests in its queue before it releases resources and returns from `close()`.
+
+`Observer` implementations do not expose a `close()` method, and generally do not invoke `close()`.  Instead, when `onCompleted()` is invoked, it should arrange for `onCompleted()` to be called on any `Observer` instances that `this` directly invokes, free any resources it is holding, and then return.  Since the downstream `onCompleted()` calls are potentially asynchronous, it cannot assume that downstream cleanup completes before it returns.
+
+In a thread pool `Stage`, the final `close()` call will block until there are no more outstanding events queued in the stage.  Once `close()` has been called (and returns) on each stage, no events are left in any queues, and no `Observer` or `EventHandler` objects are holding resources or scheduled on any cores, so shutdown is compelete.
+
+Helper libraries
+----------------
+
+Wake includes a number of standard library packages:
+
+ - ```org.apache.reef.wake.time``` allows events to be scheduled in the future, and notifies the application when it starts and when it is being torn down.
+ - ```org.apache.reef.wake.remote``` provides networking primitives, including hooks into netty (a high-performance event-based networking library for Java).
+ - ```org.apache.reef.wake.metrics``` provides implementations of standard latency and throughput instrumentation.
+ - ```org.apache.reef.wake.profiler``` provides a graphical profiler that automatically instruments Tang-based Wake applications.
+
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/pom.xml b/lang/java/reef-wake/pom.xml
new file mode 100644
index 0000000..88eeea5
--- /dev/null
+++ b/lang/java/reef-wake/pom.xml
@@ -0,0 +1,38 @@
+<?xml version="1.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.
+-->
+<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>
+    <packaging>pom</packaging>
+    <name>REEF Wake Project</name>
+    <artifactId>wake-project</artifactId>
+
+    <parent>
+        <groupId>org.apache.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <modules>
+        <module>wake</module>
+    </modules>
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/pom.xml b/lang/java/reef-wake/wake/pom.xml
new file mode 100644
index 0000000..75fc953
--- /dev/null
+++ b/lang/java/reef-wake/wake/pom.xml
@@ -0,0 +1,123 @@
+<?xml version="1.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.
+-->
+<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>
+    <artifactId>wake</artifactId>
+    <name>REEF Wake</name>
+
+    <parent>
+        <groupId>org.apache.reef</groupId>
+        <artifactId>wake-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <build>
+
+        <resources>
+            <resource>
+                <targetPath>META-INF/conf</targetPath>
+                <filtering>false</filtering>
+                <directory>${basedir}/src/main/conf</directory>
+                <includes>
+                    <include>*.xml</include>
+                    <include>*.properties</include>
+                </includes>
+                <excludes>
+                </excludes>
+            </resource>
+        </resources>
+
+        <plugins>
+            <plugin>
+                <artifactId>maven-antrun-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>generate-sources</id>
+                        <phase>generate-sources</phase>
+                        <configuration>
+                            <tasks>
+                                <mkdir dir="target/generated-sources/proto"/>
+                                <exec executable="protoc">
+                                    <arg value="--proto_path=src/main/proto/"/>
+                                    <arg value="--java_out=target/generated-sources/proto"/>
+                                    <arg value="src/main/proto/RemoteProtocol.proto"/>
+                                </exec>
+                                <exec executable="protoc">
+                                    <arg value="--proto_path=src/test/proto/"/>
+                                    <arg value="--java_out=target/generated-sources/proto"/>
+                                    <arg value="src/test/proto/TestProtocol.proto"/>
+                                </exec>
+                            </tasks>
+                            <sourceRoot>target/generated-sources/proto</sourceRoot>
+                        </configuration>
+                        <goals>
+                            <goal>run</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>add-source</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>target/generated-sources/proto</source>
+                            </sources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>cglib</groupId>
+            <artifactId>cglib</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>io.netty</groupId>
+            <artifactId>netty-all</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.protobuf</groupId>
+            <artifactId>protobuf-java</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>tang</artifactId>
+        </dependency>
+    </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/AbstractEStage.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/AbstractEStage.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/AbstractEStage.java
new file mode 100644
index 0000000..30cf265
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/AbstractEStage.java
@@ -0,0 +1,91 @@
+/**
+ * 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.reef.wake;
+
+import org.apache.reef.wake.metrics.Meter;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * An {@link EStage} that implements metering
+ *
+ * @param <T> type
+ */
+public abstract class AbstractEStage<T> implements EStage<T> {
+
+  protected final AtomicBoolean closed;
+  protected final String name;
+  protected final Meter inMeter;
+
+  /**
+   * outputs share a single meter
+   */
+  protected final Meter outMeter;
+
+  /**
+   * Constructs an abstract estage
+   *
+   * @parm stageName the stage name
+   */
+  public AbstractEStage(String stageName) {
+    this.closed = new AtomicBoolean(false);
+    this.name = stageName;
+    this.inMeter = new Meter(stageName + "_in");
+    this.outMeter = new Meter(stageName + "_out");
+  }
+
+  /**
+   * Gets the input meter of this stage
+   *
+   * @return the input meter
+   */
+  public Meter getInMeter() {
+    return inMeter;
+  }
+
+  /**
+   * Gets the output meter of this stage
+   *
+   * @return the output meter
+   */
+  public Meter getOutMeter() {
+    return outMeter;
+  }
+
+  /**
+   * Updates the input meter.
+   * <p/>
+   * Stages that want to meter their
+   * input must call this each time an event is input.
+   */
+  protected void beforeOnNext() {
+    inMeter.mark(1);
+  }
+
+  /**
+   * Updates the output meter.
+   * <p/>
+   * Stages that want to meter their
+   * output must call this each time an event is output.
+   */
+  protected void afterOnNext() {
+    outMeter.mark(1);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/ComparableIdentifier.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/ComparableIdentifier.java b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/ComparableIdentifier.java
new file mode 100644
index 0000000..a428266
--- /dev/null
+++ b/lang/java/reef-wake/wake/src/main/java/org/apache/reef/wake/ComparableIdentifier.java
@@ -0,0 +1,27 @@
+/**
+ * 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.reef.wake;
+
+/**
+ * Identifier that can be totally ordered.
+ *
+ * @param <T> type
+ */
+public interface ComparableIdentifier extends Identifier, Comparable<Identifier> {
+}


[09/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestTang.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestTang.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestTang.java
new file mode 100644
index 0000000..fcb0ad6
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestTang.java
@@ -0,0 +1,1356 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.ThreeConstructors.TCFloat;
+import org.apache.reef.tang.ThreeConstructors.TCInt;
+import org.apache.reef.tang.ThreeConstructors.TCString;
+import org.apache.reef.tang.annotations.*;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.ClassHierarchyException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.exceptions.NameResolutionException;
+import org.apache.reef.tang.formats.ConfigurationFile;
+import org.apache.reef.tang.util.ReflectionUtilities;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import javax.inject.Inject;
+
+interface SMC {
+}
+
+@DefaultImplementation(HaveDefaultImplImpl.class)
+interface HaveDefaultImpl {
+}
+
+@DefaultImplementation(name = "org.apache.reef.tang.HaveDefaultStringImplImpl")
+interface HaveDefaultStringImpl {
+}
+
+interface Interf {
+}
+
+interface IfaceWithDefault {
+}
+
+interface X<T> {
+}
+
+interface Bottle<Y> {
+
+}
+
+interface EventHandler<T> {
+}
+
+@DefaultImplementation(MyEventHandler.class)
+interface MyEventHandlerIface extends EventHandler<Foo> {
+}
+
+interface SomeIface {
+}
+
+@DefaultImplementation(AHandlerImpl.class)
+interface AHandler extends EventHandler<AH> {
+}
+
+@DefaultImplementation(BHandlerImpl.class)
+interface BHandler extends EventHandler<BH> {
+}
+
+interface CheckChildIface {
+}
+
+public class TestTang {
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+  Tang tang;
+
+  @Before
+  public void setUp() throws Exception {
+    MustBeSingleton.alreadyInstantiated = false;
+    tang = Tang.Factory.getTang();
+  }
+
+  @Test
+  public void testSingleton() throws InjectionException {
+    Injector injector = tang.newInjector();
+    Assert.assertNotNull(injector.getInstance(TwoSingletons.class));
+    Assert.assertNotNull(injector.getInstance(TwoSingletons.class));
+  }
+
+  @Test
+  public void testNotSingleton() throws InjectionException {
+    thrown.expect(InjectionException.class);
+    thrown.expectMessage("Could not invoke constructor");
+    Assert.assertNotNull(tang.newInjector().getInstance(TwoSingletons.class));
+    tang.newInjector().getInstance(TwoSingletons.class);
+  }
+
+  // TODO: Delete this?  (It is handled in TestClassHierarchy!)
+  @Test(expected = ClassHierarchyException.class)
+  public void testRepeatedAmbiguousArgs() throws BindException, NameResolutionException {
+    JavaConfigurationBuilder t = tang.newConfigurationBuilder();
+    t.getClassHierarchy().getNode(ReflectionUtilities.getFullName(RepeatedAmbiguousArgs.class));
+  }
+
+  @Test
+  public void testRepeatedOKArgs() throws BindException, InjectionException {
+    JavaConfigurationBuilder t = tang.newConfigurationBuilder();
+    t.bindNamedParameter(RepeatedNamedArgs.A.class, "1");
+    t.bindNamedParameter(RepeatedNamedArgs.B.class, "2");
+    Injector injector = tang.newInjector(t.build());
+    injector.getInstance(RepeatedNamedArgs.class);
+  }
+
+  // NamedParameter A has no default_value, so this should throw.
+  @Test
+  public void testOneNamedFailArgs() throws InjectionException {
+    thrown.expect(InjectionException.class);
+    thrown.expectMessage("Cannot inject org.apache.reef.tang.OneNamedSingletonArgs: org.apache.reef.tang.OneNamedSingletonArgs missing argument org.apache.reef.tang.OneNamedSingletonArgs$A");
+    tang.newInjector().getInstance(OneNamedSingletonArgs.class);
+  }
+
+  @Test
+  public void testOneNamedOKArgs() throws InjectionException {
+    thrown.expect(InjectionException.class);
+    thrown.expectMessage("Cannot inject org.apache.reef.tang.OneNamedSingletonArgs: org.apache.reef.tang.OneNamedSingletonArgs missing argument org.apache.reef.tang.OneNamedSingletonArgs$A");
+    tang.newInjector().getInstance(OneNamedSingletonArgs.class);
+  }
+
+  // NamedParameter A has no default_value
+  @Test
+  public void testOneNamedSingletonFailArgs() throws InjectionException {
+    thrown.expect(InjectionException.class);
+    thrown.expectMessage("Cannot inject org.apache.reef.tang.OneNamedSingletonArgs: org.apache.reef.tang.OneNamedSingletonArgs missing argument org.apache.reef.tang.OneNamedSingletonArgs$A");
+    tang.newInjector().getInstance(OneNamedSingletonArgs.class);
+  }
+
+  // NamedParameter A get's bound to a volatile, so this should succeed.
+  @Test
+  public void testOneNamedSingletonOKArgs() throws BindException, InjectionException {
+    final Injector i = tang.newInjector();
+    i.bindVolatileParameter(OneNamedSingletonArgs.A.class,
+        i.getInstance(MustBeSingleton.class));
+    i.getInstance(OneNamedSingletonArgs.class);
+  }
+
+  @Test
+  public void testRepeatedNamedOKArgs() throws BindException,
+      InjectionException {
+    final Injector i = tang.newInjector();
+    i.bindVolatileParameter(RepeatedNamedSingletonArgs.A.class,
+        i.getInstance(MustBeSingleton.class));
+    i.bindVolatileParameter(RepeatedNamedSingletonArgs.B.class,
+        i.getInstance(MustBeSingleton.class));
+    i.getInstance(RepeatedNamedSingletonArgs.class);
+  }
+
+  @Test
+  public void testRepeatedNamedArgs() throws BindException,
+      InjectionException {
+    Injector i = tang.newInjector();
+    i.bindVolatileParameter(RepeatedNamedSingletonArgs.A.class,
+        i.getInstance(MustBeSingleton.class));
+    i.bindVolatileParameter(RepeatedNamedSingletonArgs.B.class,
+        i.getInstance(MustBeSingleton.class));
+    i.getInstance(RepeatedNamedSingletonArgs.class);
+  }
+
+  @Test
+  public void testStraightforwardBuild() throws BindException,
+      InjectionException {
+    JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+    cb.bind(Interf.class, Impl.class);
+    tang.newInjector(cb.build()).getInstance(Interf.class);
+  }
+
+  @Test
+  public void testOneNamedStringArgCantRebind() throws BindException,
+      InjectionException {
+    thrown.expect(BindException.class);
+    thrown.expectMessage("Attempt to re-bind named parameter org.apache.reef.tang.OneNamedStringArg$A.  Old value was [not default] new value is [volatile]");
+    JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+    OneNamedStringArg a = tang.newInjector(cb.build()).getInstance(
+        OneNamedStringArg.class);
+    Assert.assertEquals("default", a.s);
+    cb.bindNamedParameter(OneNamedStringArg.A.class, "not default");
+    Injector i = tang.newInjector(cb.build());
+    Assert
+        .assertEquals("not default", i.getInstance(OneNamedStringArg.class).s);
+    i.bindVolatileParameter(OneNamedStringArg.A.class, "volatile");
+    Assert.assertEquals("volatile", i.getInstance(OneNamedStringArg.class).s);
+  }
+
+  @Test
+  public void testOneNamedStringArgBind() throws BindException,
+      InjectionException {
+    JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+    OneNamedStringArg a = tang.newInjector(cb.build()).getInstance(
+        OneNamedStringArg.class);
+    Assert.assertEquals("default", a.s);
+    cb.bindNamedParameter(OneNamedStringArg.A.class, "not default");
+    Injector i = tang.newInjector(cb.build());
+    Assert
+        .assertEquals("not default", i.getInstance(OneNamedStringArg.class).s);
+  }
+
+  @Test
+  public void testOneNamedStringArgVolatile() throws BindException,
+      InjectionException {
+    OneNamedStringArg a = tang.newInjector().getInstance(
+        OneNamedStringArg.class);
+    Assert.assertEquals("default", a.s);
+    Injector i = tang.newInjector();
+    i.bindVolatileParameter(OneNamedStringArg.A.class, "volatile");
+    Assert.assertEquals("volatile", i.getInstance(OneNamedStringArg.class).s);
+  }
+
+  @Test
+  public void testTwoNamedStringArgsBind() throws BindException,
+      InjectionException {
+    JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+    TwoNamedStringArgs a = tang.newInjector(cb.build()).getInstance(
+        TwoNamedStringArgs.class);
+    Assert.assertEquals("defaultA", a.a);
+    Assert.assertEquals("defaultB", a.b);
+    cb.bindNamedParameter(TwoNamedStringArgs.A.class, "not defaultA");
+    cb.bindNamedParameter(TwoNamedStringArgs.B.class, "not defaultB");
+    Injector i = tang.newInjector(cb.build());
+    Assert.assertEquals("not defaultA",
+        i.getInstance(TwoNamedStringArgs.class).a);
+    Assert.assertEquals("not defaultB",
+        i.getInstance(TwoNamedStringArgs.class).b);
+  }
+
+  @Test
+  public void testTwoNamedStringArgsBindVolatile() throws BindException,
+      InjectionException {
+    JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+    TwoNamedStringArgs a = tang.newInjector(cb.build()).getInstance(
+        TwoNamedStringArgs.class);
+    Assert.assertEquals("defaultA", a.a);
+    Assert.assertEquals("defaultB", a.b);
+    final Injector i = tang.newInjector(cb.build());
+    i.bindVolatileParameter(TwoNamedStringArgs.A.class, "not defaultA");
+    i.bindVolatileParameter(TwoNamedStringArgs.B.class, "not defaultB");
+    Assert.assertEquals("not defaultA",
+        i.getInstance(TwoNamedStringArgs.class).a);
+    Assert.assertEquals("not defaultB",
+        i.getInstance(TwoNamedStringArgs.class).b);
+
+  }
+
+  @Test//(expected = BindException.class)
+  public void testTwoNamedStringArgsReBindVolatileFail() throws BindException,
+      InjectionException {
+    thrown.expect(BindException.class);
+    thrown.expectMessage("Attempt to re-bind named parameter org.apache.reef.tang.TwoNamedStringArgs$A.  Old value was [not defaultA] new value is [not defaultA]");
+    JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+    TwoNamedStringArgs a = tang.newInjector(cb.build()).getInstance(
+        TwoNamedStringArgs.class);
+    Assert.assertEquals("defaultA", a.a);
+    Assert.assertEquals("defaultB", a.b);
+    cb.bindNamedParameter(TwoNamedStringArgs.A.class, "not defaultA");
+    cb.bindNamedParameter(TwoNamedStringArgs.B.class, "not defaultB");
+    Injector i = tang.newInjector(cb.build());
+    i.bindVolatileParameter(TwoNamedStringArgs.A.class, "not defaultA");
+    i.bindVolatileParameter(TwoNamedStringArgs.B.class, "not defaultB");
+  }
+
+  @Test
+  public void testBextendsAinjectA() throws BindException, InjectionException {
+    JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+    cb.bind(BextendsAinjectA.A.class, BextendsAinjectA.A.class);
+    tang.newInjector(cb.build()).getInstance(BextendsAinjectA.A.class);
+  }
+
+  @Test
+  public void testExternalConstructor() throws BindException,
+      InjectionException {
+    JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+    cb.bindConstructor(ExternalConstructorExample.Legacy.class,
+        ExternalConstructorExample.LegacyWrapper.class);
+    Injector i = tang.newInjector(cb.build());
+    i.bindVolatileInstance(Integer.class, 42);
+    i.bindVolatileInstance(String.class, "The meaning of life is ");
+    ExternalConstructorExample.Legacy l = i
+        .getInstance(ExternalConstructorExample.Legacy.class);
+    Assert.assertEquals(new Integer(42), l.x);
+    Assert.assertEquals("The meaning of life is ", l.y);
+
+  }
+
+  @Test
+  public void testLegacyConstructor() throws BindException, InjectionException {
+    JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+    cb.registerLegacyConstructor(
+        ReflectionUtilities.getFullName(LegacyConstructor.class),
+        ReflectionUtilities.getFullName(Integer.class),
+        ReflectionUtilities.getFullName(String.class));
+    cb.bind(LegacyConstructor.class, LegacyConstructor.class);
+    String confString = ConfigurationFile.toConfigurationString(cb.build());
+    JavaConfigurationBuilder cb2 = tang.newConfigurationBuilder();
+    // System.err.println(confString);
+    ConfigurationFile.addConfiguration(cb2, confString);
+    Injector i = tang.newInjector(cb2.build());
+    i.bindVolatileInstance(Integer.class, 42);
+    i.bindVolatileInstance(String.class, "The meaning of life is ");
+    LegacyConstructor l = i.getInstance(LegacyConstructor.class);
+    Assert.assertEquals(new Integer(42), l.x);
+    Assert.assertEquals("The meaning of life is ", l.y);
+
+  }
+
+  @Test
+  public void testNamedImpl() throws BindException, InjectionException {
+    JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+    cb.bindNamedParameter(NamedImpl.AImplName.class, NamedImpl.Aimpl.class);
+    cb.bindNamedParameter(NamedImpl.BImplName.class, NamedImpl.Bimpl.class);
+    Injector i = tang.newInjector(cb.build());
+    NamedImpl.Aimpl a1 = (NamedImpl.Aimpl) i
+        .getNamedInstance(NamedImpl.AImplName.class);
+    NamedImpl.Aimpl a2 = (NamedImpl.Aimpl) i
+        .getNamedInstance(NamedImpl.AImplName.class);
+    NamedImpl.Bimpl b1 = (NamedImpl.Bimpl) i
+        .getNamedInstance(NamedImpl.BImplName.class);
+    NamedImpl.Bimpl b2 = (NamedImpl.Bimpl) i
+        .getNamedInstance(NamedImpl.BImplName.class);
+    Assert.assertSame(a1, a2);
+    Assert.assertSame(b1, b2);
+  }
+
+  @SuppressWarnings({"rawtypes", "unchecked"})
+  @Test
+  public void testWrongNamedImpl() throws BindException {
+    thrown.expect(BindException.class);
+    thrown.expectMessage("Name<org.apache.reef.tang.NamedImpl$A> org.apache.reef.tang.NamedImpl$AImplName cannot take non-subclass org.apache.reef.tang.NamedImpl$Cimpl");
+    JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+    cb.bindNamedParameter((Class) NamedImpl.AImplName.class, (Class) NamedImpl.Cimpl.class);
+  }
+
+  @Test
+  public void testUnit() throws BindException, InjectionException {
+    Injector inj = tang.newInjector();
+    OuterUnit.InA a = inj.getInstance(OuterUnit.InA.class);
+    OuterUnit.InB b = inj.getInstance(OuterUnit.InB.class);
+    Assert.assertEquals(a.slf, b.slf);
+  }
+
+  @Test
+  public void testMissedUnit() throws BindException, InjectionException {
+    thrown.expect(InjectionException.class);
+    thrown.expectMessage("Cannot inject org.apache.reef.tang.MissOuterUnit$InA: No known implementations / injectable constructors for org.apache.reef.tang.MissOuterUnit$InA");
+    Injector inj = tang.newInjector();
+    MissOuterUnit.InA a = inj.getInstance(MissOuterUnit.InA.class);
+  }
+
+  @Test
+  public void testMissedUnitButWithInjectInnerClass() throws BindException, InjectionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("Cannot @Inject non-static member class unless the enclosing class an @Unit.  Nested class is:org.apache.reef.tang.MissOuterUnit$InB");
+    Injector inj = tang.newInjector();
+    MissOuterUnit.InB b = inj.getInstance(MissOuterUnit.InB.class);
+  }
+
+  @Test
+  public void testThreeConstructors() throws BindException, InjectionException {
+    JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+    cb.bindNamedParameter(TCInt.class, "1");
+    cb.bindNamedParameter(TCString.class, "s");
+    ThreeConstructors tc = tang.newInjector(cb.build()).getInstance(ThreeConstructors.class);
+    Assert.assertEquals(1, tc.i);
+    Assert.assertEquals("s", tc.s);
+
+    cb = tang.newConfigurationBuilder();
+    cb.bindNamedParameter(TCInt.class, "1");
+    tc = tang.newInjector(cb.build()).getInstance(ThreeConstructors.class);
+    Assert.assertEquals(1, tc.i);
+    Assert.assertEquals("default", tc.s);
+
+    cb = tang.newConfigurationBuilder();
+    cb.bindNamedParameter(TCString.class, "s");
+    tc = tang.newInjector(cb.build()).getInstance(ThreeConstructors.class);
+    Assert.assertEquals(-1, tc.i);
+    Assert.assertEquals("s", tc.s);
+
+    cb = tang.newConfigurationBuilder();
+    cb.bindNamedParameter(TCFloat.class, "2");
+    tc = tang.newInjector(cb.build()).getInstance(ThreeConstructors.class);
+    Assert.assertEquals(-1, tc.i);
+    Assert.assertEquals("default", tc.s);
+    Assert.assertEquals(2.0f, tc.f, 1e-9);
+  }
+
+  @Test
+  public void testThreeConstructorsAmbiguous() throws BindException, InjectionException {
+    thrown.expect(InjectionException.class);
+    thrown.expectMessage("Cannot inject org.apache.reef.tang.ThreeConstructors Ambigous subplan org.apache.reef.tang.ThreeConstructors");
+//    thrown.expectMessage("Cannot inject org.apache.reef.tang.ThreeConstructors Multiple ways to inject org.apache.reef.tang.ThreeConstructors");
+
+    final JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+    cb.bindNamedParameter(TCString.class, "s");
+    cb.bindNamedParameter(TCFloat.class, "-2");
+
+    // Ambiguous; there is a constructor that takes a string, and another that
+    // takes a float, but none that takes both.
+    tang.newInjector(cb.build()).getInstance(ThreeConstructors.class);
+  }
+
+  @Test
+  public void testTwoConstructorsAmbiguous() throws BindException, InjectionException {
+    thrown.expect(InjectionException.class);
+    thrown.expectMessage("Cannot inject org.apache.reef.tang.TwoConstructors: Multiple infeasible plans: org.apache.reef.tang.TwoConstructors:");
+    final JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+    cb.bindNamedParameter(TCString.class, "s");
+    cb.bindNamedParameter(TCInt.class, "1");
+
+    tang.newInjector(cb.build()).getInstance(TwoConstructors.class);
+  }
+
+  @Test
+  public void testDefaultImplementation() throws BindException, ClassHierarchyException, InjectionException {
+    ConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    Injector i = Tang.Factory.getTang().newInjector(cb.build());
+    @SuppressWarnings("unused")
+    IfaceWithDefault iwd = i.getNamedInstance(IfaceWithDefaultName.class);
+  }
+
+  @Test
+  public void testCantGetInstanceOfNamedParameter() throws BindException, InjectionException {
+    thrown.expect(InjectionException.class);
+    thrown.expectMessage("getInstance() called on Name org.apache.reef.tang.IfaceWithDefaultName Did you mean to call getNamedInstance() instead?");
+    ConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    Injector i = Tang.Factory.getTang().newInjector(cb.build());
+    @SuppressWarnings("unused")
+    IfaceWithDefaultName iwd = i.getInstance(IfaceWithDefaultName.class);
+  }
+
+  @Test
+  public void testCanGetDefaultedInterface() throws BindException, InjectionException {
+    Assert.assertNotNull(Tang.Factory.getTang().newInjector().getInstance(HaveDefaultImpl.class));
+  }
+
+  @Test
+  public void testCanOverrideDefaultedInterface() throws BindException, InjectionException {
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindImplementation(HaveDefaultImpl.class, OverrideDefaultImpl.class);
+    Assert.assertTrue(Tang.Factory.getTang().newInjector(cb.build())
+        .getInstance(HaveDefaultImpl.class) instanceof OverrideDefaultImpl);
+  }
+
+  @Test
+  public void testCanGetStringDefaultedInterface() throws BindException, InjectionException {
+    Assert.assertNotNull(Tang.Factory.getTang().newInjector().getInstance(HaveDefaultStringImpl.class));
+  }
+
+  @Test
+  public void testCanOverrideStringDefaultedInterface() throws BindException, InjectionException {
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindImplementation(HaveDefaultStringImpl.class, OverrideDefaultStringImpl.class);
+    Assert.assertTrue(Tang.Factory.getTang().newInjector(cb.build())
+        .getInstance(HaveDefaultStringImpl.class) instanceof OverrideDefaultStringImpl);
+  }
+
+  @Test
+  public void testSingletonWithMultipleConstructors() throws BindException, InjectionException {
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindImplementation(SMC.class, SingletonMultiConst.class);
+    cb.bindNamedParameter(SingletonMultiConst.A.class, "foo");
+    Injector i = Tang.Factory.getTang().newInjector(cb.build());
+    i.getInstance(SMC.class);
+  }
+
+  @Test
+  public void testInjectInjector() throws InjectionException, BindException {
+    Injector i = Tang.Factory.getTang().newInjector();
+    InjectInjector ii = i.getInstance(InjectInjector.class);
+    Assert.assertSame(i, ii.i);
+  }
+
+  @Test
+  public void testProactiveFutures() throws InjectionException, BindException {
+    Injector i = Tang.Factory.getTang().newInjector();
+    IsFuture.instantiated = false;
+    i.getInstance(NeedsFuture.class);
+    Assert.assertTrue(IsFuture.instantiated);
+  }
+
+  @SuppressWarnings({"unchecked", "rawtypes"})
+  @Test
+  public void testGenericEventHandlers() throws BindException, InjectionException {
+    JavaConfigurationBuilder cba = Tang.Factory.getTang().newConfigurationBuilder();
+    cba.bindNamedParameter(XName.class, (Class) XAA.class);
+    Tang.Factory.getTang().newInjector(cba.build()).getNamedInstance(XName.class);
+    JavaConfigurationBuilder cbb = Tang.Factory.getTang().newConfigurationBuilder();
+    cbb.bindNamedParameter(XName.class, XBB.class);
+    Tang.Factory.getTang().newInjector(cbb.build()).getNamedInstance(XName.class);
+    JavaConfigurationBuilder cbc = Tang.Factory.getTang().newConfigurationBuilder();
+    cbc.bindNamedParameter(XName.class, (Class) XCC.class);
+    Tang.Factory.getTang().newInjector(cbc.build()).getNamedInstance(XName.class);
+  }
+
+  @Test
+  public void testGenericEventHandlerDefaults() throws BindException, InjectionException {
+    JavaConfigurationBuilder cba = Tang.Factory.getTang().newConfigurationBuilder();
+    Tang.Factory.getTang().newInjector(cba.build()).getNamedInstance(XNameDA.class);
+    JavaConfigurationBuilder cbb = Tang.Factory.getTang().newConfigurationBuilder();
+    Tang.Factory.getTang().newInjector(cbb.build()).getNamedInstance(XNameDB.class);
+    JavaConfigurationBuilder cbc = Tang.Factory.getTang().newConfigurationBuilder();
+    Tang.Factory.getTang().newInjector(cbc.build()).getNamedInstance(XNameDC.class);
+  }
+
+  @Test
+  public void testGenericEventHandlerDefaultsBadTreeIndirection() throws BindException, InjectionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("class org.apache.reef.tang.XNameDAA defines a default class org.apache.reef.tang.XCC with a raw type that does not extend of its target's raw type class org.apache.reef.tang.XBB");
+
+    JavaConfigurationBuilder cba = Tang.Factory.getTang().newConfigurationBuilder();
+    Tang.Factory.getTang().newInjector(cba.build()).getNamedInstance(XNameDAA.class);
+  }
+
+  @Test
+  public void testGenericEventHandlerDefaultsGoodTreeIndirection() throws BindException, InjectionException {
+    JavaConfigurationBuilder cba = Tang.Factory.getTang().newConfigurationBuilder();
+    Tang.Factory.getTang().newInjector(cba.build()).getNamedInstance(XNameDDAA.class);
+  }
+
+  @Test
+  public void testGenericUnrelatedGenericTypeParameters() throws BindException, InjectionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("class org.apache.reef.tang.WaterBottleName defines a default class org.apache.reef.tang.GasCan with a type that does not extend its target's type org.apache.reef.tang.Bottle<org.apache.reef.tang.Water");
+
+    JavaConfigurationBuilder cba = Tang.Factory.getTang().newConfigurationBuilder();
+    Tang.Factory.getTang().newInjector(cba.build()).getNamedInstance(WaterBottleName.class);
+  }
+
+  @Test
+  public void testGenericInterfaceUnboundTypeParametersName() throws BindException, InjectionException {
+    JavaConfigurationBuilder cba = Tang.Factory.getTang().newConfigurationBuilder();
+    Tang.Factory.getTang().newInjector(cba.build()).getNamedInstance(FooEventHandler.class);
+  }
+
+  @Test
+  public void testGenericInterfaceUnboundTypeParametersNameIface() throws BindException, InjectionException {
+    JavaConfigurationBuilder cba = Tang.Factory.getTang().newConfigurationBuilder();
+    Tang.Factory.getTang().newInjector(cba.build()).getNamedInstance(IfaceEventHandler.class);
+  }
+
+  @Test
+  public void testGenericInterfaceUnboundTypeParametersIface() throws BindException, InjectionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("interface org.apache.reef.tang.MyEventHandlerIface declares its default implementation to be non-subclass class org.apache.reef.tang.MyEventHandler");
+
+    JavaConfigurationBuilder cba = Tang.Factory.getTang().newConfigurationBuilder();
+    Tang.Factory.getTang().newInjector(cba.build()).isInjectable(MyEventHandlerIface.class);
+  }
+
+  @Test
+  public void testWantSomeHandlers() throws BindException, InjectionException {
+    Tang.Factory.getTang().newInjector().getInstance(WantSomeHandlers.class);
+  }
+
+  @Test
+  public void testWantSomeHandlersBadOrder() throws BindException, InjectionException {
+    Injector i = Tang.Factory.getTang().newInjector();
+    i.getInstance(AHandler.class);
+    i.getInstance(BHandler.class);
+    i.getInstance(WantSomeFutureHandlers.class);
+  }
+
+  @Test
+  public void testWantSomeFutureHandlersAlreadyBoundVolatile() throws BindException, InjectionException {
+    Injector i = Tang.Factory.getTang().newInjector();
+    i.bindVolatileInstance(AHandler.class, new AHandlerImpl());
+    i.bindVolatileInstance(BHandler.class, new BHandlerImpl());
+    i.getInstance(WantSomeFutureHandlers.class);
+  }
+
+  @Test
+  public void testWantSomeFutureHandlers() throws BindException, InjectionException {
+    Tang.Factory.getTang().newInjector().getInstance(WantSomeFutureHandlers.class);
+  }
+
+  @Test
+  public void testWantSomeFutureHandlersUnit() throws BindException, InjectionException {
+    Tang.Factory.getTang().newInjector().getInstance(WantSomeFutureHandlersUnit.class);
+  }
+
+  @Test
+  public void testWantSomeFutureHandlersName() throws BindException, InjectionException {
+    Tang.Factory.getTang().newInjector().getInstance(WantSomeFutureHandlersName.class);
+  }
+
+  @Test
+  public void testUnitMixedCanInject() throws BindException, InjectionException {
+    //testing that you should be able to have @Unit and also static inner classes not included
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    Injector i = Tang.Factory.getTang().newInjector(cb.build());
+
+    i.getInstance(OuterUnitWithStatic.InnerStaticClass2.class);
+  }
+
+  @Test
+  public void testUnitMixedCantInject() throws BindException, InjectionException {
+    thrown.expect(InjectionException.class);
+    thrown.expectMessage("Cannot inject org.apache.reef.tang.OuterUnitWithStatic$InnerStaticClass: No known implementations / injectable constructors for org.apache.reef.tang.OuterUnitWithStatic$InnerStaticClass");
+
+    //testing that you should be able to have @Unit and also static inner classes not included
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    Injector i = Tang.Factory.getTang().newInjector(cb.build());
+
+    i.getInstance(OuterUnitWithStatic.InnerStaticClass.class);
+  }
+
+  @Test
+  public void testForkWorks() throws BindException, InjectionException {
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bind(CheckChildIface.class, CheckChildImpl.class);
+
+    Injector i = Tang.Factory.getTang().newInjector(cb.build());
+    Injector i1 = i.forkInjector();
+    CheckChildIface c1 = i1.getInstance(CheckChildIface.class);
+    Injector i2 = i.forkInjector();
+    CheckChildIface c2 = i2.getInstance(CheckChildIface.class);
+    Assert.assertTrue(c1 != c2);
+  }
+
+  @Test
+  public void testReuseFailedInjector() throws BindException, InjectionException {
+    Injector i = Tang.Factory.getTang().newInjector();
+    try {
+      i.getInstance(Fail.class);
+      Assert.fail("Injecting Fail should not have worked!");
+    } catch (InjectionException e) {
+      i.getInstance(Pass.class);
+    }
+  }
+
+  @Test
+  public void testForksInjectorInConstructor() throws BindException, InjectionException {
+    Injector i = Tang.Factory.getTang().newInjector();
+    i.getInstance(ForksInjectorInConstructor.class);
+  }
+
+  /**
+   * This is to test multiple inheritance case.
+   * When a subclass is bound to an interface, it's instance will be created in injection
+   * When a subsubclass is bound to the interface, the subsubclass instance will be created in injection
+   *
+   * @throws BindException
+   * @throws InjectionException
+   */
+  @Test
+  public void testMultiInheritanceMiddleClassFirst() throws BindException, InjectionException {
+    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindImplementation(CheckChildIface.class, CheckChildImpl.class);
+    final Injector i = Tang.Factory.getTang().newInjector(cb.build());
+    final CheckChildIface o1 = i.getInstance(CheckChildIface.class);
+    Assert.assertTrue(o1 instanceof CheckChildImpl);
+
+    final JavaConfigurationBuilder cb2 = Tang.Factory.getTang().newConfigurationBuilder();
+    cb2.bindImplementation(CheckChildIface.class, CheckChildImplImpl.class);
+    final Injector i2 = Tang.Factory.getTang().newInjector(cb2.build());
+    final CheckChildIface o2 = i2.getInstance(CheckChildIface.class);
+    Assert.assertTrue(o2 instanceof CheckChildImplImpl);
+  }
+
+  /**
+   * This is to test multiple inheritance case.
+   * When CheckChildImplImpl is bound to an interface, the CheckChildImplImpl instance will be created in injection
+   * When CheckChildImpl is then bound to the same interface, even class hierarchy already knows it has an subclass CheckChildImplImpl,
+   * Tang will only look at the constructors in CheckChildImpl
+   *
+   * @throws BindException
+   * @throws InjectionException
+   */
+  @Test
+  public void testMultiInheritanceSubclassFirst() throws BindException, InjectionException {
+    final JavaConfigurationBuilder cb2 = Tang.Factory.getTang().newConfigurationBuilder();
+    cb2.bindImplementation(CheckChildIface.class, CheckChildImplImpl.class);
+    final Injector i2 = Tang.Factory.getTang().newInjector(cb2.build());
+    final CheckChildIface o2 = i2.getInstance(CheckChildIface.class);
+    Assert.assertTrue(o2 instanceof CheckChildImplImpl);
+
+    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindImplementation(CheckChildIface.class, CheckChildImpl.class);
+    final Injector i = Tang.Factory.getTang().newInjector(cb.build());
+    final CheckChildIface o1 = i.getInstance(CheckChildIface.class);
+    Assert.assertTrue(o1 instanceof CheckChildImpl);
+  }
+}
+
+class Fail {
+  @Inject
+  public Fail() {
+    throw new UnsupportedOperationException();
+  }
+}
+
+class Pass {
+  @Inject
+  public Pass() {
+  }
+}
+
+class IsFuture {
+  static boolean instantiated;
+
+  @Inject
+  IsFuture(NeedsFuture nf) {
+    instantiated = true;
+  }
+}
+
+class NeedsFuture {
+  @Inject
+  NeedsFuture(InjectionFuture<IsFuture> isFut) {
+  }
+}
+
+class InjectInjector {
+  public final Injector i;
+
+  @Inject
+  InjectInjector(Injector i) {
+    this.i = i;
+  }
+}
+
+class SingletonMultiConst implements SMC {
+  @Inject
+  public SingletonMultiConst(@Parameter(A.class) String a) {
+  }
+
+  @Inject
+  public SingletonMultiConst(@Parameter(A.class) String a, @Parameter(B.class) String b) {
+  }
+
+  @NamedParameter
+  class A implements Name<String> {
+  }
+
+  @NamedParameter
+  class B implements Name<String> {
+  }
+}
+
+class HaveDefaultImplImpl implements HaveDefaultImpl {
+  @Inject
+  HaveDefaultImplImpl() {
+  }
+}
+
+class OverrideDefaultImpl implements HaveDefaultImpl {
+  @Inject
+  public OverrideDefaultImpl() {
+  }
+}
+
+class HaveDefaultStringImplImpl implements HaveDefaultStringImpl {
+  @Inject
+  HaveDefaultStringImplImpl() {
+  }
+}
+
+class OverrideDefaultStringImpl implements HaveDefaultStringImpl {
+  @Inject
+  public OverrideDefaultStringImpl() {
+  }
+}
+
+@NamedParameter(doc = "woo", short_name = "woo", default_value = "42")
+class Param implements Name<Integer> {
+}
+
+class Impl implements Interf {
+  @Inject
+  Impl(@Parameter(Param.class) int p) {
+  }
+}
+
+class MustBeSingleton {
+  static boolean alreadyInstantiated;
+
+  @Inject
+  public MustBeSingleton() {
+    if (alreadyInstantiated) {
+      throw new IllegalStateException("Can't instantiate me twice!");
+    }
+    alreadyInstantiated = true;
+  }
+}
+
+class SubSingleton {
+  @Inject
+  SubSingleton(MustBeSingleton a) {
+    // Does not call super
+  }
+}
+
+class TwoSingletons {
+  @Inject
+  TwoSingletons(SubSingleton a, MustBeSingleton b) {
+  }
+}
+
+class RepeatedAmbiguousArgs {
+  @Inject
+  RepeatedAmbiguousArgs(int x, int y) {
+  }
+}
+
+class RepeatedNamedArgs {
+  @Inject
+  RepeatedNamedArgs(@Parameter(A.class) int x, @Parameter(B.class) int y) {
+  }
+
+  @NamedParameter()
+  class A implements Name<Integer> {
+  }
+
+  @NamedParameter()
+  class B implements Name<Integer> {
+  }
+}
+
+class RepeatedNamedSingletonArgs {
+  @Inject
+  RepeatedNamedSingletonArgs(@Parameter(A.class) MustBeSingleton a,
+                             @Parameter(B.class) MustBeSingleton b) {
+  }
+
+  @NamedParameter()
+  class A implements Name<MustBeSingleton> {
+  }
+
+  @NamedParameter()
+  class B implements Name<MustBeSingleton> {
+  }
+}
+
+class OneNamedSingletonArgs {
+  @Inject
+  OneNamedSingletonArgs(@Parameter(A.class) MustBeSingleton a) {
+  }
+
+  @NamedParameter()
+  class A implements Name<MustBeSingleton> {
+  }
+
+  @NamedParameter()
+  class B implements Name<MustBeSingleton> {
+  }
+}
+
+class OneNamedStringArg {
+  public final String s;
+
+  @Inject
+  OneNamedStringArg(@Parameter(A.class) String s) {
+    this.s = s;
+  }
+
+  @NamedParameter(default_value = "default")
+  class A implements Name<String> {
+  }
+}
+
+class TwoNamedStringArgs {
+  public final String a;
+  public final String b;
+
+  @Inject
+  TwoNamedStringArgs(@Parameter(A.class) String a, @Parameter(B.class) String b) {
+    this.a = a;
+    this.b = b;
+  }
+
+  @NamedParameter(default_value = "defaultA")
+  class A implements Name<String> {
+  }
+
+  @NamedParameter(default_value = "defaultB")
+  class B implements Name<String> {
+  }
+}
+
+class BextendsAinjectA {
+  static class A {
+    @Inject
+    A() {
+    }
+  }
+
+  static class B extends A {
+  }
+}
+
+class ExternalConstructorExample {
+  static class LegacyWrapper implements ExternalConstructor<Legacy> {
+    final Integer x;
+    final String y;
+
+    @Inject
+    LegacyWrapper(Integer x, String y) {
+      this.x = x;
+      this.y = y;
+    }
+
+    @Override
+    public Legacy newInstance() {
+      return new ExternalConstructorExample().new Legacy(x, y);
+    }
+
+  }
+
+  class Legacy {
+    final Integer x;
+    final String y;
+
+    public Legacy(Integer x, String y) {
+      this.x = x;
+      this.y = y;
+    }
+  }
+}
+
+class LegacyConstructor {
+  final Integer x;
+  final String y;
+
+  public LegacyConstructor(Integer x, String y) {
+    this.x = x;
+    this.y = y;
+  }
+}
+
+class NamedImpl {
+  static interface A {
+  }
+
+  static interface C {
+
+  }
+
+  @NamedParameter
+  static class AImplName implements Name<A> {
+  }
+
+  @NamedParameter
+  static class BImplName implements Name<A> {
+  }
+
+  @NamedParameter
+  static class CImplName implements Name<C> {
+  }
+
+  static class Aimpl implements A {
+    @Inject
+    Aimpl() {
+    }
+  }
+
+  static class Bimpl implements A {
+    @Inject
+    Bimpl() {
+    }
+  }
+
+  static class Cimpl implements C {
+    @Inject
+    Cimpl() {
+    }
+  }
+
+  static class ABtaker {
+    @Inject
+    ABtaker(@Parameter(AImplName.class) A a, @Parameter(BImplName.class) A b) {
+      Assert.assertTrue("AImplName must be instance of Aimpl",
+          a instanceof Aimpl);
+      Assert.assertTrue("BImplName must be instance of Bimpl",
+          b instanceof Bimpl);
+    }
+  }
+}
+
+@Unit
+class OuterUnit {
+
+  final OuterUnit self;
+
+  @Inject
+  OuterUnit() {
+    self = this;
+  }
+
+  class InA {
+    OuterUnit slf = self;
+  }
+
+  class InB {
+    OuterUnit slf = self;
+  }
+}
+
+class MissOuterUnit {
+
+  final MissOuterUnit self;
+
+  @Inject
+  MissOuterUnit() {
+    self = this;
+  }
+
+  class InA {
+    MissOuterUnit slf = self;
+  }
+
+  class InB {
+    MissOuterUnit slf = self;
+
+    @Inject
+    InB() {
+    }
+  }
+}
+
+class ThreeConstructors {
+
+  final int i;
+  final String s;
+  final Float f;
+
+  @Inject
+  ThreeConstructors(@Parameter(TCInt.class) int i, @Parameter(TCString.class) String s) {
+    this.i = i;
+    this.s = s;
+    this.f = -1.0f;
+  }
+
+  @Inject
+  ThreeConstructors(@Parameter(TCString.class) String s) {
+    this(-1, s);
+  }
+
+  @Inject
+  ThreeConstructors(@Parameter(TCInt.class) int i) {
+    this(i, "default");
+  }
+
+  @Inject
+  ThreeConstructors(@Parameter(TCFloat.class) float f) {
+    this.i = -1;
+    this.s = "default";
+    this.f = f;
+  }
+
+  @NamedParameter
+  static class TCInt implements Name<Integer> {
+  }
+
+  @NamedParameter
+  static class TCString implements Name<String> {
+  }
+
+  @NamedParameter
+  static class TCFloat implements Name<Float> {
+  }
+}
+
+class TwoConstructors {
+
+  final int i;
+  final String s;
+
+  @Inject
+  TwoConstructors(@Parameter(TCInt.class) int i, @Parameter(TCString.class) String s) {
+    this.i = i;
+    this.s = s;
+  }
+
+  @Inject
+  TwoConstructors(@Parameter(TCString.class) String s, @Parameter(TCInt.class) int i) {
+    this.i = i;
+    this.s = s;
+  }
+
+  @NamedParameter
+  static class TCInt implements Name<Integer> {
+  }
+
+  @NamedParameter
+  static class TCString implements Name<String> {
+  }
+}
+
+class IfaceWithDefaultDefaultImpl implements IfaceWithDefault {
+  @Inject
+  IfaceWithDefaultDefaultImpl() {
+  }
+}
+
+@NamedParameter(default_class = IfaceWithDefaultDefaultImpl.class)
+class IfaceWithDefaultName implements Name<IfaceWithDefault> {
+}
+
+@NamedParameter
+class XName implements Name<X<BB>> {
+}
+
+@NamedParameter(default_class = XAA.class)
+class XNameDA implements Name<X<BB>> {
+}
+
+@NamedParameter(default_class = XBB.class)
+class XNameDB implements Name<X<BB>> {
+}
+
+@NamedParameter(default_class = XCC.class)
+class XNameDC implements Name<X<BB>> {
+}
+
+@NamedParameter(default_class = XCC.class)
+class XNameDAA implements Name<XBB> {
+}
+
+@NamedParameter(default_class = XXBB.class)
+class XNameDDAA implements Name<XBB> {
+}
+
+@DefaultImplementation(AA.class)
+class AA {
+  @Inject
+  AA() {
+  }
+}
+
+@DefaultImplementation(BB.class)
+class BB extends AA {
+  @Inject
+  BB() {
+  }
+}
+
+@DefaultImplementation(CC.class)
+class CC extends BB {
+  @Inject
+  CC() {
+  }
+}
+
+class XAA implements X<AA> {
+  @Inject
+  XAA(AA aa) {
+  }
+}
+
+@DefaultImplementation(XBB.class)
+class XBB implements X<BB> {
+  @Inject
+  XBB(BB aa) {
+  }
+}
+
+class XXBB extends XBB {
+  @Inject
+  XXBB(BB aa) {
+    super(aa);
+  }
+}
+
+class XCC implements X<CC> {
+  @Inject
+  XCC(CC aa) {
+  }
+}
+
+class WaterBottle implements Bottle<Water> {
+
+}
+
+class GasCan implements Bottle<Gas> {
+
+}
+
+class Water {
+}
+
+class Gas {
+}
+
+@NamedParameter(default_class = GasCan.class)
+class WaterBottleName implements Name<Bottle<Water>> {
+}
+
+class MyEventHandler<T> implements EventHandler<T> {
+  @Inject
+  MyEventHandler() {
+  }
+}
+
+@NamedParameter(default_class = MyEventHandler.class)
+class FooEventHandler implements Name<EventHandler<Foo>> {
+}
+
+@NamedParameter(default_class = MyEventHandler.class)
+class IfaceEventHandler implements Name<EventHandler<SomeIface>> {
+}
+
+class AH {
+  @Inject
+  AH() {
+  }
+}
+
+class BH {
+  @Inject
+  BH() {
+  }
+}
+
+class AHandlerImpl implements AHandler {
+  @Inject
+  AHandlerImpl() {
+  }
+}
+
+class BHandlerImpl implements BHandler {
+  @Inject
+  BHandlerImpl() {
+  }
+}
+
+@Unit
+class DefaultHandlerUnit {
+  @Inject
+  DefaultHandlerUnit() {
+  }
+
+  @DefaultImplementation(AHandlerImpl.class)
+  interface AHandler extends EventHandler<AH> {
+  }
+
+  @DefaultImplementation(BHandlerImpl.class)
+  interface BHandler extends EventHandler<BH> {
+  }
+
+  class AHandlerImpl implements AHandler {
+    AHandlerImpl() {
+    }
+  }
+
+  class BHandlerImpl implements BHandler {
+    BHandlerImpl() {
+    }
+  }
+}
+
+class WantSomeHandlers {
+  @Inject
+  WantSomeHandlers(AHandler a, BHandler b) {
+  }
+}
+
+class WantSomeFutureHandlers {
+  @Inject
+  WantSomeFutureHandlers(InjectionFuture<AHandler> a, InjectionFuture<BHandler> b) {
+  }
+}
+
+class WantSomeFutureHandlersUnit {
+  @Inject
+  WantSomeFutureHandlersUnit(InjectionFuture<DefaultHandlerUnit.AHandler> a, InjectionFuture<DefaultHandlerUnit.BHandler> b) {
+  }
+}
+
+@NamedParameter(default_class = AHandlerImpl.class)
+class AHandlerName implements Name<EventHandler<AH>> {
+}
+
+@NamedParameter(default_class = BHandlerImpl.class)
+class BHandlerName implements Name<EventHandler<BH>> {
+}
+
+class WantSomeFutureHandlersName {
+  @Inject
+  WantSomeFutureHandlersName(
+      @Parameter(AHandlerName.class) InjectionFuture<EventHandler<AH>> a,
+      @Parameter(BHandlerName.class) InjectionFuture<EventHandler<BH>> b) {
+  }
+}
+
+@Unit
+class OuterUnitWithStatic {
+
+  @Inject
+  public OuterUnitWithStatic() {
+  }
+
+  public void bar() {
+    new InnerStaticClass().baz();
+  }
+
+  static class InnerStaticClass {
+    public InnerStaticClass() {
+    }
+
+    public void baz() {
+    }
+  }
+
+  static class InnerStaticClass2 {
+    @Inject
+    public InnerStaticClass2() {
+    }
+
+    public void baz() {
+    }
+  }
+
+  public class InnerUnitClass {
+    public void foo() {
+    }
+  }
+}
+
+class CheckChildImpl implements CheckChildIface {
+  @Inject
+  CheckChildImpl() {
+  }
+}
+
+class CheckChildImplImpl extends CheckChildImpl {
+  @Inject
+  CheckChildImplImpl() {
+  }
+}
+
+class ForksInjectorInConstructor {
+  @Inject
+  ForksInjectorInConstructor(Injector i) throws BindException {
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindImplementation(Number.class, Integer.class);
+    i.forkInjector(cb.build());
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestTweetExample.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestTweetExample.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestTweetExample.java
new file mode 100644
index 0000000..09ba8b4
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/TestTweetExample.java
@@ -0,0 +1,120 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.RequiredParameter;
+import org.junit.*;
+
+import javax.inject.Inject;
+
+public class TestTweetExample {
+  Tang tang;
+
+  @BeforeClass
+  public static void setUpBeforeClass() throws Exception {
+  }
+
+  @AfterClass
+  public static void tearDownAfterClass() throws Exception {
+  }
+
+  @Before
+  public void setUp() throws Exception {
+    tang = Tang.Factory.getTang();
+  }
+
+  @After
+  public void tearDown() throws Exception {
+  }
+
+  @Test
+  public void test() throws Exception {
+    Tweeter tw = (Tweeter) tang.newInjector(TweetConfig.CONF.set(TweetConfig.PHONE_NUMBER, new Long(867 - 5309)).build()).getInstance(Tweeter.class);
+    tw.sendMessage();
+  }
+
+  static interface TweetFactory {
+    public String getTweet();
+  }
+
+  static interface SMS {
+    public void sendSMS(String msg, long phoneNumber);
+  }
+
+  static class MockTweetFactory implements TweetFactory {
+    @Inject
+    public MockTweetFactory() {
+    }
+
+    @Override
+    public String getTweet() {
+      return "@tw #bbq bbqftw!!! gopher://vuwed.wefd/bbqftw!";
+    }
+  }
+
+  static class MockSMS implements SMS {
+    @Inject
+    public MockSMS() {
+    }
+
+    @Override
+    public void sendSMS(String msg, long phoneNumber) {
+      if (phoneNumber != 867 - 5309) {
+        throw new IllegalArgumentException("Unknown recipient");
+      }
+      // success!
+    }
+  }
+
+  static class Tweeter {
+    final TweetFactory tw;
+    final SMS sms;
+    final long phoneNumber;
+
+    @Inject
+    public Tweeter(TweetFactory tw, SMS sms,
+                   @Parameter(PhoneNumber.class) long phoneNumber) {
+      this.tw = tw;
+      this.sms = sms;
+      this.phoneNumber = phoneNumber;
+    }
+
+    public void sendMessage() {
+      sms.sendSMS(tw.getTweet(), phoneNumber);
+    }
+
+    @NamedParameter()
+    class PhoneNumber implements Name<Long> {
+    }
+  }
+
+  public static final class TweetConfig extends ConfigurationModuleBuilder {
+    public static final RequiredParameter<Long> PHONE_NUMBER = new RequiredParameter<>();
+    static final ConfigurationModule CONF = new TweetConfig()
+        .bindImplementation(TweetFactory.class, MockTweetFactory.class)
+        .bindImplementation(SMS.class, MockSMS.class)
+        .bindNamedParameter(Tweeter.PhoneNumber.class, PHONE_NUMBER)
+        .build();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerAvroRoundtripTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerAvroRoundtripTest.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerAvroRoundtripTest.java
new file mode 100644
index 0000000..9ffdee5
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerAvroRoundtripTest.java
@@ -0,0 +1,41 @@
+/**
+ * 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.reef.tang.formats;
+
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.formats.avro.AvroConfiguration;
+import org.apache.reef.tang.test.RoundTripTest;
+
+/**
+ * A RoundTripTest that converts to and from AvroConfiguration.
+ */
+public final class AvroConfigurationSerializerAvroRoundtripTest extends RoundTripTest {
+  @Override
+  public Configuration roundTrip(final Configuration configuration) throws Exception {
+    final AvroConfiguration aConf = new AvroConfigurationSerializer().toAvro(configuration);
+    return new AvroConfigurationSerializer().fromAvro(aConf);
+  }
+
+  @Override
+  public Configuration roundTrip(final Configuration configuration, final ClassHierarchy classHierarchy) throws Exception {
+    final AvroConfiguration aConf = new AvroConfigurationSerializer().toAvro(configuration);
+    return new AvroConfigurationSerializer().fromAvro(aConf, classHierarchy);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerByteArrayRoundtripTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerByteArrayRoundtripTest.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerByteArrayRoundtripTest.java
new file mode 100644
index 0000000..5de561a
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerByteArrayRoundtripTest.java
@@ -0,0 +1,42 @@
+/**
+ * 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.reef.tang.formats;
+
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.test.RoundTripTest;
+
+/**
+ * A RoundTripTest that uses avro to serialize to byte[].
+ */
+public final class AvroConfigurationSerializerByteArrayRoundtripTest extends RoundTripTest {
+  @Override
+  public Configuration roundTrip(Configuration configuration) throws Exception {
+    final AvroConfigurationSerializer serializer = new AvroConfigurationSerializer();
+    final byte[] theBytes = serializer.toByteArray(configuration);
+    return serializer.fromByteArray(theBytes);
+  }
+
+  @Override
+  public Configuration roundTrip(Configuration configuration, final ClassHierarchy classHierarchy) throws Exception {
+    final AvroConfigurationSerializer serializer = new AvroConfigurationSerializer();
+    final byte[] theBytes = serializer.toByteArray(configuration);
+    return serializer.fromByteArray(theBytes, classHierarchy);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerFileRoundtripTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerFileRoundtripTest.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerFileRoundtripTest.java
new file mode 100644
index 0000000..6d69576
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerFileRoundtripTest.java
@@ -0,0 +1,50 @@
+/**
+ * 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.reef.tang.formats;
+
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.test.RoundTripTest;
+
+import java.io.File;
+
+/**
+ * A RoundTripTest that serializes to and from files generated by Avro.
+ */
+public final class AvroConfigurationSerializerFileRoundtripTest extends RoundTripTest {
+  @Override
+  public Configuration roundTrip(Configuration configuration) throws Exception {
+    final File tempFile = java.io.File.createTempFile("TangTest", "avroconf");
+    final AvroConfigurationSerializer serializer = new AvroConfigurationSerializer();
+    serializer.toFile(configuration, tempFile);
+    final Configuration c = serializer.fromFile(tempFile);
+    tempFile.delete();
+    return c;
+  }
+
+  @Override
+  public Configuration roundTrip(Configuration configuration, final ClassHierarchy classHierarchy) throws Exception {
+    final File tempFile = java.io.File.createTempFile("TangTest", "avroconf");
+    final AvroConfigurationSerializer serializer = new AvroConfigurationSerializer();
+    serializer.toFile(configuration, tempFile);
+    final Configuration c = serializer.fromFile(tempFile, classHierarchy);
+    tempFile.delete();
+    return c;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerStringRoundtripTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerStringRoundtripTest.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerStringRoundtripTest.java
new file mode 100644
index 0000000..add5bcf
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerStringRoundtripTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.reef.tang.formats;
+
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.test.RoundTripTest;
+
+/**
+ * A test for Configuration serialization to Strings using AvroConfigurationSerializer.
+ */
+public class AvroConfigurationSerializerStringRoundtripTest extends RoundTripTest {
+  @Override
+  public Configuration roundTrip(final Configuration configuration) throws Exception {
+    final AvroConfigurationSerializer serializer = new AvroConfigurationSerializer();
+    return serializer.fromString(serializer.toString(configuration));
+  }
+
+  @Override
+  public Configuration roundTrip(final Configuration configuration, final ClassHierarchy classHierarchy) throws Exception {
+    final AvroConfigurationSerializer serializer = new AvroConfigurationSerializer();
+    return serializer.fromString(serializer.toString(configuration), classHierarchy);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerTextFileRoundtripTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerTextFileRoundtripTest.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerTextFileRoundtripTest.java
new file mode 100644
index 0000000..2220a9c
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/AvroConfigurationSerializerTextFileRoundtripTest.java
@@ -0,0 +1,50 @@
+/**
+ * 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.reef.tang.formats;
+
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.test.RoundTripTest;
+
+import java.io.File;
+
+/**
+ * A RoundTripTest that serializes to and from files generated by Avro.
+ */
+public final class AvroConfigurationSerializerTextFileRoundtripTest extends RoundTripTest {
+  @Override
+  public Configuration roundTrip(Configuration configuration) throws Exception {
+    final File tempFile = File.createTempFile("TangTest", "avroconf");
+    final AvroConfigurationSerializer serializer = new AvroConfigurationSerializer();
+    serializer.toTextFile(configuration, tempFile);
+    final Configuration c = serializer.fromTextFile(tempFile);
+    tempFile.delete();
+    return c;
+  }
+
+  @Override
+  public Configuration roundTrip(Configuration configuration, final ClassHierarchy classHierarchy) throws Exception {
+    final File tempFile = File.createTempFile("TangTest", "avroconf");
+    final AvroConfigurationSerializer serializer = new AvroConfigurationSerializer();
+    serializer.toTextFile(configuration, tempFile);
+    final Configuration c = serializer.fromTextFile(tempFile, classHierarchy);
+    tempFile.delete();
+    return c;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/ConfigurationFileTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/ConfigurationFileTest.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/ConfigurationFileTest.java
new file mode 100644
index 0000000..9197b85
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/ConfigurationFileTest.java
@@ -0,0 +1,54 @@
+/**
+ * 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.reef.tang.formats;
+
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.test.RoundTripTest;
+
+import java.io.File;
+
+/**
+ * Tests the file writing routines in ConfigurationFile.
+ */
+public final class ConfigurationFileTest extends RoundTripTest {
+  @Override
+  public Configuration roundTrip(final Configuration configuration) throws Exception {
+    final File tempFile = java.io.File.createTempFile("TangTest", "txt");
+    final ConfigurationSerializer serializer = new AvroConfigurationSerializer();
+    serializer.toTextFile(configuration, tempFile);
+    final JavaConfigurationBuilder configurationBuilder = Tang.Factory.getTang().newConfigurationBuilder();
+    final Configuration conf = serializer.fromTextFile(tempFile);
+    configurationBuilder.addConfiguration(conf);
+    tempFile.delete();
+    return configurationBuilder.build();
+  }
+
+  @Override
+  public Configuration roundTrip(final Configuration configuration, final ClassHierarchy classHierarchy) throws Exception {
+    final File tempFile = java.io.File.createTempFile("TangTest", "txt");
+    final ConfigurationSerializer serializer = new AvroConfigurationSerializer();
+    serializer.toTextFile(configuration, tempFile);
+    final Configuration conf = serializer.fromTextFile(tempFile, classHierarchy);
+    tempFile.delete();
+    return conf;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/NamedParameters.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/NamedParameters.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/NamedParameters.java
new file mode 100644
index 0000000..3dd7cf6
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/NamedParameters.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.tang.formats;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * Named parameters to be used in tests.
+ */
+public class NamedParameters {
+
+  @NamedParameter(short_name = StringShortNameDefault.SHORT_NAME, default_value = StringShortNameDefault.DEFAULT_VALUE)
+  public static class StringShortNameDefault implements Name<String> {
+    public static final String SHORT_NAME = "string";
+    public static final String DEFAULT_VALUE = "default";
+  }
+
+  @NamedParameter
+  public static class StringNoShortNameNoDefault implements Name<String> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/TestCommandLine.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/TestCommandLine.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/TestCommandLine.java
new file mode 100644
index 0000000..0fb3bb3
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/TestCommandLine.java
@@ -0,0 +1,79 @@
+/**
+ * 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.reef.tang.formats;
+
+import junit.framework.Assert;
+import org.apache.commons.cli.ParseException;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.ConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+/**
+ * Tests for the CommandLine class.
+ */
+public final class TestCommandLine {
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  @Test
+  public void testNoShortNameToRegister() throws BindException {
+    thrown.expect(BindException.class);
+    final ConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    final CommandLine cl = new CommandLine(cb);
+    cl.registerShortNameOfClass(NamedParameters.StringNoShortNameNoDefault.class);
+  }
+
+  /**
+   * Tests for parseToConfiguration() with a named parameter that is set
+   *
+   * @throws ParseException
+   * @throws InjectionException
+   */
+  @Test
+  public void testParseToConfiguration() throws ParseException, InjectionException {
+    final String expected = "hello";
+    final String[] args = {"-" + NamedParameters.StringShortNameDefault.SHORT_NAME, expected};
+    final Configuration configuration = CommandLine
+        .parseToConfiguration(args, NamedParameters.StringShortNameDefault.class);
+    final String injected = Tang.Factory.getTang().newInjector(configuration)
+        .getNamedInstance(NamedParameters.StringShortNameDefault.class);
+    Assert.assertEquals(expected, injected);
+  }
+
+  /**
+   * Tests for parseToConfiguration() with a named parameter that is not set
+   *
+   * @throws ParseException
+   * @throws InjectionException
+   */
+  @Test
+  public void testParseToConfigurationWithDefault() throws ParseException, InjectionException {
+    final Configuration configuration = CommandLine
+        .parseToConfiguration(new String[0], NamedParameters.StringShortNameDefault.class);
+    final String injected = Tang.Factory.getTang().newInjector(configuration)
+        .getNamedInstance(NamedParameters.StringShortNameDefault.class);
+    Assert.assertEquals(NamedParameters.StringShortNameDefault.DEFAULT_VALUE, injected);
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/TestConfigurationModule.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/TestConfigurationModule.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/TestConfigurationModule.java
new file mode 100644
index 0000000..97403d9
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/formats/TestConfigurationModule.java
@@ -0,0 +1,445 @@
+/**
+ * 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.reef.tang.formats;
+
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.ConfigurationBuilder;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.ClassHierarchyException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.util.Set;
+
+/*
+ * Define a configuration module that explains how Foo should be injected.
+ * 
+ * A configuration module is like a configuration builder, except that it
+ * is not language independent (it should be defined in the same jar / whatever 
+ * as the stuff it configures, and it has a concept of variables that can be
+ * required or optional.
+ * 
+ * If you call build() without setting the required variables (or if the
+ * configuration declares variables that it does not use), then it blows up
+ * in your face.
+ * 
+ * Note that MyConfigurationModule does not actually subclass
+ * ConfigurationModule.  Instead, it has a static final field that contains a
+ * configuration module, and some other ones that define the parameters, and
+ * their types.
+ * 
+ * There are some *ahem* non-idiomatic java things going on here.
+ * 
+ * Sorry about that; if you can find my java programming license, you can take it
+ * away. :)
+ *
+ * First, you need the " = new RequiredImpl<>()" after each parameter.  This is
+ * because you need to pass something into set (other than null).  References to
+ * live objects happen to be unique, so that works.
+ * 
+ * Second, ConfigurationModule() is abstract, and all of its methods are defined
+ * as final.  To instantiate it, you need to put the {}'s between the () and the
+ * .bind stuff.  This is so I can call getClass().getEnclosingClass() in its
+ * constructor, and discover all those juicy configuration parameters that
+ * were assigned above it.  On the bright side, if you forget the {}'s you get
+ * a compiler error.  It used to be that you'd get a cryptic NPE from the
+ * classloader.  Also, note that adding methods to ConfigurationModule() won't
+ * work.  The bind calls implement immutability by using a secret final clone
+ * method called deepCopy() that strips your subclass off, and uses an anonomyous
+ * inner class instead.
+ * 
+ * 
+ */
+
+interface Super {
+}
+
+final class MyBadConfigurationModule extends ConfigurationModuleBuilder {
+
+}
+
+final class MyConfigurationModule extends ConfigurationModuleBuilder {
+  // Tell us what implementation you want, or else!!
+  public static final RequiredImpl<TestConfigurationModule.Foo> THE_FOO = new RequiredImpl<>();
+  // If you want, you can change the fooness.
+  public static final OptionalParameter<Integer> FOO_NESS = new OptionalParameter<>();
+
+  public static final ConfigurationModule CONF = new MyConfigurationModule()
+
+      // This binds the above to tang configuration stuff.  You can use parameters more than
+      // once, but you'd better use them all at least once, or I'll throw exceptions at you.
+
+      .bindImplementation(TestConfigurationModule.Foo.class, MyConfigurationModule.THE_FOO)
+      .bindNamedParameter(TestConfigurationModule.Fooness.class, MyConfigurationModule.FOO_NESS)
+      .build();
+}
+
+final class MyMissingBindConfigurationModule extends ConfigurationModuleBuilder {
+  // Tell us what implementation you want, or else!!
+  public static final RequiredImpl<TestConfigurationModule.Foo> THE_FOO = new RequiredImpl<>();
+  // If you want, you can change the fooness.
+  public static final OptionalParameter<Integer> FOO_NESS = new OptionalParameter<>();
+
+  // This conf doesn't use FOO_NESS.  Expect trouble below
+  public static final ConfigurationModule BAD_CONF = new MyMissingBindConfigurationModule()
+      .bindImplementation(TestConfigurationModule.Foo.class, THE_FOO)
+      .build();
+
+}
+
+public class TestConfigurationModule {
+  /*
+   *  Toy class hierarchy: FooImpl implements Foo, has a Fooness named
+   *  parameter that defaults to 42.
+   */
+
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  @Test
+  public void smokeTest() throws BindException, InjectionException {
+    // Here we set some configuration values.  In true tang style,
+    // you won't be able to set them more than once ConfigurationModule's
+    // implementation is complete.
+    Configuration c = MyConfigurationModule.CONF
+        .set(MyConfigurationModule.THE_FOO, FooImpl.class)
+        .set(MyConfigurationModule.FOO_NESS, "" + 12)
+        .build();
+    Foo f = Tang.Factory.getTang().newInjector(c).getInstance(Foo.class);
+    Assert.assertEquals(f.getFooness(), 12);
+  }
+
+  @Test
+  public void smokeTestConfigFile() throws BindException, InjectionException, IOException {
+    // Here we set some configuration values.  In true tang style,
+    // you won't be able to set them more than once ConfigurationModule's
+    // implementation is complete.
+    Configuration c = MyConfigurationModule.CONF
+        .set(MyConfigurationModule.THE_FOO, FooImpl.class)
+        .set(MyConfigurationModule.FOO_NESS, "" + 12)
+        .build();
+    Foo f = Tang.Factory.getTang().newInjector(c).getInstance(Foo.class);
+    Assert.assertEquals(f.getFooness(), 12);
+
+    final File tempFile = File.createTempFile("TangTest", ".avroconf");
+    final AvroConfigurationSerializer serializer = new AvroConfigurationSerializer();
+    serializer.toFile(c, tempFile);
+    serializer.fromFile(tempFile);
+
+  }
+
+  @Test
+  public void omitOptionalTest() throws BindException, InjectionException {
+    // Optional is optional.
+    Configuration c = MyConfigurationModule.CONF
+        .set(MyConfigurationModule.THE_FOO, FooImpl.class)
+        .build();
+    Foo f = Tang.Factory.getTang().newInjector(c).getInstance(Foo.class);
+    Assert.assertEquals(f.getFooness(), 42);
+  }
+
+  @Test
+  public void omitRequiredTest() throws Throwable {
+    thrown.expect(BindException.class);
+    thrown.expectMessage("Attempt to build configuration before setting required option(s): { THE_FOO }");
+    try {
+      MyConfigurationModule.CONF
+          .set(MyConfigurationModule.FOO_NESS, "" + 12)
+          .build();
+    } catch (ExceptionInInitializerError e) {
+      throw e.getCause();
+    }
+  }
+
+  @Test
+  public void badConfTest() throws Throwable {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("Found declared options that were not used in binds: { FOO_NESS }");
+    try {
+      // Java's classloader semantics cause it to load a class when executing the
+      // first line that references the class in question.
+      @SuppressWarnings("unused")
+      Object o = MyMissingBindConfigurationModule.BAD_CONF;
+    } catch (ExceptionInInitializerError e) {
+      throw e.getCause();
+    }
+  }
+
+  @Test
+  public void nonExistentStringBindOK() throws BindException, InjectionException {
+    new MyBadConfigurationModule().bindImplementation(Foo.class, "i.do.not.exist");
+  }
+
+  @Test
+  public void nonExistentStringBindNotOK() throws BindException, InjectionException {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("ConfigurationModule refers to unknown class: i.do.not.exist");
+
+    new MyBadConfigurationModule().bindImplementation(Foo.class, "i.do.not.exist").build();
+  }
+
+  @Test
+  public void multiBindTest() throws BindException, InjectionException {
+    // Here we set some configuration values.  In true tang style,
+    // you won't be able to set them more than once ConfigurationModule's
+    // implementation is complete.
+    Configuration c = MultiBindConfigurationModule.CONF
+        .set(MultiBindConfigurationModule.THE_FOO, FooImpl.class)
+        .set(MultiBindConfigurationModule.FOO_NESS, "" + 12)
+        .build();
+    Foo f = Tang.Factory.getTang().newInjector(c).getInstance(Foo.class);
+    Foo g = (Foo) Tang.Factory.getTang().newInjector(c).getInstance(Object.class);
+    Assert.assertEquals(f.getFooness(), 12);
+    Assert.assertEquals(g.getFooness(), 12);
+    Assert.assertFalse(f == g);
+  }
+
+  @Test
+  public void foreignSetTest() throws Throwable {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("Unknown Impl/Param when setting RequiredImpl.  Did you pass in a field from some other module?");
+    try {
+      // Pass in something from the wrong module, watch it fail.
+      MultiBindConfigurationModule.CONF.set(MyConfigurationModule.THE_FOO, FooImpl.class);
+    } catch (ExceptionInInitializerError e) {
+      throw e.getCause();
+    }
+  }
+
+  @Test
+  public void foreignBindTest() throws Throwable {
+    thrown.expect(ClassHierarchyException.class);
+    thrown.expectMessage("Unknown Impl/Param when binding RequiredImpl.  Did you pass in a field from some other module?");
+    try {
+      // Pass in something from the wrong module, watch it fail.
+      new MyConfigurationModule().bindImplementation(Object.class, MultiBindConfigurationModule.THE_FOO);
+    } catch (ExceptionInInitializerError e) {
+      throw e.getCause();
+    }
+  }
+
+  @Test
+  public void singletonTest() throws BindException, InjectionException {
+    Configuration c = new MyConfigurationModule()
+        .bindImplementation(Foo.class, MyConfigurationModule.THE_FOO)
+        .bindNamedParameter(Fooness.class, MyConfigurationModule.FOO_NESS)
+        .build()
+        .set(MyConfigurationModule.THE_FOO, FooImpl.class)
+        .build();
+    Injector i = Tang.Factory.getTang().newInjector(c);
+    Assert.assertTrue(i.getInstance(Foo.class) == i.getInstance(Foo.class));
+  }
+
+  @Test
+  public void immutablilityTest() throws BindException, InjectionException {
+    // builder methods return copies; the original module is immutable
+    ConfigurationModule builder1 = MyConfigurationModule.CONF
+        .set(MyConfigurationModule.THE_FOO, FooImpl.class);
+    Assert.assertFalse(builder1 == MyConfigurationModule.CONF);
+    Configuration config1 = builder1.build();
+
+    // reusable
+    Configuration config2 = MyConfigurationModule.CONF
+        .set(MyConfigurationModule.THE_FOO, FooAltImpl.class)
+        .build();
+
+    // instantiation of each just to be sure everything is fine in this situation
+    Injector i1 = Tang.Factory.getTang().newInjector(config1);
+    Injector i2 = Tang.Factory.getTang().newInjector(config2);
+    Assert.assertEquals(42, i1.getInstance(Foo.class).getFooness());
+    Assert.assertEquals(7, i2.getInstance(Foo.class).getFooness());
+  }
+
+  @Test
+  public void setParamTest() throws BindException, InjectionException {
+    Configuration c = SetConfigurationModule.CONF
+        .set(SetConfigurationModule.P, "a")
+        .set(SetConfigurationModule.P, "b")
+        .build();
+    Set<String> s = Tang.Factory.getTang().newInjector(c).getNamedInstance(SetName.class);
+    Assert.assertEquals(s.size(), 2);
+    Assert.assertTrue(s.contains("a"));
+    Assert.assertTrue(s.contains("b"));
+  }
+
+  @Test
+  public void setClassTest() throws BindException, InjectionException {
+    Configuration c = SetClassConfigurationModule.CONF
+        .set(SetClassConfigurationModule.P, SubA.class)
+        .set(SetClassConfigurationModule.P, SubB.class)
+        .build();
+    Set<Super> s = Tang.Factory.getTang().newInjector(c).getNamedInstance(SetClass.class);
+    Assert.assertEquals(2, s.size());
+    boolean sawA = false, sawB = false;
+    for (Super sup : s) {
+      if (sup instanceof SubA) {
+        sawA = true;
+      } else if (sup instanceof SubB) {
+        sawB = true;
+      } else {
+        Assert.fail();
+      }
+    }
+    Assert.assertTrue(sawA && sawB);
+  }
+
+  @Test
+  public void setClassRoundTripTest() throws BindException, InjectionException {
+    Configuration c = SetClassConfigurationModule.CONF
+        .set(SetClassConfigurationModule.P, SubA.class)
+        .set(SetClassConfigurationModule.P, SubB.class)
+        .build();
+    ConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    ConfigurationFile.addConfiguration(cb, ConfigurationFile.toConfigurationString(c));
+    Set<Super> s = Tang.Factory.getTang().newInjector(cb.build()).getNamedInstance(SetClass.class);
+    Assert.assertEquals(2, s.size());
+    boolean sawA = false, sawB = false;
+    for (Super sup : s) {
+      if (sup instanceof SubA) {
+        sawA = true;
+      } else if (sup instanceof SubB) {
+        sawB = true;
+      } else {
+        Assert.fail();
+      }
+    }
+    Assert.assertTrue(sawA && sawB);
+  }
+
+  @Test(expected = ClassHierarchyException.class)
+  public void errorOnStaticTimeSet() throws BindException, InjectionException {
+    StaticTimeSet.CONF.assertStaticClean();
+  }
+
+  @Test(expected = ClassHierarchyException.class)
+  public void errorOnSetMerge() throws BindException, InjectionException {
+    ConfigurationModuleBuilder b = new ConfigurationModuleBuilder() {
+    };
+    b.merge(StaticTimeSet.CONF);
+  }
+
+
+  static interface Foo {
+    public int getFooness();
+  }
+
+  static class FooImpl implements Foo {
+    private final int fooness;
+
+    @Inject
+    FooImpl(@Parameter(Fooness.class) int fooness) {
+      this.fooness = fooness;
+    }
+
+    public int getFooness() {
+      return this.fooness;
+    }
+  }
+
+  static class FooAltImpl implements Foo {
+    @SuppressWarnings("unused")
+    private final int fooness;
+
+    @Inject
+    FooAltImpl(@Parameter(Fooness.class) int fooness) {
+      this.fooness = fooness;
+    }
+
+    public int getFooness() {
+      return 7;
+    }
+  }
+
+  public static final class MultiBindConfigurationModule extends ConfigurationModuleBuilder {
+    // Tell us what implementation you want, or else!!
+    public static final RequiredImpl<Foo> THE_FOO = new RequiredImpl<>();
+    // If you want, you can change the fooness.
+    public static final OptionalParameter<Integer> FOO_NESS = new OptionalParameter<>();
+
+    public static final ConfigurationModule CONF = new MultiBindConfigurationModule()
+
+        // This binds the above to tang configuration stuff.  You can use parameters more than
+        // once, but you'd better use them all at least once, or I'll throw exceptions at you.
+
+        .bindImplementation(Foo.class, THE_FOO)
+        .bindImplementation(Object.class, THE_FOO)
+        .bindNamedParameter(Fooness.class, FOO_NESS)
+        .build();
+
+  }
+
+  @NamedParameter(default_value = "42")
+  class Fooness implements Name<Integer> {
+  }
+
+}
+
+@NamedParameter
+class SetName implements Name<Set<String>> {
+}
+
+class SetConfigurationModule extends ConfigurationModuleBuilder {
+  public final static RequiredParameter<String> P = new RequiredParameter<>();
+
+  public static final ConfigurationModule CONF = new SetConfigurationModule()
+      .bindSetEntry(SetName.class, SetConfigurationModule.P)
+      .build();
+}
+
+@NamedParameter
+class SetClass implements Name<Set<Super>> {
+}
+
+class SetClassConfigurationModule extends ConfigurationModuleBuilder {
+  public final static RequiredParameter<Super> P = new RequiredParameter<>();
+  public static final ConfigurationModule CONF = new SetClassConfigurationModule()
+      .bindSetEntry(SetClass.class, SetClassConfigurationModule.P)
+      .build();
+}
+
+class SubA implements Super {
+  @Inject
+  public SubA() {
+  }
+}
+
+class SubB implements Super {
+  @Inject
+  public SubB() {
+  }
+}
+
+class StaticTimeSet extends ConfigurationModuleBuilder {
+  public static final OptionalImpl<Super> X = new OptionalImpl<>();
+  public static final ConfigurationModule CONF = new StaticTimeSet()
+      .bindImplementation(Super.class, X)
+      .build()
+      .set(X, SubA.class);
+}
\ No newline at end of file


[45/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/fs/FSCheckPointServiceConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/fs/FSCheckPointServiceConfiguration.java b/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/fs/FSCheckPointServiceConfiguration.java
new file mode 100644
index 0000000..bccf091
--- /dev/null
+++ b/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/fs/FSCheckPointServiceConfiguration.java
@@ -0,0 +1,110 @@
+/**
+ * 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.reef.io.checkpoint.fs;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.io.checkpoint.CheckpointID;
+import org.apache.reef.io.checkpoint.CheckpointNamingService;
+import org.apache.reef.io.checkpoint.CheckpointService;
+import org.apache.reef.io.checkpoint.RandomNameCNS;
+import org.apache.reef.tang.ExternalConstructor;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.OptionalParameter;
+import org.apache.reef.tang.formats.RequiredParameter;
+
+import javax.inject.Inject;
+import java.io.IOException;
+
+/**
+ * ConfigurationModule for the FSCheckPointService.
+ * This can be used to create Evaluator-side configurations of the checkpointing service.
+ */
+@DriverSide
+@Public
+public class FSCheckPointServiceConfiguration extends ConfigurationModuleBuilder {
+
+  /**
+   * Use local file system if true; otherwise, use HDFS.
+   */
+  public static final RequiredParameter<Boolean> IS_LOCAL = new RequiredParameter<>();
+
+  /**
+   * Path to be used to store the checkpoints on file system.
+   */
+  public static final RequiredParameter<String> PATH = new RequiredParameter<>();
+
+  /**
+   * Replication factor to be used for the checkpoints.
+   */
+  public static final OptionalParameter<Short> REPLICATION_FACTOR = new OptionalParameter<>();
+
+  /**
+   * Prefix for checkpoint files (optional).
+   */
+  public static final OptionalParameter<String> PREFIX = new OptionalParameter<>();
+  public static final ConfigurationModule CONF = new FSCheckPointServiceConfiguration()
+      .bindImplementation(CheckpointService.class, FSCheckpointService.class) // Use the HDFS based ccheckpoints
+      .bindImplementation(CheckpointNamingService.class, RandomNameCNS.class) // Use Random Names for the checkpoints
+      .bindImplementation(CheckpointID.class, FSCheckpointID.class)
+      .bindConstructor(FileSystem.class, FileSystemConstructor.class)
+      .bindNamedParameter(FileSystemConstructor.IS_LOCAL.class, IS_LOCAL)
+      .bindNamedParameter(FSCheckpointService.PATH.class, PATH)
+      .bindNamedParameter(FSCheckpointService.REPLICATION_FACTOR.class, REPLICATION_FACTOR)
+      .bindNamedParameter(RandomNameCNS.PREFIX.class, PREFIX)
+      .build();
+
+  /**
+   * Constructor for Hadoop FileSystem instances.
+   * This assumes that Hadoop Configuration is in the CLASSPATH.
+   */
+  public static class FileSystemConstructor implements ExternalConstructor<FileSystem> {
+
+    /**
+     * If false, use default values for Hadoop configuration; otherwise, load from config file.
+     * Set to false when REEF is running in local mode.
+     */
+    private final boolean loadConfig;
+
+    @Inject
+    public FileSystemConstructor(final @Parameter(IS_LOCAL.class) boolean isLocal) {
+      this.loadConfig = !isLocal;
+    }
+
+    @Override
+    public FileSystem newInstance() {
+      try {
+        return FileSystem.get(new Configuration(this.loadConfig));
+      } catch (final IOException ex) {
+        throw new RuntimeException("Unable to create a FileSystem instance." +
+            " Probably Hadoop configuration is not in the CLASSPATH", ex);
+      }
+    }
+
+    @NamedParameter(doc = "Use local file system if true; otherwise, use HDFS.")
+    static class IS_LOCAL implements Name<Boolean> {
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/fs/FSCheckpointID.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/fs/FSCheckpointID.java b/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/fs/FSCheckpointID.java
new file mode 100644
index 0000000..784e026
--- /dev/null
+++ b/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/fs/FSCheckpointID.java
@@ -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.reef.io.checkpoint.fs;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.io.Text;
+import org.apache.reef.io.checkpoint.CheckpointID;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+/**
+ * A FileSystem based checkpoint ID contains reference to the Path
+ * where the checkpoint has been saved.
+ */
+public class FSCheckpointID implements CheckpointID {
+
+  private Path path;
+
+  public FSCheckpointID() {
+  }
+
+  public FSCheckpointID(Path path) {
+    this.path = path;
+  }
+
+  public Path getPath() {
+    return path;
+  }
+
+  @Override
+  public String toString() {
+    return path.toString();
+  }
+
+  @Override
+  public void write(DataOutput out) throws IOException {
+    Text.writeString(out, path.toString());
+  }
+
+  @Override
+  public void readFields(DataInput in) throws IOException {
+    this.path = new Path(Text.readString(in));
+  }
+
+  @Override
+  public boolean equals(Object other) {
+    return other instanceof FSCheckpointID
+        && path.equals(((FSCheckpointID) other).path);
+  }
+
+  @Override
+  public int hashCode() {
+    return path.hashCode();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/fs/FSCheckpointService.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/fs/FSCheckpointService.java b/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/fs/FSCheckpointService.java
new file mode 100644
index 0000000..a3fabfb
--- /dev/null
+++ b/lang/java/reef-checkpoint/src/main/java/org/apache/reef/io/checkpoint/fs/FSCheckpointService.java
@@ -0,0 +1,221 @@
+/**
+ * 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.reef.io.checkpoint.fs;
+
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.reef.io.checkpoint.CheckpointID;
+import org.apache.reef.io.checkpoint.CheckpointNamingService;
+import org.apache.reef.io.checkpoint.CheckpointService;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+
+/**
+ * A FileSystem based CheckpointService.
+ */
+public class FSCheckpointService implements CheckpointService {
+
+  private final Path base;
+  private final FileSystem fs;
+  private final CheckpointNamingService namingPolicy;
+  private final short replication;
+
+  @Inject
+  FSCheckpointService(final FileSystem fs,
+                      final @Parameter(PATH.class) String basePath,
+                      final CheckpointNamingService namingPolicy,
+                      final @Parameter(REPLICATION_FACTOR.class) short replication) {
+    this.fs = fs;
+    this.base = new Path(basePath);
+    this.namingPolicy = namingPolicy;
+    this.replication = replication;
+  }
+
+  public FSCheckpointService(final FileSystem fs,
+                             final Path base,
+                             final CheckpointNamingService namingPolicy,
+                             final short replication) {
+    this.fs = fs;
+    this.base = base;
+    this.namingPolicy = namingPolicy;
+    this.replication = replication;
+  }
+
+  static final Path tmpfile(final Path p) {
+    return new Path(p.getParent(), p.getName() + ".tmp");
+  }
+
+  public CheckpointWriteChannel create()
+      throws IOException {
+
+    final String name = namingPolicy.getNewName();
+
+    final Path p = new Path(name);
+    if (p.isUriPathAbsolute()) {
+      throw new IOException("Checkpoint cannot be an absolute path");
+    }
+    return createInternal(new Path(base, p));
+  }
+
+  CheckpointWriteChannel createInternal(Path name) throws IOException {
+
+    //create a temp file, fail if file exists
+    return new FSCheckpointWriteChannel(name, fs.create(tmpfile(name), replication));
+  }
+
+  @Override
+  public CheckpointReadChannel open(final CheckpointID id)
+      throws IOException, InterruptedException {
+    if (!(id instanceof FSCheckpointID)) {
+      throw new IllegalArgumentException(
+          "Mismatched checkpoint type: " + id.getClass());
+    }
+    return new FSCheckpointReadChannel(
+        fs.open(((FSCheckpointID) id).getPath()));
+  }
+
+  @Override
+  public CheckpointID commit(final CheckpointWriteChannel ch) throws IOException,
+      InterruptedException {
+    if (ch.isOpen()) {
+      ch.close();
+    }
+    final FSCheckpointWriteChannel hch = (FSCheckpointWriteChannel) ch;
+    final Path dst = hch.getDestination();
+    if (!fs.rename(tmpfile(dst), dst)) {
+      // attempt to clean up
+      abort(ch);
+      throw new IOException("Failed to promote checkpoint" +
+          tmpfile(dst) + " -> " + dst);
+    }
+    return new FSCheckpointID(hch.getDestination());
+  }
+
+  @Override
+  public void abort(final CheckpointWriteChannel ch) throws IOException {
+    if (ch.isOpen()) {
+      ch.close();
+    }
+    final FSCheckpointWriteChannel hch = (FSCheckpointWriteChannel) ch;
+    final Path tmp = tmpfile(hch.getDestination());
+    try {
+      if (!fs.delete(tmp, false)) {
+        throw new IOException("Failed to delete checkpoint during abort");
+      }
+    } catch (FileNotFoundException e) {
+      // IGNORE
+    }
+  }
+
+  @Override
+  public boolean delete(final CheckpointID id) throws IOException,
+      InterruptedException {
+    if (!(id instanceof FSCheckpointID)) {
+      throw new IllegalArgumentException(
+          "Mismatched checkpoint type: " + id.getClass());
+    }
+    Path tmp = ((FSCheckpointID) id).getPath();
+    try {
+      return fs.delete(tmp, false);
+    } catch (FileNotFoundException e) {
+      // IGNORE
+    }
+    return true;
+  }
+
+  @NamedParameter(doc = "The path to be used to store the checkpoints.")
+  static class PATH implements Name<String> {
+  }
+
+  @NamedParameter(doc = "The replication factor to be used for the stored checkpoints", default_value = "3")
+  static class REPLICATION_FACTOR implements Name<Short> {
+  }
+
+  private static class FSCheckpointWriteChannel
+      implements CheckpointWriteChannel {
+    private final Path finalDst;
+    private final WritableByteChannel out;
+    private boolean isOpen = true;
+
+    FSCheckpointWriteChannel(final Path finalDst, final FSDataOutputStream out) {
+      this.finalDst = finalDst;
+      this.out = Channels.newChannel(out);
+    }
+
+    public int write(final ByteBuffer b) throws IOException {
+      return out.write(b);
+    }
+
+    public Path getDestination() {
+      return finalDst;
+    }
+
+    @Override
+    public void close() throws IOException {
+      isOpen = false;
+      out.close();
+    }
+
+    @Override
+    public boolean isOpen() {
+      return isOpen;
+    }
+
+  }
+
+  private static class FSCheckpointReadChannel
+      implements CheckpointReadChannel {
+
+    private final ReadableByteChannel in;
+    private boolean isOpen = true;
+
+    FSCheckpointReadChannel(final FSDataInputStream in) {
+      this.in = Channels.newChannel(in);
+    }
+
+    @Override
+    public int read(final ByteBuffer bb) throws IOException {
+      return in.read(bb);
+    }
+
+    @Override
+    public void close() throws IOException {
+      isOpen = false;
+      in.close();
+    }
+
+    @Override
+    public boolean isOpen() {
+      return isOpen;
+    }
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/maven-eclipse.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/maven-eclipse.xml b/lang/java/reef-common/maven-eclipse.xml
new file mode 100644
index 0000000..6c6b5ae
--- /dev/null
+++ b/lang/java/reef-common/maven-eclipse.xml
@@ -0,0 +1,28 @@
+<!--
+
+    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 default="copy-resources">
+  <target name="init"/>
+  <target name="copy-resources" depends="init">
+    <copy todir="target/classes/META-INF/conf" filtering="false">
+      <fileset dir="src/main/conf" includes="*.xml|*.properties" excludes="**/*.java"/>
+    </copy>
+  </target>
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/pom.xml b/lang/java/reef-common/pom.xml
new file mode 100644
index 0000000..c2d5ee0
--- /dev/null
+++ b/lang/java/reef-common/pom.xml
@@ -0,0 +1,142 @@
+<?xml version="1.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.
+-->
+<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.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>reef-common</artifactId>
+    <name>REEF Common</name>
+
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-antrun-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>generate-sources</id>
+                        <phase>generate-sources</phase>
+                        <configuration>
+                            <tasks>
+                                <mkdir dir="target/generated-sources/proto"/>
+                                <exec executable="protoc">
+                                    <arg value="--proto_path=src/main/proto/"/>
+                                    <arg value="--java_out=target/generated-sources/proto"/>
+                                    <arg value="src/main/proto/reef_service_protos.proto"/>
+                                    <arg value="src/main/proto/evaluator_runtime.proto"/>
+                                    <arg value="src/main/proto/client_runtime.proto"/>
+                                    <arg value="src/main/proto/driver_runtime.proto"/>
+                                    <arg value="src/main/proto/reef_protocol.proto"/>
+                                </exec>
+                            </tasks>
+                            <sourceRoot>target/generated-sources/proto</sourceRoot>
+                        </configuration>
+                        <goals>
+                            <goal>run</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>add-source</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>target/generated-sources/proto</source>
+                            </sources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+        <resources>
+            <resource>
+                <directory>${basedir}/src/main/resources</directory>
+                <includes>
+                    <include>version.properties</include>
+                </includes>
+                <filtering>true</filtering>
+            </resource>
+            <resource>
+                <directory>${basedir}/src/main/resources</directory>
+                <excludes>
+                    <exclude>version.properties</exclude>
+                </excludes>
+                <filtering>false</filtering>
+            </resource>
+        </resources>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-annotations</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-utils</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.google.protobuf</groupId>
+            <artifactId>protobuf-java</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>wake</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>tang</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>net.jcip</groupId>
+            <artifactId>jcip-annotations</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+        </dependency>
+    </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/conf/log4j.properties
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/conf/log4j.properties b/lang/java/reef-common/src/main/conf/log4j.properties
new file mode 100644
index 0000000..53d72e2
--- /dev/null
+++ b/lang/java/reef-common/src/main/conf/log4j.properties
@@ -0,0 +1,40 @@
+#
+# 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.
+#
+
+#### Use two appenders, one to log to console, another to log to a file  
+log4j.rootCategory=info, stdout, R
+  
+#### First appender writes to console  
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender  
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout  
+  
+# Pattern to output the caller's file name and line number.  
+log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F%L) - %m%n  
+  
+#### Second appender writes to a file  
+log4j.appender.R=org.apache.log4j.RollingFileAppender  
+log4j.appender.R.File=D:\\log\\import.log  
+  
+# Control the maximum log file size  
+log4j.appender.R.MaxFileSize=10000KB  
+# Archive log files (one backup file here)  
+log4j.appender.R.MaxBackupIndex=10  
+  
+log4j.appender.R.layout=org.apache.log4j.PatternLayout  
+log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n  

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/conf/reef-site.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/conf/reef-site.xml b/lang/java/reef-common/src/main/conf/reef-site.xml
new file mode 100644
index 0000000..334e913
--- /dev/null
+++ b/lang/java/reef-common/src/main/conf/reef-site.xml
@@ -0,0 +1,21 @@
+<!--
+
+    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.
+
+-->
+-->

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/client/ClientConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/client/ClientConfiguration.java b/lang/java/reef-common/src/main/java/org/apache/reef/client/ClientConfiguration.java
new file mode 100644
index 0000000..3bdb992
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/client/ClientConfiguration.java
@@ -0,0 +1,83 @@
+/**
+ * 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.reef.client;
+
+import org.apache.reef.client.parameters.*;
+import org.apache.reef.runtime.common.client.parameters.ClientPresent;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.OptionalImpl;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.RemoteConfiguration;
+
+/**
+ * A ConfigurationModule to fill out for the client configuration.
+ */
+public final class ClientConfiguration extends ConfigurationModuleBuilder {
+
+  /**
+   * Event handler for messages from the running job.
+   * Default implementation just writes message to the log.
+   * A message contains a status and a client-defined message payload.
+   */
+  public static final OptionalImpl<EventHandler<JobMessage>> ON_JOB_MESSAGE = new OptionalImpl<>();
+
+  /**
+   * Handler for the event when a submitted REEF Job is running.
+   * Default implementation just writes to the log.
+   */
+  public static final OptionalImpl<EventHandler<RunningJob>> ON_JOB_RUNNING = new OptionalImpl<>();
+
+  /**
+   * Handler for the event when a submitted REEF Job is completed.
+   * Default implementation just writes to the log.
+   */
+  public static final OptionalImpl<EventHandler<CompletedJob>> ON_JOB_COMPLETED = new OptionalImpl<>();
+
+  /**
+   * Handler for the event when a submitted REEF Job has failed.
+   * Default implementation logs an error and rethrows the exception in the client JVM.
+   */
+  public static final OptionalImpl<EventHandler<FailedJob>> ON_JOB_FAILED = new OptionalImpl<>();
+
+  /**
+   * Receives fatal resourcemanager errors. The presence of this error means that the
+   * underlying REEF instance is no longer able to execute REEF jobs. The
+   * actual Jobs may or may not still be running.
+   * Default implementation logs an error and rethrows the exception in the client JVM.
+   */
+  public static final OptionalImpl<EventHandler<FailedRuntime>> ON_RUNTIME_ERROR = new OptionalImpl<>();
+
+  /**
+   * Error handler for events on Wake-spawned threads.
+   * Exceptions that are thrown on wake-spawned threads (e.g. in EventHandlers) will be caught by Wake and delivered to
+   * this handler. Default behavior is to log the exceptions and rethrow them as RuntimeExceptions.
+   */
+  public static final OptionalImpl<EventHandler<Throwable>> ON_WAKE_ERROR = new OptionalImpl<>();
+
+  public static final ConfigurationModule CONF = new ClientConfiguration()
+      .bind(JobMessageHandler.class, ON_JOB_MESSAGE)
+      .bind(JobRunningHandler.class, ON_JOB_RUNNING)
+      .bind(JobCompletedHandler.class, ON_JOB_COMPLETED)
+      .bind(JobFailedHandler.class, ON_JOB_FAILED)
+      .bind(ResourceManagerErrorHandler.class, ON_RUNTIME_ERROR)
+      .bindNamedParameter(ClientPresent.class, ClientPresent.YES)
+      .bindNamedParameter(RemoteConfiguration.ErrorHandler.class, ON_WAKE_ERROR)
+      .build();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/client/CompletedJob.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/client/CompletedJob.java b/lang/java/reef-common/src/main/java/org/apache/reef/client/CompletedJob.java
new file mode 100644
index 0000000..5f763c2
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/client/CompletedJob.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.client;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.io.naming.Identifiable;
+
+/**
+ * Represents a completed REEF job.
+ */
+@Public
+@ClientSide
+@Provided
+public interface CompletedJob extends Identifiable {
+
+  /**
+   * @return the ID of the completed job.
+   */
+  @Override
+  public String getId();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/client/DriverConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/client/DriverConfiguration.java b/lang/java/reef-common/src/main/java/org/apache/reef/client/DriverConfiguration.java
new file mode 100644
index 0000000..5573fed
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/client/DriverConfiguration.java
@@ -0,0 +1,253 @@
+/**
+ * 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.reef.client;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ClosedContext;
+import org.apache.reef.driver.context.ContextMessage;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.CompletedEvaluator;
+import org.apache.reef.driver.evaluator.FailedEvaluator;
+import org.apache.reef.driver.parameters.*;
+import org.apache.reef.driver.task.*;
+import org.apache.reef.runtime.common.DriverRestartCompleted;
+import org.apache.reef.runtime.common.driver.DriverRuntimeConfiguration;
+import org.apache.reef.tang.formats.*;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.event.StartTime;
+import org.apache.reef.wake.time.event.StopTime;
+
+/**
+ * A ConfigurationModule for Drivers.
+ */
+@ClientSide
+@Public
+@Provided
+public final class DriverConfiguration extends ConfigurationModuleBuilder {
+
+  /**
+   * Identifies the driver and therefore the JOB. Expect to see this e.g. on YARN's dashboard.
+   */
+  public static final OptionalParameter<String> DRIVER_IDENTIFIER = new OptionalParameter<>();
+
+  /**
+   * The amount of memory to be allocated for the Driver. This is the size of the AM container in YARN.
+   */
+  public static final OptionalParameter<Integer> DRIVER_MEMORY = new OptionalParameter<>();
+
+  /**
+   * Files to be made available on the Driver and all Evaluators.
+   */
+  public static final OptionalParameter<String> GLOBAL_FILES = new OptionalParameter<>();
+
+  /**
+   * Libraries to be made available on the Driver and all Evaluators.
+   */
+  public static final OptionalParameter<String> GLOBAL_LIBRARIES = new OptionalParameter<>();
+
+  /**
+   * Files to be made available on the Driver only.
+   */
+  public static final OptionalParameter<String> LOCAL_FILES = new OptionalParameter<>();
+
+  /**
+   * Libraries to be made available on the Driver only.
+   */
+  public static final OptionalParameter<String> LOCAL_LIBRARIES = new OptionalParameter<>();
+
+  /**
+   * Job submission directory to be used by driver. This is the folder on the DFS used to stage the files
+   * for the Driver and subsequently for the Evaluators. It will be created if it doesn't exist yet.
+   * If this is set by the user, user must make sure its uniqueness across different jobs.
+   */
+  public static final OptionalParameter<String> DRIVER_JOB_SUBMISSION_DIRECTORY = new OptionalParameter<>();
+
+  /**
+   * The event handler invoked right after the driver boots up.
+   */
+  public static final RequiredImpl<EventHandler<StartTime>> ON_DRIVER_STARTED = new RequiredImpl<>();
+
+  /**
+   * This event is fired in place of the ON_DRIVER_STARTED when the Driver is in fact restarted after failure.
+   */
+  public static final OptionalImpl<EventHandler<StartTime>> ON_DRIVER_RESTARTED = new OptionalImpl<>();
+
+  /**
+   * The event handler invoked right before the driver shuts down. Defaults to ignore.
+   */
+  public static final OptionalImpl<EventHandler<StopTime>> ON_DRIVER_STOP = new OptionalImpl<>();
+
+  // ***** EVALUATOR HANDLER BINDINGS:
+
+  /**
+   * Event handler for allocated evaluators. Defaults to returning the evaluator if not bound.
+   */
+  public static final OptionalImpl<EventHandler<AllocatedEvaluator>> ON_EVALUATOR_ALLOCATED = new OptionalImpl<>();
+
+  /**
+   * Event handler for completed evaluators. Defaults to logging if not bound.
+   */
+  public static final OptionalImpl<EventHandler<CompletedEvaluator>> ON_EVALUATOR_COMPLETED = new OptionalImpl<>();
+
+  /**
+   * Event handler for failed evaluators. Defaults to job failure if not bound.
+   */
+  public static final OptionalImpl<EventHandler<FailedEvaluator>> ON_EVALUATOR_FAILED = new OptionalImpl<>();
+
+  // ***** TASK HANDLER BINDINGS:
+
+  /**
+   * Event handler for task messages. Defaults to logging if not bound.
+   */
+  public static final OptionalImpl<EventHandler<TaskMessage>> ON_TASK_MESSAGE = new OptionalImpl<>();
+
+  /**
+   * Event handler for completed tasks. Defaults to closing the context the task ran on if not bound.
+   */
+  public static final OptionalImpl<EventHandler<CompletedTask>> ON_TASK_COMPLETED = new OptionalImpl<>();
+
+  /**
+   * Event handler for failed tasks. Defaults to job failure if not bound.
+   */
+  public static final OptionalImpl<EventHandler<FailedTask>> ON_TASK_FAILED = new OptionalImpl<>();
+
+  /**
+   * Event handler for running tasks. Defaults to logging if not bound.
+   */
+  public static final OptionalImpl<EventHandler<RunningTask>> ON_TASK_RUNNING = new OptionalImpl<>();
+
+  /**
+   * Event handler for running tasks in previous evaluator, when driver restarted. Defaults to crash if not bound.
+   */
+  public static final OptionalImpl<EventHandler<RunningTask>> ON_DRIVER_RESTART_TASK_RUNNING = new OptionalImpl<>();
+
+  /**
+   * Event handler for suspended tasks. Defaults to job failure if not bound. Rationale: many jobs don't support
+   * task suspension. Hence, this parameter should be optional. The only sane default is to crash the job, then.
+   */
+  public static final OptionalImpl<EventHandler<SuspendedTask>> ON_TASK_SUSPENDED = new OptionalImpl<>();
+
+  // ***** CLIENT HANDLER BINDINGS:
+
+  /**
+   * Event handler for client messages. Defaults to logging if not bound.
+   */
+  public static final OptionalImpl<EventHandler<byte[]>> ON_CLIENT_MESSAGE = new OptionalImpl<>();
+
+  /**
+   * Event handler for close messages sent by the client. Defaults to job failure if not bound.
+   */
+  public static final OptionalImpl<EventHandler<Void>> ON_CLIENT_CLOSED = new OptionalImpl<>();
+
+  /**
+   * Event handler for close messages sent by the client. Defaults to job failure if not bound.
+   */
+  public static final OptionalImpl<EventHandler<byte[]>> ON_CLIENT_CLOSED_MESSAGE = new OptionalImpl<>();
+
+  // ***** CONTEXT HANDLER BINDINGS:
+
+  /**
+   * Event handler for active context. Defaults to closing the context if not bound.
+   */
+  public static final OptionalImpl<EventHandler<ActiveContext>> ON_CONTEXT_ACTIVE = new OptionalImpl<>();
+
+  /**
+   * Event handler for active context when driver restart. Defaults to closing the context if not bound.
+   */
+  public static final OptionalImpl<EventHandler<ActiveContext>> ON_DRIVER_RESTART_CONTEXT_ACTIVE = new OptionalImpl<>();
+
+  /**
+   * Event handler for closed context. Defaults to logging if not bound.
+   */
+  public static final OptionalImpl<EventHandler<ClosedContext>> ON_CONTEXT_CLOSED = new OptionalImpl<>();
+
+  /**
+   * Event handler for closed context. Defaults to job failure if not bound.
+   */
+  public static final OptionalImpl<EventHandler<FailedContext>> ON_CONTEXT_FAILED = new OptionalImpl<>();
+
+  /**
+   * Event handler for context messages. Defaults to logging if not bound.
+   */
+  public static final OptionalImpl<EventHandler<ContextMessage>> ON_CONTEXT_MESSAGE = new OptionalImpl<>();
+
+  /**
+   * "Number of threads allocated per evaluator to dispatch events from this Evaluator.
+   */
+  public static final OptionalParameter<Integer> EVALUATOR_DISPATCHER_THREADS = new OptionalParameter<>();
+
+  /**
+   * Event handler for the event of driver restart completion, default to logging if not bound.
+   */
+  public static final OptionalImpl<EventHandler<DriverRestartCompleted>> ON_DRIVER_RESTART_COMPLETED = new OptionalImpl<>();
+
+  /**
+   * ConfigurationModule to fill out to get a legal Driver Configuration.
+   */
+  public static final ConfigurationModule CONF = new DriverConfiguration().merge(DriverRuntimeConfiguration.CONF)
+
+      .bindNamedParameter(DriverIdentifier.class, DRIVER_IDENTIFIER)
+      .bindNamedParameter(DriverMemory.class, DRIVER_MEMORY)
+      .bindNamedParameter(DriverJobSubmissionDirectory.class, DRIVER_JOB_SUBMISSION_DIRECTORY)
+      .bindSetEntry(JobGlobalFiles.class, GLOBAL_FILES)
+      .bindSetEntry(JobGlobalLibraries.class, GLOBAL_LIBRARIES)
+      .bindSetEntry(DriverLocalFiles.class, LOCAL_FILES)
+      .bindSetEntry(DriverLocalLibraries.class, LOCAL_LIBRARIES)
+
+          // Driver start/stop handlers
+      .bindSetEntry(DriverStartHandler.class, ON_DRIVER_STARTED)
+      .bindNamedParameter(DriverRestartHandler.class, ON_DRIVER_RESTARTED)
+      .bindSetEntry(Clock.StartHandler.class, org.apache.reef.runtime.common.driver.DriverStartHandler.class)
+      .bindSetEntry(Clock.StopHandler.class, ON_DRIVER_STOP)
+
+          // Evaluator handlers
+      .bindSetEntry(EvaluatorAllocatedHandlers.class, ON_EVALUATOR_ALLOCATED)
+      .bindSetEntry(EvaluatorCompletedHandlers.class, ON_EVALUATOR_COMPLETED)
+      .bindSetEntry(EvaluatorFailedHandlers.class, ON_EVALUATOR_FAILED)
+
+          // Task handlers
+      .bindSetEntry(TaskRunningHandlers.class, ON_TASK_RUNNING)
+      .bindSetEntry(DriverRestartTaskRunningHandlers.class, ON_DRIVER_RESTART_TASK_RUNNING)
+      .bindSetEntry(TaskFailedHandlers.class, ON_TASK_FAILED)
+      .bindSetEntry(TaskMessageHandlers.class, ON_TASK_MESSAGE)
+      .bindSetEntry(TaskCompletedHandlers.class, ON_TASK_COMPLETED)
+      .bindSetEntry(TaskSuspendedHandlers.class, ON_TASK_SUSPENDED)
+
+          // Context handlers
+      .bindSetEntry(ContextActiveHandlers.class, ON_CONTEXT_ACTIVE)
+      .bindSetEntry(DriverRestartContextActiveHandlers.class, ON_DRIVER_RESTART_CONTEXT_ACTIVE)
+      .bindSetEntry(ContextClosedHandlers.class, ON_CONTEXT_CLOSED)
+      .bindSetEntry(ContextMessageHandlers.class, ON_CONTEXT_MESSAGE)
+      .bindSetEntry(ContextFailedHandlers.class, ON_CONTEXT_FAILED)
+
+          // Client handlers
+      .bindSetEntry(ClientMessageHandlers.class, ON_CLIENT_MESSAGE)
+      .bindSetEntry(ClientCloseHandlers.class, ON_CLIENT_CLOSED)
+      .bindSetEntry(ClientCloseWithMessageHandlers.class, ON_CLIENT_CLOSED_MESSAGE)
+
+          // Various parameters
+      .bindNamedParameter(EvaluatorDispatcherThreads.class, EVALUATOR_DISPATCHER_THREADS)
+      .bindSetEntry(DriverRestartCompletedHandlers.class, ON_DRIVER_RESTART_COMPLETED)
+      .build();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/client/DriverLauncher.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/client/DriverLauncher.java b/lang/java/reef-common/src/main/java/org/apache/reef/client/DriverLauncher.java
new file mode 100644
index 0000000..009fa24
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/client/DriverLauncher.java
@@ -0,0 +1,220 @@
+/**
+ * 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.reef.client;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A launcher for REEF Drivers.
+ * <p/>
+ * It can be instantiated using a configuration that can create a REEF instance.
+ * For example, the local resourcemanager and the YARN resourcemanager can do this.
+ * <p/>
+ * {@see org.apache.reef.examples.hello.HelloREEF} for a demo use case.
+ */
+@Public
+@Provided
+@ClientSide
+@Unit
+public final class DriverLauncher {
+
+  private static final Logger LOG = Logger.getLogger(DriverLauncher.class.getName());
+  private final REEF reef;
+  private LauncherStatus status = LauncherStatus.INIT;
+  private RunningJob theJob = null;
+
+  @Inject
+  private DriverLauncher(final REEF reef) {
+    this.reef = reef;
+  }
+
+  /**
+   * Instantiate a launcher for the given Configuration.
+   *
+   * @param runtimeConfiguration the resourcemanager configuration to be used
+   * @return a DriverLauncher based on the given resourcemanager configuration
+   * @throws BindException      on configuration errors
+   * @throws InjectionException on configuration errors
+   */
+  public static DriverLauncher getLauncher(
+      final Configuration runtimeConfiguration) throws BindException, InjectionException {
+
+    final Configuration clientConfiguration = ClientConfiguration.CONF
+        .set(ClientConfiguration.ON_JOB_RUNNING, RunningJobHandler.class)
+        .set(ClientConfiguration.ON_JOB_COMPLETED, CompletedJobHandler.class)
+        .set(ClientConfiguration.ON_JOB_FAILED, FailedJobHandler.class)
+        .set(ClientConfiguration.ON_RUNTIME_ERROR, RuntimeErrorHandler.class)
+        .build();
+
+    return Tang.Factory.getTang()
+        .newInjector(runtimeConfiguration, clientConfiguration)
+        .getInstance(DriverLauncher.class);
+  }
+
+  /**
+   * Kills the running job.
+   */
+  public synchronized void close() {
+    if (this.status.isRunning()) {
+      this.status = LauncherStatus.FORCE_CLOSED;
+    }
+    if (null != this.theJob) {
+      this.theJob.close();
+    }
+    this.notify();
+  }
+
+  /**
+   * Run a job. Waits indefinitely for the job to complete.
+   *
+   * @param driverConfig the configuration for the driver. See DriverConfiguration for details.
+   * @return the state of the job after execution.
+   */
+  public LauncherStatus run(final Configuration driverConfig) {
+    this.reef.submit(driverConfig);
+    synchronized (this) {
+      while (!this.status.isDone()) {
+        try {
+          LOG.log(Level.FINE, "Wait indefinitely");
+          this.wait();
+        } catch (final InterruptedException ex) {
+          LOG.log(Level.FINE, "Interrupted: {0}", ex);
+        }
+      }
+    }
+    this.reef.close();
+    return this.status;
+  }
+
+  /**
+   * Run a job with a waiting timeout after which it will be killed, if it did not complete yet.
+   *
+   * @param driverConfig the configuration for the driver. See DriverConfiguration for details.
+   * @param timeOut      timeout on the job.
+   * @return the state of the job after execution.
+   */
+  public LauncherStatus run(final Configuration driverConfig, final long timeOut) {
+    final long endTime = System.currentTimeMillis() + timeOut;
+    this.reef.submit(driverConfig);
+    synchronized (this) {
+      while (!this.status.isDone()) {
+        try {
+          final long waitTime = endTime - System.currentTimeMillis();
+          if (waitTime <= 0) {
+            break;
+          }
+          LOG.log(Level.FINE, "Wait for {0} milliSeconds", waitTime);
+          this.wait(waitTime);
+        } catch (final InterruptedException ex) {
+          LOG.log(Level.FINE, "Interrupted: {0}", ex);
+        }
+      }
+      if (System.currentTimeMillis() >= endTime) {
+        LOG.log(Level.WARNING, "The Job timed out.");
+        this.status = LauncherStatus.FORCE_CLOSED;
+      }
+    }
+
+    this.reef.close();
+    return this.status;
+  }
+
+  /**
+   * @return the current status of the job.
+   */
+  public LauncherStatus getStatus() {
+    return this.status;
+  }
+
+  /**
+   * Update job status and notify the waiting thread.
+   */
+  public synchronized void setStatusAndNotify(final LauncherStatus status) {
+    LOG.log(Level.FINEST, "Set status: {0} -> {1}", new Object[]{this.status, status});
+    this.status = status;
+    this.notify();
+  }
+
+  @Override
+  public String toString() {
+    return this.status.toString();
+  }
+
+  /**
+   * Job driver notifies us that the job is running.
+   */
+  public final class RunningJobHandler implements EventHandler<RunningJob> {
+    @Override
+    public void onNext(final RunningJob job) {
+      LOG.log(Level.INFO, "The Job {0} is running.", job.getId());
+      theJob = job;
+      setStatusAndNotify(LauncherStatus.RUNNING);
+    }
+  }
+
+  /**
+   * Job driver notifies us that the job had failed.
+   */
+  public final class FailedJobHandler implements EventHandler<FailedJob> {
+    @Override
+    public void onNext(final FailedJob job) {
+      final Optional<Throwable> ex = job.getReason();
+      LOG.log(Level.SEVERE, "Received an error for job " + job.getId(), ex);
+      theJob = null;
+      setStatusAndNotify(LauncherStatus.FAILED(ex));
+    }
+  }
+
+  /**
+   * Job driver notifies us that the job had completed successfully.
+   */
+  public final class CompletedJobHandler implements EventHandler<CompletedJob> {
+    @Override
+    public void onNext(final CompletedJob job) {
+      LOG.log(Level.INFO, "The Job {0} is done.", job.getId());
+      theJob = null;
+      setStatusAndNotify(LauncherStatus.COMPLETED);
+    }
+  }
+
+  /**
+   * Handler an error in the job driver.
+   */
+  public final class RuntimeErrorHandler implements EventHandler<FailedRuntime> {
+    @Override
+    public void onNext(final FailedRuntime error) {
+      LOG.log(Level.SEVERE, "Received a resourcemanager error", error.getReason());
+      theJob = null;
+      setStatusAndNotify(LauncherStatus.FAILED(error.getReason()));
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/client/DriverServiceConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/client/DriverServiceConfiguration.java b/lang/java/reef-common/src/main/java/org/apache/reef/client/DriverServiceConfiguration.java
new file mode 100644
index 0000000..4cf452e
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/client/DriverServiceConfiguration.java
@@ -0,0 +1,196 @@
+/**
+ * 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.reef.client;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ClosedContext;
+import org.apache.reef.driver.context.ContextMessage;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.CompletedEvaluator;
+import org.apache.reef.driver.evaluator.FailedEvaluator;
+import org.apache.reef.driver.parameters.*;
+import org.apache.reef.driver.task.*;
+import org.apache.reef.tang.formats.*;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.event.StartTime;
+import org.apache.reef.wake.time.event.StopTime;
+
+/**
+ * Use this ConfigurationModule to configure Services to be run in the Driver.
+ * <p/>
+ * A service is a set of event handlers that are informed of events in addition to * the event handlers defined in
+ * DriverConfiguration. However, most services will treat the events as read-only. Doing differently should be
+ * documented clearly in the Service documentation.
+ */
+@ClientSide
+@Public
+@Provided
+public final class DriverServiceConfiguration extends ConfigurationModuleBuilder {
+
+
+  /**
+   * Files to be made available on the Driver and all Evaluators.
+   */
+  public static final OptionalParameter<String> GLOBAL_FILES = new OptionalParameter<>();
+
+  /**
+   * Libraries to be made available on the Driver and all Evaluators.
+   */
+  public static final OptionalParameter<String> GLOBAL_LIBRARIES = new OptionalParameter<>();
+
+  /**
+   * Files to be made available on the Driver only.
+   */
+  public static final OptionalParameter<String> LOCAL_FILES = new OptionalParameter<>();
+
+  /**
+   * Libraries to be made available on the Driver only.
+   */
+  public static final OptionalParameter<String> LOCAL_LIBRARIES = new OptionalParameter<>();
+
+  /**
+   * The event handler invoked right after the driver boots up.
+   */
+  public static final RequiredImpl<EventHandler<StartTime>> ON_DRIVER_STARTED = new RequiredImpl<>();
+
+  /**
+   * The event handler invoked right before the driver shuts down. Defaults to ignore.
+   */
+  public static final OptionalImpl<EventHandler<StopTime>> ON_DRIVER_STOP = new OptionalImpl<>();
+
+  // ***** EVALUATOR HANDLER BINDINGS:
+
+  /**
+   * Event handler for allocated evaluators. Defaults to returning the evaluator if not bound.
+   */
+  public static final OptionalImpl<EventHandler<AllocatedEvaluator>> ON_EVALUATOR_ALLOCATED = new OptionalImpl<>();
+
+  /**
+   * Event handler for completed evaluators. Defaults to logging if not bound.
+   */
+  public static final OptionalImpl<EventHandler<CompletedEvaluator>> ON_EVALUATOR_COMPLETED = new OptionalImpl<>();
+
+  /**
+   * Event handler for failed evaluators. Defaults to job failure if not bound.
+   */
+  public static final OptionalImpl<EventHandler<FailedEvaluator>> ON_EVALUATOR_FAILED = new OptionalImpl<>();
+
+  // ***** TASK HANDLER BINDINGS:
+
+  /**
+   * Event handler for task messages. Defaults to logging if not bound.
+   */
+  public static final OptionalImpl<EventHandler<TaskMessage>> ON_TASK_MESSAGE = new OptionalImpl<>();
+
+  /**
+   * Event handler for completed tasks. Defaults to closing the context the task ran on if not bound.
+   */
+  public static final OptionalImpl<EventHandler<CompletedTask>> ON_TASK_COMPLETED = new OptionalImpl<>();
+
+  /**
+   * Event handler for failed tasks. Defaults to job failure if not bound.
+   */
+  public static final OptionalImpl<EventHandler<FailedTask>> ON_TASK_FAILED = new OptionalImpl<>();
+
+  /**
+   * Event handler for running tasks. Defaults to logging if not bound.
+   */
+  public static final OptionalImpl<EventHandler<RunningTask>> ON_TASK_RUNNING = new OptionalImpl<>();
+
+  /**
+   * Event handler for running tasks in previous evaluator, when driver restarted. Defaults to logging if not bound.
+   */
+  public static final OptionalImpl<EventHandler<RunningTask>> ON_DRIVER_RESTART_TASK_RUNNING = new OptionalImpl<>();
+
+  /**
+   * Event handler for suspended tasks. Defaults to job failure if not bound. Rationale: many jobs don't support
+   * task suspension. Hence, this parameter should be optional. The only sane default is to crash the job, then.
+   */
+  public static final OptionalImpl<EventHandler<SuspendedTask>> ON_TASK_SUSPENDED = new OptionalImpl<>();
+
+
+  // ***** CONTEXT HANDLER BINDINGS:
+
+  /**
+   * Event handler for active context. Defaults to closing the context if not bound.
+   */
+  public static final OptionalImpl<EventHandler<ActiveContext>> ON_CONTEXT_ACTIVE = new OptionalImpl<>();
+
+  /**
+   * Event handler for active context when driver restart. Defaults to closing the context if not bound.
+   */
+  public static final OptionalImpl<EventHandler<ActiveContext>> ON_DRIVER_RESTART_CONTEXT_ACTIVE = new OptionalImpl<>();
+
+  /**
+   * Event handler for closed context. Defaults to logging if not bound.
+   */
+  public static final OptionalImpl<EventHandler<ClosedContext>> ON_CONTEXT_CLOSED = new OptionalImpl<>();
+
+  /**
+   * Event handler for closed context. Defaults to job failure if not bound.
+   */
+  public static final OptionalImpl<EventHandler<FailedContext>> ON_CONTEXT_FAILED = new OptionalImpl<>();
+
+  /**
+   * Event handler for context messages. Defaults to logging if not bound.
+   */
+  public static final OptionalImpl<EventHandler<ContextMessage>> ON_CONTEXT_MESSAGE = new OptionalImpl<>();
+
+
+  /**
+   * ConfigurationModule to fill out to get a legal Driver Configuration.
+   */
+  public static final ConfigurationModule CONF = new DriverServiceConfiguration()
+      // Files use the very same named parameters as the DriverConfiguration
+      .bindSetEntry(JobGlobalFiles.class, GLOBAL_FILES)
+      .bindSetEntry(JobGlobalLibraries.class, GLOBAL_LIBRARIES)
+      .bindSetEntry(DriverLocalFiles.class, LOCAL_FILES)
+      .bindSetEntry(DriverLocalLibraries.class, LOCAL_LIBRARIES)
+
+          // Start and stop events are the same handlers for applications and services.
+      .bindSetEntry(Clock.StartHandler.class, ON_DRIVER_STARTED)
+      .bindSetEntry(Clock.StopHandler.class, ON_DRIVER_STOP)
+
+          // Evaluator handlers
+      .bindSetEntry(ServiceEvaluatorAllocatedHandlers.class, ON_EVALUATOR_ALLOCATED)
+      .bindSetEntry(ServiceEvaluatorCompletedHandlers.class, ON_EVALUATOR_COMPLETED)
+      .bindSetEntry(ServiceEvaluatorFailedHandlers.class, ON_EVALUATOR_FAILED)
+
+          // Task handlers
+      .bindSetEntry(ServiceTaskRunningHandlers.class, ON_TASK_RUNNING)
+      .bindSetEntry(DriverRestartTaskRunningHandlers.class, ON_DRIVER_RESTART_TASK_RUNNING)
+      .bindSetEntry(ServiceTaskFailedHandlers.class, ON_TASK_FAILED)
+      .bindSetEntry(ServiceTaskMessageHandlers.class, ON_TASK_MESSAGE)
+      .bindSetEntry(ServiceTaskCompletedHandlers.class, ON_TASK_COMPLETED)
+      .bindSetEntry(ServiceTaskSuspendedHandlers.class, ON_TASK_SUSPENDED)
+
+          // Context handlers
+      .bindSetEntry(ServiceContextActiveHandlers.class, ON_CONTEXT_ACTIVE)
+      .bindSetEntry(DriverRestartContextActiveHandlers.class, ON_DRIVER_RESTART_CONTEXT_ACTIVE)
+      .bindSetEntry(ServiceContextClosedHandlers.class, ON_CONTEXT_CLOSED)
+      .bindSetEntry(ServiceContextMessageHandlers.class, ON_CONTEXT_MESSAGE)
+      .bindSetEntry(ServiceContextFailedHandlers.class, ON_CONTEXT_FAILED)
+
+      .build();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/client/FailedJob.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/client/FailedJob.java b/lang/java/reef-common/src/main/java/org/apache/reef/client/FailedJob.java
new file mode 100644
index 0000000..06757ce
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/client/FailedJob.java
@@ -0,0 +1,48 @@
+/**
+ * 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.reef.client;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.common.AbstractFailure;
+import org.apache.reef.util.Optional;
+
+/**
+ * An error message that REEF Client receives when there is a user error in REEF job.
+ */
+@Public
+@ClientSide
+@Provided
+public final class FailedJob extends AbstractFailure {
+  /**
+   * @param id          Identifier of the Job that produced the error.
+   * @param message     One-line error message.
+   * @param description Long error description.
+   * @param cause       Java Exception that caused the error.
+   * @param data        byte array that contains serialized version of the error.
+   */
+  public FailedJob(final String id,
+                   final String message,
+                   final Optional<String> description,
+                   final Optional<Throwable> cause,
+                   final Optional<byte[]> data) {
+    super(id, message, description, cause, data);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/client/FailedRuntime.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/client/FailedRuntime.java b/lang/java/reef-common/src/main/java/org/apache/reef/client/FailedRuntime.java
new file mode 100644
index 0000000..8cae76f
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/client/FailedRuntime.java
@@ -0,0 +1,82 @@
+/**
+ * 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.reef.client;
+
+import org.apache.reef.common.AbstractFailure;
+import org.apache.reef.proto.ReefServiceProtos.RuntimeErrorProto;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Error message that REEF Client gets when there is an error in REEF resourcemanager.
+ */
+public final class FailedRuntime extends AbstractFailure {
+
+  /**
+   * Standard java logger.
+   */
+  private static final Logger LOG = Logger.getLogger(AbstractFailure.class.getName());
+
+  /**
+   * Codec to decode serialized exception from a byte array. It is used in getThrowable().
+   */
+  private static final ObjectSerializableCodec<Exception> CODEC = new ObjectSerializableCodec<>();
+
+  /**
+   * Create a new Failure object out of protobuf data.
+   *
+   * @param error Error message as a protocol buffers object.
+   */
+  public FailedRuntime(final RuntimeErrorProto error) {
+    super(error.getIdentifier(), error.getMessage(), Optional.<String>empty(), Optional.of(getThrowable(error)), Optional.<byte[]>empty());
+  }
+
+  /**
+   * Retrieve Java exception from protobuf object, if possible. Otherwise, return null.
+   * This is a utility method used in the FailedRuntime constructor.
+   *
+   * @param error protobuf error message structure.
+   * @return Java exception or null if exception is missing or cannot be decoded.
+   */
+  private static Throwable getThrowable(final RuntimeErrorProto error) {
+    final byte[] data = getData(error);
+    if (data != null) {
+      try {
+        return CODEC.decode(data);
+      } catch (final Throwable ex) {
+        LOG.log(Level.FINE, "Could not decode exception {0}: {1}", new Object[]{error, ex});
+      }
+    }
+    return null;
+  }
+
+  /**
+   * Get binary data for the exception, if it exists. Otherwise, return null.
+   * This is a utility method used in the FailedRuntime constructor and getThrowable() method.
+   *
+   * @param error protobuf error message structure.
+   * @return byte array of the exception or null if exception is missing.
+   */
+  private static byte[] getData(final RuntimeErrorProto error) {
+    return error.hasException() ? error.getException().toByteArray() : null;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/client/JobMessage.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/client/JobMessage.java b/lang/java/reef-common/src/main/java/org/apache/reef/client/JobMessage.java
new file mode 100644
index 0000000..ea929b9
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/client/JobMessage.java
@@ -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.reef.client;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.io.Message;
+import org.apache.reef.io.naming.Identifiable;
+
+/**
+ * A message received by the client from the driver.
+ */
+@Public
+@ClientSide
+@Provided
+public final class JobMessage implements Message, Identifiable {
+
+  private final String id;
+  private final byte[] value;
+
+  /**
+   * @param id    the identifier of the sending Job
+   * @param value the message
+   */
+  public JobMessage(final String id, final byte[] value) {
+    this.id = id;
+    this.value = value;
+  }
+
+  /**
+   * Get the message sent by the Job.
+   *
+   * @return the message sent by the Job.
+   */
+  @Override
+  public final byte[] get() {
+    return this.value;
+  }
+
+  /**
+   * Get the Identifier of the sending Job.
+   *
+   * @return the Identifier of the sending Job.
+   */
+  @Override
+  public final String getId() {
+    return this.id;
+  }
+
+  @Override
+  public String toString() {
+    return "JobMessage{" +
+        "id='" + id + '\'' +
+        ", value.length=" + value.length +
+        '}';
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/client/LauncherStatus.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/client/LauncherStatus.java b/lang/java/reef-common/src/main/java/org/apache/reef/client/LauncherStatus.java
new file mode 100644
index 0000000..b35a008
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/client/LauncherStatus.java
@@ -0,0 +1,123 @@
+/**
+ * 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.reef.client;
+
+import org.apache.reef.util.Optional;
+
+/**
+ * The status of a reef job spawned using the DriverLauncher class.
+ */
+public final class LauncherStatus {
+
+  public static final LauncherStatus INIT = new LauncherStatus(State.INIT);
+  public static final LauncherStatus RUNNING = new LauncherStatus(State.RUNNING);
+  public static final LauncherStatus COMPLETED = new LauncherStatus(State.COMPLETED);
+  public static final LauncherStatus FORCE_CLOSED = new LauncherStatus(State.FORCE_CLOSED);
+  public static final LauncherStatus FAILED = new LauncherStatus(State.FAILED);
+  private final State state;
+  private final Optional<Throwable> error;
+
+  private LauncherStatus(final State state) {
+    this(state, null);
+  }
+
+
+  private LauncherStatus(final State state, final Throwable ex) {
+    this.state = state;
+    this.error = Optional.ofNullable(ex);
+  }
+
+  public static final LauncherStatus FAILED(final Throwable ex) {
+    return new LauncherStatus(State.FAILED, ex);
+  }
+
+  public static final LauncherStatus FAILED(final Optional<Throwable> ex) {
+    return new LauncherStatus(State.FAILED, ex.orElse(null));
+  }
+
+  public Optional<Throwable> getError() {
+    return this.error;
+  }
+
+  /**
+   * Compare the <b>State</b> of two LauncherStatus objects.
+   * Note that it does NOT compare the exceptions - just the states.
+   *
+   * @return True if both LauncherStatus objects are in the same state.
+   */
+  @Override
+  public boolean equals(final Object other) {
+    return this == other ||
+        (other instanceof LauncherStatus && ((LauncherStatus) other).state == this.state);
+  }
+
+  /**
+   * Has the job completed?
+   *
+   * @return True if the job has been completed, false otherwise.
+   */
+  public final boolean isDone() {
+    switch (this.state) {
+      case FAILED:
+      case COMPLETED:
+      case FORCE_CLOSED:
+        return true;
+      default:
+        return false;
+    }
+  }
+
+  /**
+   * Has the job completed successfully?
+   *
+   * @return True if the job has been completed successfully, false otherwise.
+   */
+  public final boolean isSuccess() {
+    return this.state == State.COMPLETED;
+  }
+
+  /**
+   * Is the job still running?
+   *
+   * @return True if the job is still running, false otherwise.
+   */
+  public final boolean isRunning() {
+    return this.state == State.RUNNING;
+  }
+
+  @Override
+  public String toString() {
+    if (this.error.isPresent()) {
+      return this.state + "(" + this.error.get() + ")";
+    } else {
+      return this.state.toString();
+    }
+  }
+
+  /**
+   * The state the computation could be in.
+   */
+  private enum State {
+    INIT,
+    RUNNING,
+    COMPLETED,
+    FAILED,
+    FORCE_CLOSED
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/client/REEF.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/client/REEF.java b/lang/java/reef-common/src/main/java/org/apache/reef/client/REEF.java
new file mode 100644
index 0000000..5a783f0
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/client/REEF.java
@@ -0,0 +1,55 @@
+/**
+ * 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.reef.client;
+
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.runtime.common.client.REEFImplementation;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.DefaultImplementation;
+
+/**
+ * The main entry point into the REEF resourcemanager.
+ * <p/>
+ * Every REEF resourcemanager provides an implementation of this interface. That
+ * instance is used to submitTask the Driver class for execution to REEF. As with
+ * all submissions in REEF, this is done in the form of a TANG Configuration
+ * object.
+ */
+@Public
+@ClientSide
+@DefaultImplementation(REEFImplementation.class)
+public interface REEF extends AutoCloseable {
+
+  /**
+   * Close the resourcemanager connection.
+   */
+  @Override
+  public void close();
+
+  /**
+   * Submits the Driver set up in the given Configuration for execution.
+   * <p/>
+   * The Configuration needs to bind the Driver interface to an actual
+   * implementation of that interface for the job at hand.
+   *
+   * @param driverConf The driver configuration: including everything it needs to execute.  @see DriverConfiguration
+   */
+  public void submit(final Configuration driverConf);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/client/RunningJob.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/client/RunningJob.java b/lang/java/reef-common/src/main/java/org/apache/reef/client/RunningJob.java
new file mode 100644
index 0000000..f29cb32
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/client/RunningJob.java
@@ -0,0 +1,62 @@
+/**
+ * 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.reef.client;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.io.naming.Identifiable;
+import org.apache.reef.runtime.common.client.RunningJobImpl;
+import org.apache.reef.tang.annotations.DefaultImplementation;
+
+/**
+ * Represents a running REEF job.
+ */
+@Public
+@ClientSide
+@Provided
+@DefaultImplementation(RunningJobImpl.class)
+public interface RunningJob extends Identifiable, AutoCloseable {
+
+  /**
+   * Cancels the running Job.
+   */
+  @Override
+  public void close();
+
+  /**
+   * Cancels the running Job.
+   *
+   * @param message delivered along with cancel request.
+   */
+  public void close(final byte[] message);
+
+  /**
+   * @return the ID of the running job.
+   */
+  @Override
+  public String getId();
+
+  /**
+   * Send a message to the Driver.
+   *
+   * @param message to send to the running driver
+   */
+  public void send(final byte[] message);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/client/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/client/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/client/package-info.java
new file mode 100644
index 0000000..9962aa0
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/client/package-info.java
@@ -0,0 +1,23 @@
+/**
+ * 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.
+ */
+/**
+ * Client APIs for REEF. A Client in REEF is the program that submits a Driver to a resource manager.
+ * This submission is done via the REEF.submit() method which accepts a Driver Configuration.
+ */
+package org.apache.reef.client;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/JobCompletedHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/JobCompletedHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/JobCompletedHandler.java
new file mode 100644
index 0000000..3367ae0
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/JobCompletedHandler.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.client.parameters;
+
+import org.apache.reef.client.CompletedJob;
+import org.apache.reef.runtime.common.client.defaults.DefaultCompletedJobHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ * Event handler for CompletedJob
+ */
+@NamedParameter(doc = "Event handler for CompletedJob",
+    default_classes = DefaultCompletedJobHandler.class)
+public final class JobCompletedHandler implements Name<EventHandler<CompletedJob>> {
+  private JobCompletedHandler() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/JobFailedHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/JobFailedHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/JobFailedHandler.java
new file mode 100644
index 0000000..7dd186c
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/JobFailedHandler.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.client.parameters;
+
+import org.apache.reef.client.FailedJob;
+import org.apache.reef.runtime.common.client.defaults.DefaultFailedJobHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ * Client EventHandler triggered on remote job failure.
+ */
+@NamedParameter(doc = "Client EventHandler triggered on remote job failure.",
+    default_classes = DefaultFailedJobHandler.class)
+public final class JobFailedHandler implements Name<EventHandler<FailedJob>> {
+  private JobFailedHandler() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/JobMessageHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/JobMessageHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/JobMessageHandler.java
new file mode 100644
index 0000000..7d0942c
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/JobMessageHandler.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.client.parameters;
+
+import org.apache.reef.client.JobMessage;
+import org.apache.reef.runtime.common.client.defaults.DefaultJobMessageHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ * Client EventHandler that gets messages from the Driver.
+ */
+@NamedParameter(doc = "Client EventHandler that gets messages from the Driver.",
+    default_classes = DefaultJobMessageHandler.class)
+public final class JobMessageHandler implements Name<EventHandler<JobMessage>> {
+  private JobMessageHandler() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/JobRunningHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/JobRunningHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/JobRunningHandler.java
new file mode 100644
index 0000000..1de835c
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/client/parameters/JobRunningHandler.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.client.parameters;
+
+import org.apache.reef.client.RunningJob;
+import org.apache.reef.runtime.common.client.defaults.DefaultRunningJobHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ * Client EventHandler triggered when the REEF job is running.
+ */
+@NamedParameter(doc = "Client EventHandler triggered when the REEF job is running.",
+    default_classes = DefaultRunningJobHandler.class)
+public final class JobRunningHandler implements Name<EventHandler<RunningJob>> {
+  private JobRunningHandler() {
+  }
+}


[51/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
[REEF-93] Move java sources to lang/java

This moves all current Java code to the new folder lang/java.

JIRA: [REEF-93]: https://issues.apache.org/jira/browse/REEF-93

Pull Request: This closes #53


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

Branch: refs/heads/master
Commit: 53ea32cce6cf4649315febaf27d71acda3b632d2
Parents: c908a52
Author: Julia Wang <ju...@microsoft.com>
Authored: Tue Jan 20 16:58:25 2015 -0800
Committer: Markus Weimer <we...@apache.org>
Committed: Thu Jan 22 15:44:12 2015 -0800

----------------------------------------------------------------------
 lang/java/pom.xml                               |  656 +++++++++
 lang/java/reef-annotations/pom.xml              |   31 +
 .../org/apache/reef/annotations/Optional.java   |   26 +
 .../org/apache/reef/annotations/Provided.java   |   26 +
 .../org/apache/reef/annotations/Unstable.java   |   25 +
 .../reef/annotations/audience/ClientSide.java   |   26 +
 .../reef/annotations/audience/DriverSide.java   |   26 +
 .../annotations/audience/EvaluatorSide.java     |   25 +
 .../reef/annotations/audience/Private.java      |   26 +
 .../reef/annotations/audience/Public.java       |   26 +
 .../annotations/audience/RuntimeAuthor.java     |   26 +
 .../reef/annotations/audience/TaskSide.java     |   26 +
 .../reef/annotations/audience/package-info.java |   22 +
 .../apache/reef/annotations/package-info.java   |   22 +
 .../reef/annotations/semantics/Idempotent.java  |   25 +
 lang/java/reef-bridge-project/.gitignore        |   34 +
 lang/java/reef-bridge-project/pom.xml           |  101 ++
 .../reef-bridge-project/reef-bridge-clr/pom.xml |  162 +++
 .../CSharp/CSharp/ClrHandler/ClrHandler.csproj  |   66 +
 .../ClrHandler/Properties/AssemblyInfo.cs       |   49 +
 .../externals/Microsoft.Reef.Driver.dll         |  Bin 0 -> 123392 bytes
 .../CSharp/ClrHandler/externals/msvcr110.dll    |  Bin 0 -> 849360 bytes
 .../ClrHandler/interface/IInteropReturnInfo.cs  |   30 +
 .../CSharp/ClrHandler/interface/ILogger.cs      |   37 +
 .../JavaClrBridge/ActiveContextClr2Java.cpp     |  106 ++
 .../AllocatedEvaluatorClr2Java.cpp              |  164 +++
 .../CppBridge/JavaClrBridge/AssemblyInfo.cpp    |   50 +
 .../CppBridge/JavaClrBridge/AssemblyUtil.cpp    |   53 +
 .../Cpp/CppBridge/JavaClrBridge/BinaryUtil.cpp  |  102 ++
 .../Cpp/CppBridge/JavaClrBridge/BinaryUtil.h    |   26 +
 .../JavaClrBridge/ClosedContextClr2Java.cpp     |   86 ++
 .../CppBridge/JavaClrBridge/Clr2JavaImpl.cpp    |   44 +
 .../Cpp/CppBridge/JavaClrBridge/Clr2JavaImpl.h  |  220 +++
 .../CppBridge/JavaClrBridge/CommonUtilities.cpp |   51 +
 .../CompletedEvaluatorClr2Java.cpp              |   58 +
 .../JavaClrBridge/CompletedTaskClr2Java.cpp     |   69 +
 .../JavaClrBridge/ContextMessageClr2Java.cpp    |   76 +
 .../EvaluatorRequestorClr2Java.cpp              |   69 +
 .../JavaClrBridge/FailedContextClr2Java.cpp     |   94 ++
 .../JavaClrBridge/FailedEvaluatorClr2Java.cpp   |   72 +
 .../JavaClrBridge/FailedTaskClr2Java.cpp        |   79 +
 .../JavaClrBridge/HttpServerClr2Java.cpp        |  135 ++
 .../CppBridge/JavaClrBridge/InteropAssemblies.h |   40 +
 .../CppBridge/JavaClrBridge/InteropLogger.cpp   |   50 +
 .../Cpp/CppBridge/JavaClrBridge/InteropLogger.h |   47 +
 .../JavaClrBridge/InteropReturnInfo.cpp         |   91 ++
 .../CppBridge/JavaClrBridge/InteropReturnInfo.h |   57 +
 .../Cpp/CppBridge/JavaClrBridge/InteropUtil.cpp |  129 ++
 .../Cpp/CppBridge/JavaClrBridge/InteropUtil.h   |   65 +
 .../CppBridge/JavaClrBridge/JavaClrBridge.cpp   |  492 +++++++
 .../Cpp/CppBridge/JavaClrBridge/JavaClrBridge.h |   33 +
 .../CppBridge/JavaClrBridge/JavaClrBridge.sln   |   56 +
 .../JavaClrBridge/JavaClrBridge.vcxproj         |  173 +++
 .../JavaClrBridge/JavaClrBridge.vcxproj.filters |  104 ++
 .../CppBridge/JavaClrBridge/ManagedLogger.cpp   |   47 +
 .../main/Cpp/CppBridge/JavaClrBridge/ReadMe.txt |   57 +
 .../JavaClrBridge/RunningTaskClr2Java.cpp       |   90 ++
 .../JavaClrBridge/SuspendedTaskClr2Java.cpp     |   83 ++
 .../JavaClrBridge/TaskMessageClr2Java.cpp       |   58 +
 .../reef-bridge-java/pom.xml                    |  116 ++
 .../reef/javabridge/ActiveContextBridge.java    |   80 ++
 .../javabridge/AllocatedEvaluatorBridge.java    |  141 ++
 .../reef/javabridge/ClosedContextBridge.java    |   81 ++
 .../javabridge/CompletedEvaluatorBridge.java    |   43 +
 .../reef/javabridge/CompletedTaskBridge.java    |   40 +
 .../reef/javabridge/ContextMessageBridge.java   |   56 +
 .../javabridge/EvaluatorRequestorBridge.java    |   76 +
 .../reef/javabridge/FailedContextBridge.java    |   83 ++
 .../reef/javabridge/FailedEvaluatorBridge.java  |   47 +
 .../reef/javabridge/FailedTaskBridge.java       |   60 +
 .../reef/javabridge/HttpServerEventBridge.java  |   79 +
 .../apache/reef/javabridge/InteropLogger.java   |   55 +
 .../reef/javabridge/InteropReturnInfo.java      |   52 +
 .../org/apache/reef/javabridge/JavaBridge.java  |   31 +
 .../org/apache/reef/javabridge/LibLoader.java   |  154 ++
 .../apache/reef/javabridge/NativeBridge.java    |   32 +
 .../apache/reef/javabridge/NativeInterop.java   |  166 +++
 .../reef/javabridge/RunningTaskBridge.java      |   49 +
 .../reef/javabridge/SuspendedTaskBridge.java    |   54 +
 .../reef/javabridge/TaskMessageBridge.java      |   36 +
 .../org/apache/reef/javabridge/Utilities.java   |   57 +
 .../reef/javabridge/generic/JobClient.java      |  322 +++++
 .../reef/javabridge/generic/JobDriver.java      |  724 ++++++++++
 .../apache/reef/javabridge/generic/Launch.java  |  236 +++
 .../reef/javabridge/generic/LaunchHeadless.java |  100 ++
 .../reef/javabridge/generic/package-info.java   |   22 +
 .../util/logging/CLRBufferedLogHandler.java     |  167 +++
 .../reef/util/logging/CLRLoggingConfig.java     |   31 +
 .../apache/reef/util/logging/package-info.java  |   22 +
 .../org/apache/reef/clr.logging.properties      |   82 ++
 .../reef-bridge-project/reef-bridge/pom.xml     |  111 ++
 lang/java/reef-checkpoint/maven-eclipse.xml     |   28 +
 lang/java/reef-checkpoint/pom.xml               |   68 +
 .../apache/reef/io/checkpoint/CheckpointID.java |   31 +
 .../io/checkpoint/CheckpointNamingService.java  |   33 +
 .../reef/io/checkpoint/CheckpointService.java   |  100 ++
 .../reef/io/checkpoint/RandomNameCNS.java       |   49 +
 .../reef/io/checkpoint/SimpleNamingService.java |   55 +
 .../fs/FSCheckPointServiceConfiguration.java    |  110 ++
 .../reef/io/checkpoint/fs/FSCheckpointID.java   |   74 +
 .../io/checkpoint/fs/FSCheckpointService.java   |  221 +++
 lang/java/reef-common/maven-eclipse.xml         |   28 +
 lang/java/reef-common/pom.xml                   |  142 ++
 .../reef-common/src/main/conf/log4j.properties  |   40 +
 .../reef-common/src/main/conf/reef-site.xml     |   21 +
 .../apache/reef/client/ClientConfiguration.java |   83 ++
 .../org/apache/reef/client/CompletedJob.java    |   39 +
 .../apache/reef/client/DriverConfiguration.java |  253 ++++
 .../org/apache/reef/client/DriverLauncher.java  |  220 +++
 .../reef/client/DriverServiceConfiguration.java |  196 +++
 .../java/org/apache/reef/client/FailedJob.java  |   48 +
 .../org/apache/reef/client/FailedRuntime.java   |   82 ++
 .../java/org/apache/reef/client/JobMessage.java |   74 +
 .../org/apache/reef/client/LauncherStatus.java  |  123 ++
 .../main/java/org/apache/reef/client/REEF.java  |   55 +
 .../java/org/apache/reef/client/RunningJob.java |   62 +
 .../org/apache/reef/client/package-info.java    |   23 +
 .../client/parameters/JobCompletedHandler.java  |   35 +
 .../client/parameters/JobFailedHandler.java     |   35 +
 .../client/parameters/JobMessageHandler.java    |   35 +
 .../client/parameters/JobRunningHandler.java    |   35 +
 .../parameters/ResourceManagerErrorHandler.java |   35 +
 .../reef/client/parameters/package-info.java    |   22 +
 .../org/apache/reef/common/AbstractFailure.java |  151 ++
 .../java/org/apache/reef/common/Failure.java    |   58 +
 .../reef/driver/ContextAndTaskSubmittable.java  |   64 +
 .../apache/reef/driver/ContextSubmittable.java  |   49 +
 .../reef/driver/FlexiblePreemptionEvent.java    |   47 +
 .../org/apache/reef/driver/PreemptionEvent.java |   47 +
 .../apache/reef/driver/PreemptionHandler.java   |   36 +
 .../reef/driver/StrictPreemptionEvent.java      |   37 +
 .../org/apache/reef/driver/TaskSubmittable.java |   40 +
 .../reef/driver/catalog/NodeDescriptor.java     |   42 +
 .../reef/driver/catalog/RackDescriptor.java     |   35 +
 .../reef/driver/catalog/ResourceCatalog.java    |   65 +
 .../reef/driver/client/JobMessageObserver.java  |   44 +
 .../apache/reef/driver/client/package-info.java |   25 +
 .../reef/driver/context/ActiveContext.java      |   71 +
 .../reef/driver/context/ClosedContext.java      |   37 +
 .../apache/reef/driver/context/ContextBase.java |   56 +
 .../driver/context/ContextConfiguration.java    |  109 ++
 .../reef/driver/context/ContextMessage.java     |   52 +
 .../reef/driver/context/FailedContext.java      |   44 +
 .../driver/context/ServiceConfiguration.java    |   79 +
 .../driver/evaluator/AllocatedEvaluator.java    |  101 ++
 .../driver/evaluator/CompletedEvaluator.java    |   33 +
 .../driver/evaluator/EvaluatorDescriptor.java   |   47 +
 .../reef/driver/evaluator/EvaluatorRequest.java |  171 +++
 .../driver/evaluator/EvaluatorRequestor.java    |   38 +
 .../reef/driver/evaluator/EvaluatorType.java    |   38 +
 .../reef/driver/evaluator/FailedEvaluator.java  |   55 +
 .../org/apache/reef/driver/package-info.java    |   22 +
 .../driver/parameters/ClientCloseHandlers.java  |   35 +
 .../ClientCloseWithMessageHandlers.java         |   35 +
 .../parameters/ClientMessageHandlers.java       |   35 +
 .../parameters/ContextActiveHandlers.java       |   36 +
 .../parameters/ContextClosedHandlers.java       |   36 +
 .../parameters/ContextFailedHandlers.java       |   36 +
 .../parameters/ContextMessageHandlers.java      |   36 +
 .../driver/parameters/DriverIdentifier.java     |   35 +
 .../driver/parameters/DriverIdleSources.java    |   34 +
 .../DriverJobSubmissionDirectory.java           |   32 +
 .../driver/parameters/DriverLocalFiles.java     |   33 +
 .../driver/parameters/DriverLocalLibraries.java |   33 +
 .../reef/driver/parameters/DriverMemory.java    |   31 +
 .../DriverRestartCompletedHandlers.java         |   36 +
 .../DriverRestartContextActiveHandlers.java     |   36 +
 .../driver/parameters/DriverRestartHandler.java |   31 +
 .../DriverRestartTaskRunningHandlers.java       |   36 +
 .../driver/parameters/DriverStartHandler.java   |   33 +
 .../parameters/EvaluatorAllocatedHandlers.java  |   36 +
 .../parameters/EvaluatorCompletedHandlers.java  |   36 +
 .../parameters/EvaluatorDispatcherThreads.java  |   33 +
 .../parameters/EvaluatorFailedHandlers.java     |   36 +
 .../reef/driver/parameters/JobGlobalFiles.java  |   33 +
 .../driver/parameters/JobGlobalLibraries.java   |   33 +
 .../ServiceContextActiveHandlers.java           |   35 +
 .../ServiceContextClosedHandlers.java           |   35 +
 .../ServiceContextFailedHandlers.java           |   35 +
 .../ServiceContextMessageHandlers.java          |   35 +
 .../ServiceDriverRestartCompletedHandlers.java  |   35 +
 ...rviceDriverRestartContextActiveHandlers.java |   35 +
 ...ServiceDriverRestartTaskRunningHandlers.java |   35 +
 .../ServiceEvaluatorAllocatedHandlers.java      |   35 +
 .../ServiceEvaluatorCompletedHandlers.java      |   35 +
 .../ServiceEvaluatorFailedHandlers.java         |   35 +
 .../ServiceTaskCompletedHandlers.java           |   35 +
 .../parameters/ServiceTaskFailedHandlers.java   |   35 +
 .../parameters/ServiceTaskMessageHandlers.java  |   35 +
 .../parameters/ServiceTaskRunningHandlers.java  |   35 +
 .../ServiceTaskSuspendedHandlers.java           |   35 +
 .../parameters/TaskCompletedHandlers.java       |   36 +
 .../driver/parameters/TaskFailedHandlers.java   |   36 +
 .../driver/parameters/TaskMessageHandlers.java  |   36 +
 .../driver/parameters/TaskRunningHandlers.java  |   36 +
 .../parameters/TaskSuspendedHandlers.java       |   36 +
 .../reef/driver/parameters/package-info.java    |   22 +
 .../apache/reef/driver/task/CompletedTask.java  |   46 +
 .../org/apache/reef/driver/task/FailedTask.java |   75 +
 .../apache/reef/driver/task/RunningTask.java    |   73 +
 .../apache/reef/driver/task/SuspendedTask.java  |   41 +
 .../reef/driver/task/TaskConfiguration.java     |   92 ++
 .../driver/task/TaskConfigurationOptions.java   |   77 +
 .../apache/reef/driver/task/TaskMessage.java    |   56 +
 .../reef/evaluator/context/ContextMessage.java  |   69 +
 .../context/ContextMessageHandler.java          |   39 +
 .../evaluator/context/ContextMessageSource.java |   39 +
 .../evaluator/context/events/ContextStart.java  |   39 +
 .../evaluator/context/events/ContextStop.java   |   39 +
 .../context/parameters/ContextIdentifier.java   |   29 +
 .../parameters/ContextMessageHandlers.java      |   34 +
 .../parameters/ContextMessageSources.java       |   34 +
 .../parameters/ContextStartHandlers.java        |   35 +
 .../context/parameters/ContextStopHandlers.java |   35 +
 .../evaluator/context/parameters/Services.java  |   35 +
 .../apache/reef/exception/DriverException.java  |   65 +
 .../reef/exception/EvaluatorException.java      |   66 +
 ...aluatorKilledByResourceManagerException.java |   29 +
 .../exception/EvaluatorTimeoutException.java    |   44 +
 .../exception/evaluator/NetworkException.java   |   38 +
 .../exception/evaluator/ServiceException.java   |   53 +
 .../evaluator/ServiceRuntimeException.java      |   75 +
 .../exception/evaluator/StorageException.java   |   36 +
 .../reef/exception/evaluator/package-info.java  |   23 +
 .../org/apache/reef/exception/package-info.java |   22 +
 .../java/org/apache/reef/io/Accumulable.java    |   39 +
 .../java/org/apache/reef/io/Accumulator.java    |   45 +
 .../java/org/apache/reef/io/ExternalMap.java    |   93 ++
 .../main/java/org/apache/reef/io/Message.java   |   36 +
 .../java/org/apache/reef/io/PartitionSpec.java  |   49 +
 .../src/main/java/org/apache/reef/io/Spool.java |   60 +
 .../apache/reef/io/SystemTempFileCreator.java   |   66 +
 .../org/apache/reef/io/TempFileCreator.java     |   65 +
 .../src/main/java/org/apache/reef/io/Tuple.java |   67 +
 .../io/WorkingDirectoryTempFileCreator.java     |   76 +
 .../org/apache/reef/io/naming/Identifiable.java |   33 +
 .../apache/reef/io/naming/NameAssignment.java   |   44 +
 .../java/org/apache/reef/io/naming/Naming.java  |   26 +
 .../org/apache/reef/io/naming/NamingLookup.java |   43 +
 .../apache/reef/io/naming/NamingRegistry.java   |   46 +
 .../java/org/apache/reef/io/package-info.java   |   24 +
 .../org/apache/reef/io/serialization/Codec.java |   45 +
 .../reef/io/serialization/Deserializer.java     |   37 +
 .../io/serialization/SerializableCodec.java     |   67 +
 .../reef/io/serialization/Serializer.java       |   38 +
 .../runtime/common/DriverRestartCompleted.java  |   28 +
 .../apache/reef/runtime/common/Launcher.java    |  156 ++
 .../runtime/common/client/ClientWireUp.java     |  104 ++
 .../client/CommonClientConfigurationModule.java |   28 +
 .../runtime/common/client/CompletedJobImpl.java |   46 +
 .../common/client/JobStatusMessageHandler.java  |   50 +
 .../common/client/JobSubmissionHelper.java      |  180 +++
 .../common/client/REEFImplementation.java       |  110 ++
 .../runtime/common/client/RunningJobImpl.java   |  168 +++
 .../reef/runtime/common/client/RunningJobs.java |   55 +
 .../runtime/common/client/RunningJobsImpl.java  |  148 ++
 .../common/client/RuntimeErrorProtoHandler.java |   51 +
 .../client/api/ClientRuntimeParameters.java     |   29 +
 .../common/client/api/JobSubmissionHandler.java |   30 +
 .../runtime/common/client/api/package-info.java |   22 +
 .../defaults/DefaultCompletedJobHandler.java    |   47 +
 .../defaults/DefaultFailedJobHandler.java       |   43 +
 .../defaults/DefaultJobMessageHandler.java      |   48 +
 .../defaults/DefaultRunningJobHandler.java      |   47 +
 .../defaults/DefaultRuntimeErrorHandler.java    |   52 +
 .../common/client/defaults/package-info.java    |   22 +
 .../runtime/common/client/package-info.java     |   22 +
 .../common/client/parameters/ClientPresent.java |   33 +
 .../common/driver/DriverExceptionHandler.java   |   53 +
 .../driver/DriverRuntimeConfiguration.java      |   73 +
 .../DriverRuntimeConfigurationOptions.java      |   33 +
 .../driver/DriverRuntimeStartHandler.java       |   80 ++
 .../common/driver/DriverRuntimeStopHandler.java |   71 +
 .../runtime/common/driver/DriverSingleton.java  |   18 +
 .../runtime/common/driver/DriverSingletons.java |   90 ++
 .../common/driver/DriverStartHandler.java       |   93 ++
 .../runtime/common/driver/DriverStatus.java     |   30 +
 .../common/driver/DriverStatusManager.java      |  330 +++++
 .../common/driver/EvaluatorRequestorImpl.java   |   95 ++
 .../api/AbstractDriverRuntimeConfiguration.java |  124 ++
 .../api/DefaultResourceManagerLifeCycle.java    |   18 +
 .../driver/api/ResourceLaunchHandler.java       |   30 +
 .../driver/api/ResourceManagerLifeCycle.java    |   18 +
 .../driver/api/ResourceReleaseHandler.java      |   30 +
 .../driver/api/ResourceRequestHandler.java      |   30 +
 .../common/driver/api/RuntimeParameters.java    |   50 +
 .../runtime/common/driver/api/package-info.java |   22 +
 .../driver/catalog/NodeDescriptorImpl.java      |   78 +
 .../driver/catalog/RackDescriptorImpl.java      |   78 +
 .../driver/catalog/ResourceCatalogImpl.java     |   88 ++
 .../common/driver/client/ClientConnection.java  |   82 ++
 .../common/driver/client/ClientManager.java     |  148 ++
 .../driver/client/JobMessageObserverImpl.java   |   44 +
 .../driver/client/LoggingJobStatusHandler.java  |   42 +
 .../common/driver/client/package-info.java      |   25 +
 .../driver/context/ClosedContextImpl.java       |   88 ++
 .../driver/context/ContextControlHandler.java   |   62 +
 .../common/driver/context/ContextFactory.java   |   97 ++
 .../driver/context/ContextMessageImpl.java      |   55 +
 .../driver/context/ContextRepresenters.java     |  247 ++++
 .../common/driver/context/EvaluatorContext.java |  280 ++++
 .../driver/context/FailedContextImpl.java       |   95 ++
 .../common/driver/context/package-info.java     |   26 +
 .../defaults/DefaultClientCloseHandler.java     |   46 +
 .../DefaultClientCloseWithMessageHandler.java   |   39 +
 .../defaults/DefaultClientMessageHandler.java   |   42 +
 .../defaults/DefaultContextActiveHandler.java   |   44 +
 .../defaults/DefaultContextClosureHandler.java  |   47 +
 .../defaults/DefaultContextFailureHandler.java  |   44 +
 .../defaults/DefaultContextMessageHandler.java  |   43 +
 .../DefaultDriverRestartCompletedHandler.java   |   44 +
 ...efaultDriverRestartContextActiveHandler.java |   44 +
 .../DefaultDriverRestartTaskRunningHandler.java |   43 +
 .../DefaultEvaluatorAllocationHandler.java      |   44 +
 .../DefaultEvaluatorCompletionHandler.java      |   43 +
 .../DefaultEvaluatorFailureHandler.java         |   41 +
 .../defaults/DefaultTaskCompletionHandler.java  |   47 +
 .../defaults/DefaultTaskFailureHandler.java     |   39 +
 .../defaults/DefaultTaskMessageHandler.java     |   43 +
 .../defaults/DefaultTaskRunningHandler.java     |   43 +
 .../defaults/DefaultTaskSuspensionHandler.java  |   39 +
 .../common/driver/defaults/package-info.java    |   22 +
 .../evaluator/AllocatedEvaluatorImpl.java       |  224 +++
 .../evaluator/CompletedEvaluatorImpl.java       |   49 +
 .../evaluator/EvaluatorControlHandler.java      |  100 ++
 .../evaluator/EvaluatorDescriptorImpl.java      |   75 +
 .../EvaluatorHeartBeatSanityChecker.java        |   57 +
 .../evaluator/EvaluatorHeartbeatHandler.java    |   74 +
 .../driver/evaluator/EvaluatorManager.java      |  529 +++++++
 .../evaluator/EvaluatorManagerFactory.java      |  105 ++
 .../evaluator/EvaluatorMessageDispatcher.java   |  247 ++++
 .../EvaluatorResourceManagerErrorHandler.java   |   67 +
 .../common/driver/evaluator/EvaluatorState.java |   38 +
 .../evaluator/EvaluatorStatusManager.java       |  106 ++
 .../common/driver/evaluator/Evaluators.java     |  128 ++
 .../driver/evaluator/FailedEvaluatorImpl.java   |   73 +
 .../common/driver/evaluator/package-info.java   |   26 +
 .../common/driver/idle/ClockIdlenessSource.java |   60 +
 .../common/driver/idle/DriverIdleManager.java   |   73 +
 .../driver/idle/DriverIdlenessSource.java       |   31 +
 .../driver/idle/EventHandlerIdlenessSource.java |   59 +
 .../runtime/common/driver/idle/IdleMessage.java |   61 +
 .../common/driver/idle/package-info.java        |   22 +
 .../runtime/common/driver/package-info.java     |   22 +
 .../resourcemanager/NodeDescriptorHandler.java  |   46 +
 .../ResourceAllocationHandler.java              |   63 +
 .../ResourceManagerErrorHandler.java            |   44 +
 .../resourcemanager/ResourceManagerStatus.java  |  156 ++
 .../resourcemanager/ResourceStatusHandler.java  |   71 +
 .../driver/resourcemanager/package-info.java    |   22 +
 .../common/driver/task/CompletedTaskImpl.java   |   60 +
 .../common/driver/task/RunningTaskImpl.java     |  138 ++
 .../common/driver/task/SuspendedTaskImpl.java   |   58 +
 .../common/driver/task/TaskMessageImpl.java     |   61 +
 .../common/driver/task/TaskRepresenter.java     |  202 +++
 .../common/driver/task/package-info.java        |   26 +
 .../evaluator/DefaultDriverConnection.java      |   48 +
 .../common/evaluator/DriverConnection.java      |   31 +
 .../evaluator/EvaluatorConfiguration.java       |   68 +
 .../common/evaluator/EvaluatorRuntime.java      |  207 +++
 .../common/evaluator/HeartBeatManager.java      |  173 +++
 .../common/evaluator/PIDStoreStartHandler.java  |   56 +
 .../context/ContextClientCodeException.java     |   78 +
 .../evaluator/context/ContextLifeCycle.java     |   97 ++
 .../evaluator/context/ContextManager.java       |  374 +++++
 .../evaluator/context/ContextRuntime.java       |  436 ++++++
 .../evaluator/context/ContextStartImpl.java     |   37 +
 .../evaluator/context/ContextStopImpl.java      |   35 +
 .../evaluator/context/RootContextLauncher.java  |  134 ++
 .../defaults/DefaultContextMessageHandler.java  |   45 +
 .../defaults/DefaultContextMessageSource.java   |   44 +
 .../defaults/DefaultContextStartHandler.java    |   43 +
 .../defaults/DefaultContextStopHandler.java     |   43 +
 .../context/defaults/package-info.java          |   22 +
 .../common/evaluator/context/package-info.java  |   22 +
 .../runtime/common/evaluator/package-info.java  |   22 +
 .../parameters/ApplicationIdentifier.java       |   33 +
 .../parameters/DriverRemoteIdentifier.java      |   31 +
 .../parameters/EvaluatorIdentifier.java         |   31 +
 .../evaluator/parameters/HeartbeatPeriod.java   |   31 +
 .../parameters/InitialTaskConfiguration.java    |   31 +
 .../parameters/RootContextConfiguration.java    |   31 +
 .../parameters/RootServiceConfiguration.java    |   31 +
 .../common/evaluator/task/CloseEventImpl.java   |   45 +
 .../evaluator/task/DriverMessageImpl.java       |   44 +
 .../common/evaluator/task/SuspendEventImpl.java |   45 +
 .../evaluator/task/TaskClientCodeException.java |   77 +
 .../evaluator/task/TaskLifeCycleHandlers.java   |   90 ++
 .../common/evaluator/task/TaskRuntime.java      |  313 ++++
 .../common/evaluator/task/TaskStartImpl.java    |   43 +
 .../common/evaluator/task/TaskStatus.java       |  310 ++++
 .../common/evaluator/task/TaskStopImpl.java     |   42 +
 .../task/defaults/DefaultCloseHandler.java      |   41 +
 .../defaults/DefaultDriverMessageHandler.java   |   41 +
 .../task/defaults/DefaultSuspendHandler.java    |   41 +
 .../evaluator/task/defaults/package-info.java   |   22 +
 .../task/exceptions/TaskCallFailure.java        |   37 +
 .../exceptions/TaskCloseHandlerFailure.java     |   37 +
 .../exceptions/TaskMessageHandlerFailure.java   |   37 +
 .../exceptions/TaskStartHandlerFailure.java     |   39 +
 .../task/exceptions/TaskStopHandlerFailure.java |   39 +
 .../exceptions/TaskSuspendHandlerFailure.java   |   37 +
 .../common/evaluator/task/package-info.java     |   22 +
 .../runtime/common/files/ClasspathProvider.java |   83 ++
 .../reef/runtime/common/files/JobJarMaker.java  |  136 ++
 .../runtime/common/files/REEFFileNames.java     |  216 +++
 .../common/files/RuntimeClasspathProvider.java  |   48 +
 .../reef/runtime/common/files/package-info.java |   22 +
 .../common/launch/CLRLaunchCommandBuilder.java  |   99 ++
 .../common/launch/JavaLaunchCommandBuilder.java |  163 +++
 .../reef/runtime/common/launch/LaunchClass.java |  191 +++
 .../common/launch/LaunchCommandBuilder.java     |   66 +
 .../common/launch/LauncherSingletons.java       |   18 +
 .../common/launch/ProfilingStopHandler.java     |   58 +
 .../runtime/common/launch/REEFErrorHandler.java |  101 ++
 .../runtime/common/launch/REEFMessageCodec.java |   96 ++
 .../launch/REEFUncaughtExceptionHandler.java    |   67 +
 .../runtime/common/launch/package-info.java     |   22 +
 .../parameters/ClockConfigurationPath.java      |   30 +
 .../launch/parameters/ErrorHandlerRID.java      |   37 +
 .../common/launch/parameters/LaunchID.java      |   27 +
 .../common/launch/parameters/package-info.java  |   22 +
 .../reef/runtime/common/package-info.java       |   26 +
 .../common/parameters/DeleteTempFiles.java      |   31 +
 .../runtime/common/parameters/JVMHeapSlack.java |   29 +
 .../common/utils/BroadCastEventHandler.java     |   44 +
 .../common/utils/DefaultExceptionCodec.java     |   64 +
 .../runtime/common/utils/DispatchingEStage.java |  143 ++
 .../runtime/common/utils/ExceptionCodec.java    |   50 +
 .../runtime/common/utils/RemoteManager.java     |   76 +
 .../reef/task/HeartBeatTriggerManager.java      |   53 +
 .../main/java/org/apache/reef/task/Task.java    |   48 +
 .../java/org/apache/reef/task/TaskMessage.java  |   67 +
 .../org/apache/reef/task/TaskMessageSource.java |   39 +
 .../org/apache/reef/task/events/CloseEvent.java |   38 +
 .../apache/reef/task/events/DriverMessage.java  |   38 +
 .../apache/reef/task/events/SuspendEvent.java   |   38 +
 .../org/apache/reef/task/events/TaskStart.java  |   37 +
 .../org/apache/reef/task/events/TaskStop.java   |   36 +
 .../main/java/org/apache/reef/util/Builder.java |   35 +
 .../java/org/apache/reef/util/CommandUtils.java |   55 +
 .../org/apache/reef/util/EnvironmentUtils.java  |  153 ++
 .../util/ExceptionHandlingEventHandler.java     |   50 +
 .../java/org/apache/reef/util/Exceptions.java   |   42 +
 .../java/org/apache/reef/util/JARFileMaker.java |  114 ++
 .../java/org/apache/reef/util/MemoryUtils.java  |  120 ++
 .../main/java/org/apache/reef/util/OSUtils.java |  105 ++
 .../reef/util/ObjectInstantiationLogger.java    |   33 +
 .../java/org/apache/reef/util/REEFVersion.java  |   84 ++
 .../main/java/org/apache/reef/util/SetOnce.java |   51 +
 .../org/apache/reef/util/SingletonAsserter.java |   41 +
 .../java/org/apache/reef/util/ThreadLogger.java |   94 ++
 .../org/apache/reef/util/logging/Config.java    |   31 +
 .../apache/reef/util/logging/LogLevelName.java  |   30 +
 .../org/apache/reef/util/logging/LogParser.java |  164 +++
 .../apache/reef/util/logging/LoggingScope.java  |   29 +
 .../reef/util/logging/LoggingScopeFactory.java  |  343 +++++
 .../reef/util/logging/LoggingScopeImpl.java     |  104 ++
 .../apache/reef/util/logging/LoggingSetup.java  |   37 +
 .../reef/util/logging/ThreadLogFormatter.java   |  141 ++
 .../java/org/apache/reef/util/package-info.java |   22 +
 .../src/main/proto/client_runtime.proto         |   54 +
 .../src/main/proto/driver_runtime.proto         |   89 ++
 .../src/main/proto/evaluator_runtime.proto      |   90 ++
 .../src/main/proto/reef_protocol.proto          |   42 +
 .../src/main/proto/reef_service_protos.proto    |  116 ++
 .../src/main/resources/log4j.properties         |   27 +
 .../org/apache/reef/logging.properties          |   85 ++
 .../src/main/resources/version.properties       |   18 +
 .../driver/EvaluatorRequestorImplTest.java      |  110 ++
 .../common/driver/catalog/CatalogTest.java      |   54 +
 .../org/apache/reef/util/LoggingScopeTest.java  |  100 ++
 .../apache/reef/util/SingletonAsserterTest.java |   34 +
 lang/java/reef-examples-clr/pom.xml             |  182 +++
 .../apache/reef/examples/helloCLR/HelloCLR.java |   93 ++
 .../reef/examples/helloCLR/HelloDriver.java     |  183 +++
 .../reef/examples/helloCLR/package-info.java    |   22 +
 .../examples/retained_evalCLR/JobClient.java    |  317 ++++
 .../examples/retained_evalCLR/JobDriver.java    |  489 +++++++
 .../reef/examples/retained_evalCLR/Launch.java  |  189 +++
 .../examples/retained_evalCLR/package-info.java |   22 +
 lang/java/reef-examples-hdinsight/pom.xml       |  128 ++
 .../reef/examples/hello/HelloHDInsight.java     |   33 +
 lang/java/reef-examples/.gitignore              |    1 +
 lang/java/reef-examples/pom.xml                 |  365 +++++
 .../examples/data/loading/DataLoadingREEF.java  |  128 ++
 .../reef/examples/data/loading/LineCounter.java |  126 ++
 .../examples/data/loading/LineCountingTask.java |   59 +
 .../apache/reef/examples/hello/HelloDriver.java |   84 ++
 .../apache/reef/examples/hello/HelloREEF.java   |   77 +
 .../reef/examples/hello/HelloREEFMesos.java     |   55 +
 .../reef/examples/hello/HelloREEFNoClient.java  |   64 +
 .../reef/examples/hello/HelloReefYarn.java      |   70 +
 .../apache/reef/examples/hello/HelloTask.java   |   39 +
 .../reef/examples/hello/package-info.java       |   22 +
 .../reef/examples/hellohttp/HelloREEFHttp.java  |  112 ++
 .../examples/hellohttp/HelloREEFHttpYarn.java   |   52 +
 .../hellohttp/HttpServerShellCmdtHandler.java   |  168 +++
 .../examples/hellohttp/HttpShellJobDriver.java  |  364 +++++
 .../apache/reef/examples/library/Command.java   |   29 +
 .../apache/reef/examples/library/ShellTask.java |   73 +
 .../apache/reef/examples/pool/JobDriver.java    |  306 ++++
 .../org/apache/reef/examples/pool/Launch.java   |  216 +++
 .../apache/reef/examples/pool/SleepTask.java    |   73 +
 .../apache/reef/examples/pool/package-info.java |   23 +
 .../reef/examples/retained_eval/JobClient.java  |  335 +++++
 .../reef/examples/retained_eval/JobDriver.java  |  370 +++++
 .../reef/examples/retained_eval/Launch.java     |  185 +++
 .../examples/retained_eval/package-info.java    |   22 +
 .../reef/examples/scheduler/Scheduler.java      |  226 +++
 .../examples/scheduler/SchedulerDriver.java     |  339 +++++
 .../scheduler/SchedulerHttpHandler.java         |  107 ++
 .../reef/examples/scheduler/SchedulerREEF.java  |  109 ++
 .../examples/scheduler/SchedulerREEFYarn.java   |   46 +
 .../examples/scheduler/SchedulerResponse.java   |  114 ++
 .../reef/examples/scheduler/TaskEntity.java     |   71 +
 .../reef/examples/scheduler/package-info.java   |   22 +
 .../apache/reef/examples/suspend/Control.java   |  103 ++
 .../apache/reef/examples/suspend/Launch.java    |  174 +++
 .../examples/suspend/ObjectWritableCodec.java   |   93 ++
 .../reef/examples/suspend/SuspendClient.java    |  172 +++
 .../examples/suspend/SuspendClientControl.java  |   92 ++
 .../reef/examples/suspend/SuspendDriver.java    |  340 +++++
 .../reef/examples/suspend/SuspendTestTask.java  |  179 +++
 .../reef/examples/suspend/package-info.java     |   22 +
 .../utils/wake/BlockingEventHandler.java        |   63 +
 .../utils/wake/LoggingEventHandler.java         |   58 +
 .../reef/examples/hello/HelloHttpTest.java      |   41 +
 .../suspend/ObjectWritableCodecTest.java        |   50 +
 lang/java/reef-io/pom.xml                       |  143 ++
 .../java/reef-io/src/main/avro/nameservice.avsc |   64 +
 .../reef/io/data/loading/api/DataLoader.java    |  236 +++
 .../api/DataLoadingDriverConfiguration.java     |   33 +
 .../loading/api/DataLoadingRequestBuilder.java  |  190 +++
 .../io/data/loading/api/DataLoadingService.java |   68 +
 .../reef/io/data/loading/api/DataSet.java       |   43 +
 .../loading/api/ResourceRequestHandler.java     |   64 +
 .../impl/EvaluatorRequestSerializer.java        |   63 +
 .../impl/EvaluatorToPartitionMapper.java        |  154 ++
 .../impl/InMemoryInputFormatDataSet.java        |   53 +
 .../data/loading/impl/InputFormatDataSet.java   |  156 ++
 .../impl/InputFormatExternalConstructor.java    |   50 +
 .../loading/impl/InputFormatLoadingService.java |  172 +++
 .../impl/InputSplitExternalConstructor.java     |   57 +
 .../impl/JobConfExternalConstructor.java        |   88 ++
 .../io/data/loading/impl/NumberedSplit.java     |   65 +
 .../data/loading/impl/WritableSerializer.java   |   93 ++
 .../java/org/apache/reef/io/network/Cache.java  |   53 +
 .../org/apache/reef/io/network/Connection.java  |   52 +
 .../reef/io/network/ConnectionFactory.java      |   37 +
 .../org/apache/reef/io/network/Message.java     |   50 +
 .../reef/io/network/TransportFactory.java       |   43 +
 .../exception/NetworkRuntimeException.java      |   54 +
 .../network/exception/ParentDeadException.java  |   48 +
 .../reef/io/network/exception/package-info.java |   19 +
 .../reef/io/network/impl/BindNSToTask.java      |   45 +
 .../network/impl/MessagingTransportFactory.java |   60 +
 .../reef/io/network/impl/NSConnection.java      |  134 ++
 .../apache/reef/io/network/impl/NSMessage.java  |   90 ++
 .../reef/io/network/impl/NSMessageCodec.java    |  134 ++
 .../network/impl/NameServiceCloseHandler.java   |   49 +
 .../reef/io/network/impl/NetworkService.java    |  235 +++
 .../impl/NetworkServiceClosingHandler.java      |   43 +
 .../network/impl/NetworkServiceParameters.java  |   60 +
 .../reef/io/network/impl/StreamingCodec.java    |   35 +
 .../reef/io/network/impl/UnbindNSFromTask.java  |   45 +
 .../reef/io/network/impl/package-info.java      |   19 +
 .../io/network/naming/NameAssignmentTuple.java  |   65 +
 .../reef/io/network/naming/NameCache.java       |   72 +
 .../reef/io/network/naming/NameClient.java      |  212 +++
 .../io/network/naming/NameLookupClient.java     |  257 ++++
 .../io/network/naming/NameRegistryClient.java   |  200 +++
 .../reef/io/network/naming/NameServer.java      |   88 ++
 .../network/naming/NameServerConfiguration.java |   51 +
 .../reef/io/network/naming/NameServerImpl.java  |  300 ++++
 .../io/network/naming/NameServerParameters.java |   40 +
 .../io/network/naming/NamingCodecFactory.java   |   82 ++
 .../naming/exception/NamingException.java       |   56 +
 .../exception/NamingRuntimeException.java       |   56 +
 .../network/naming/exception/package-info.java  |   19 +
 .../reef/io/network/naming/package-info.java    |   19 +
 .../network/naming/serialization/AvroUtils.java |   68 +
 .../serialization/NamingLookupRequest.java      |   46 +
 .../serialization/NamingLookupRequestCodec.java |   79 +
 .../serialization/NamingLookupResponse.java     |   48 +
 .../NamingLookupResponseCodec.java              |   94 ++
 .../naming/serialization/NamingMessage.java     |   46 +
 .../serialization/NamingRegisterRequest.java    |   46 +
 .../NamingRegisterRequestCodec.java             |   76 +
 .../serialization/NamingRegisterResponse.java   |   44 +
 .../NamingRegisterResponseCodec.java            |   60 +
 .../serialization/NamingUnregisterRequest.java  |   46 +
 .../NamingUnregisterRequestCodec.java           |   72 +
 .../naming/serialization/package-info.java      |   22 +
 .../apache/reef/io/network/package-info.java    |   19 +
 .../apache/reef/io/network/util/ListCodec.java  |   83 ++
 .../org/apache/reef/io/network/util/Pair.java   |   42 +
 .../reef/io/network/util/StringCodec.java       |   42 +
 .../reef/io/network/util/StringIdentifier.java  |   80 ++
 .../network/util/StringIdentifierFactory.java   |   46 +
 .../reef/io/network/util/package-info.java      |   19 +
 .../reef/io/storage/FramingInputStream.java     |   76 +
 .../reef/io/storage/FramingOutputStream.java    |  134 ++
 .../io/storage/FramingTupleDeserializer.java    |  100 ++
 .../reef/io/storage/FramingTupleSerializer.java |   86 ++
 .../apache/reef/io/storage/MergingIterator.java |   62 +
 .../apache/reef/io/storage/ScratchSpace.java    |   27 +
 .../apache/reef/io/storage/StorageService.java  |   25 +
 .../io/storage/local/CodecFileAccumulable.java  |   52 +
 .../io/storage/local/CodecFileAccumulator.java  |   58 +
 .../io/storage/local/CodecFileIterable.java     |   53 +
 .../io/storage/local/CodecFileIterator.java     |   82 ++
 .../io/storage/local/LocalScratchSpace.java     |   87 ++
 .../io/storage/local/LocalStorageService.java   |   44 +
 .../io/storage/local/SerializerFileSpool.java   |  101 ++
 .../apache/reef/io/storage/ram/CodecRamMap.java |   84 ++
 .../org/apache/reef/io/storage/ram/RamMap.java  |   74 +
 .../apache/reef/io/storage/ram/RamSpool.java    |   72 +
 .../reef/io/storage/ram/RamStorageService.java  |   38 +
 .../reef/io/storage/ram/SortingRamSpool.java    |   90 ++
 .../reef/io/storage/util/GetAllIterable.java    |   95 ++
 .../reef/io/storage/util/IntegerCodec.java      |   35 +
 .../io/storage/util/IntegerDeserializer.java    |   62 +
 .../reef/io/storage/util/IntegerSerializer.java |   62 +
 .../io/storage/util/StringDeserializer.java     |   66 +
 .../reef/io/storage/util/StringSerializer.java  |   65 +
 .../io/storage/util/TupleKeyComparator.java     |   37 +
 .../reef-io/src/main/proto/ns_protocol.proto    |   32 +
 .../reef/services/network/NameClientTest.java   |  123 ++
 .../reef/services/network/NamingTest.java       |  367 +++++
 .../services/network/NetworkServiceTest.java    |  495 +++++++
 .../apache/reef/services/network/TestEvent.java |   38 +
 .../services/network/util/LoggingUtils.java     |   43 +
 .../reef/services/network/util/Monitor.java     |   39 +
 .../reef/services/network/util/StringCodec.java |   34 +
 .../services/network/util/TimeoutHandler.java   |   36 +
 .../services/network/util/package-info.java     |   19 +
 .../reef/services/storage/ExternalMapTest.java  |   94 ++
 .../reef/services/storage/FramingTest.java      |  104 ++
 .../services/storage/MergingIteratorTest.java   |   54 +
 .../reef/services/storage/SortingSpoolTest.java |  117 ++
 .../reef/services/storage/SpoolFileTest.java    |  206 +++
 .../services/storage/TupleSerializerTest.java   |  105 ++
 lang/java/reef-poison/pom.xml                   |   52 +
 .../org/apache/reef/poison/PoisonException.java |   28 +
 .../reef/poison/PoisonedAlarmHandler.java       |   33 +
 .../reef/poison/PoisonedConfiguration.java      |   57 +
 .../context/PoisonedContextStartHandler.java    |   77 +
 .../PoissonPoisonedContextStartHandler.java     |   57 +
 .../reef/poison/context/package-info.java       |   22 +
 .../org/apache/reef/poison/package-info.java    |   22 +
 .../reef/poison/params/CrashProbability.java    |   30 +
 .../apache/reef/poison/params/CrashTimeout.java |   27 +
 .../poison/task/PoisonedTaskStartHandler.java   |   77 +
 .../task/PoissonPoisonedTaskStartHandler.java   |   57 +
 .../apache/reef/poison/task/package-info.java   |   22 +
 lang/java/reef-runtime-hdinsight/pom.xml        |   82 ++
 .../hdinsight/HDInsightClasspathProvider.java   |   73 +
 .../reef/runtime/hdinsight/cli/HDICLI.java      |  173 +++
 .../reef/runtime/hdinsight/cli/LogFetcher.java  |  134 ++
 .../runtime/hdinsight/cli/LogFileEntry.java     |  113 ++
 .../reef/runtime/hdinsight/cli/TFileParser.java |   97 ++
 .../runtime/hdinsight/cli/package-info.java     |   22 +
 .../runtime/hdinsight/client/AzureUploader.java |  151 ++
 .../client/HDInsightDriverConfiguration.java    |   95 ++
 .../client/HDInsightJobSubmissionHandler.java   |  180 +++
 .../client/HDInsightRuntimeConfiguration.java   |  123 ++
 .../HDInsightRuntimeConfigurationStatic.java    |   53 +
 .../UnsafeHDInsightRuntimeConfiguration.java    |  118 ++
 ...safeHDInsightRuntimeConfigurationStatic.java |   50 +
 .../runtime/hdinsight/client/package-info.java  |   22 +
 .../sslhacks/DefaultClientConstructor.java      |   39 +
 .../sslhacks/UnsafeClientConstructor.java       |   72 +
 .../client/sslhacks/UnsafeHostNameVerifier.java |   50 +
 .../client/sslhacks/UnsafeTrustManager.java     |   49 +
 .../client/yarnrest/ApplicationID.java          |   52 +
 .../client/yarnrest/ApplicationResponse.java    |   44 +
 .../client/yarnrest/ApplicationState.java       |  214 +++
 .../client/yarnrest/ApplicationSubmission.java  |  167 +++
 .../client/yarnrest/ContainerInfo.java          |  125 ++
 .../client/yarnrest/EnvironmentEntry.java       |   76 +
 .../hdinsight/client/yarnrest/FileResource.java |   89 ++
 .../client/yarnrest/HDInsightInstance.java      |  211 +++
 .../client/yarnrest/LocalResourcesEntry.java    |   48 +
 .../hdinsight/client/yarnrest/Resource.java     |   54 +
 .../hdinsight/client/yarnrest/package-info.java |   24 +
 .../reef/runtime/hdinsight/package-info.java    |   22 +
 .../AzureStorageAccountContainerName.java       |   29 +
 .../parameters/AzureStorageAccountKey.java      |   29 +
 .../parameters/AzureStorageAccountName.java     |   29 +
 .../parameters/AzureStorageBaseFolder.java      |   29 +
 .../parameters/HDInsightInstanceURL.java        |   29 +
 .../hdinsight/parameters/HDInsightPassword.java |   29 +
 .../hdinsight/parameters/HDInsightUsername.java |   29 +
 lang/java/reef-runtime-local/pom.xml            |   62 +
 .../runtime/local/LocalClasspathProvider.java   |  134 ++
 .../reef/runtime/local/client/DriverFiles.java  |  174 +++
 .../client/ExecutorServiceConstructor.java      |   44 +
 .../reef/runtime/local/client/FileSet.java      |  113 ++
 .../local/client/LocalJobSubmissionHandler.java |  166 +++
 .../local/client/LocalRuntimeConfiguration.java |   82 ++
 .../reef/runtime/local/client/package-info.java |   22 +
 .../client/parameters/DefaultMemorySize.java    |   29 +
 .../client/parameters/DefaultNumberOfCores.java |   29 +
 .../client/parameters/NumberOfProcesses.java    |   29 +
 .../local/client/parameters/RootFolder.java     |   30 +
 .../local/client/parameters/package-info.java   |   22 +
 .../reef/runtime/local/driver/Container.java    |   85 ++
 .../runtime/local/driver/ContainerManager.java  |  202 +++
 .../reef/runtime/local/driver/IDMaker.java      |   47 +
 .../local/driver/LocalDriverConfiguration.java  |   81 ++
 .../driver/LocalDriverRuntimeConfiguration.java |   30 +
 .../driver/LocalResourceLaunchHandler.java      |   46 +
 .../driver/LocalResourceReleaseHandler.java     |   47 +
 .../driver/LocalResourceRequestHandler.java     |   46 +
 .../runtime/local/driver/ProcessContainer.java  |  178 +++
 .../runtime/local/driver/ResourceManager.java   |  270 ++++
 .../runtime/local/driver/ResourceRequest.java   |   63 +
 .../local/driver/ResourceRequestQueue.java      |   70 +
 .../reef/runtime/local/driver/package-info.java |   22 +
 .../local/driver/parameters/GlobalFiles.java    |   31 +
 .../driver/parameters/GlobalLibraries.java      |   31 +
 .../local/driver/parameters/LocalFiles.java     |   31 +
 .../local/driver/parameters/LocalLibraries.java |   31 +
 .../local/driver/parameters/package-info.java   |   22 +
 .../process/LoggingRunnableProcessObserver.java |   44 +
 .../process/ReefRunnableProcessObserver.java    |  125 ++
 .../runtime/local/process/RunnableProcess.java  |  277 ++++
 .../local/process/RunnableProcessObserver.java  |   39 +
 .../runtime/local/process/package-info.java     |   22 +
 .../local/driver/ResourceRequestQueueTest.java  |   63 +
 .../local/driver/ResourceRequestTest.java       |   61 +
 lang/java/reef-runtime-mesos/pom.xml            |   95 ++
 .../src/main/avro/EvaluatorControl.avsc         |   47 +
 .../runtime/mesos/MesosClasspathProvider.java   |   92 ++
 .../mesos/client/MesosClientConfiguration.java  |   68 +
 .../mesos/client/MesosJobSubmissionHandler.java |  141 ++
 .../mesos/client/parameters/MasterIp.java       |   26 +
 .../mesos/client/parameters/RootFolder.java     |   26 +
 .../mesos/driver/MesosDriverConfiguration.java  |   98 ++
 .../driver/MesosResourceLaunchHandler.java      |  129 ++
 .../driver/MesosResourceReleaseHandler.java     |   42 +
 .../driver/MesosResourceRequestHandler.java     |   42 +
 .../mesos/driver/MesosRuntimeStartHandler.java  |   38 +
 .../mesos/driver/MesosRuntimeStopHandler.java   |   38 +
 .../driver/MesosSchedulerDriverExecutor.java    |   42 +
 .../runtime/mesos/driver/REEFEventHandlers.java |   65 +
 .../reef/runtime/mesos/driver/REEFExecutor.java |   50 +
 .../runtime/mesos/driver/REEFExecutors.java     |   64 +
 .../runtime/mesos/driver/REEFScheduler.java     |  506 +++++++
 .../mesos/driver/parameters/MesosMasterIp.java  |   26 +
 .../evaluator/EvaluatorControlHandler.java      |   55 +
 .../runtime/mesos/evaluator/REEFExecutor.java   |  249 ++++
 .../evaluator/parameters/MesosExecutorId.java   |   26 +
 .../util/HDFSConfigurationConstructor.java      |   35 +
 .../runtime/mesos/util/MesosErrorHandler.java   |   43 +
 .../runtime/mesos/util/MesosRemoteManager.java  |   62 +
 .../mesos/util/MesosRemoteManagerCodec.java     |   68 +
 lang/java/reef-runtime-yarn/pom.xml             |   80 ++
 .../reef/runtime/yarn/ClassPathBuilder.java     |  109 ++
 .../runtime/yarn/YarnClasspathProvider.java     |  140 ++
 .../yarn/client/YarnClientConfiguration.java    |   73 +
 .../yarn/client/YarnJobSubmissionHandler.java   |  277 ++++
 .../yarn/client/parameters/JobPriority.java     |   29 +
 .../yarn/client/parameters/JobQueue.java        |   29 +
 .../driver/ApplicationMasterRegistration.java   |   62 +
 .../yarn/driver/ContainerRequestCounter.java    |   71 +
 .../reef/runtime/yarn/driver/Containers.java    |  109 ++
 .../yarn/driver/DefaultTrackingURLProvider.java |   33 +
 .../yarn/driver/EvaluatorSetupHelper.java       |  147 ++
 .../runtime/yarn/driver/GlobalJarUploader.java  |   92 ++
 .../runtime/yarn/driver/REEFEventHandlers.java  |   91 ++
 .../yarn/driver/TrackingURLProvider.java        |   29 +
 .../yarn/driver/UploaderToJobfolder.java        |   94 ++
 .../yarn/driver/YARNResourceLaunchHandler.java  |  125 ++
 .../yarn/driver/YARNResourceReleaseHandler.java |   50 +
 .../yarn/driver/YARNRuntimeStartHandler.java    |   42 +
 .../yarn/driver/YARNRuntimeStopHandler.java     |   42 +
 .../yarn/driver/YarnContainerManager.java       |  680 +++++++++
 .../driver/YarnContainerRequestHandler.java     |   32 +
 .../driver/YarnContainerRequestHandlerImpl.java |   47 +
 .../yarn/driver/YarnDriverConfiguration.java    |   95 ++
 .../yarn/driver/YarnResourceRequestHandler.java |  111 ++
 .../reef/runtime/yarn/driver/package-info.java  |   22 +
 .../parameters/JobSubmissionDirectory.java      |   29 +
 .../driver/parameters/YarnHeartbeatPeriod.java  |   29 +
 .../yarn/util/YarnConfigurationConstructor.java |   38 +
 .../reef/runtime/yarn/util/YarnTypes.java       |   59 +
 .../driver/YarnResourceRequestHandlerTest.java  |  127 ++
 lang/java/reef-tang/.gitattributes              |    3 +
 lang/java/reef-tang/.gitignore                  |   15 +
 lang/java/reef-tang/README.md                   |  562 ++++++++
 lang/java/reef-tang/doc/tangdoc.png             |  Bin 0 -> 32351 bytes
 lang/java/reef-tang/doc/tooltip.png             |  Bin 0 -> 9677 bytes
 lang/java/reef-tang/pom.xml                     |   40 +
 lang/java/reef-tang/tang-test-jarA/pom.xml      |   31 +
 .../java/org/apache/reef/tang/examples/A.java   |   23 +
 lang/java/reef-tang/tang-test-jarAB/pom.xml     |   38 +
 .../java/org/apache/reef/tang/examples/A.java   |   25 +
 .../java/org/apache/reef/tang/examples/B.java   |   25 +
 .../reef-tang/tang-test-jarB-conflictA/pom.xml  |   31 +
 lang/java/reef-tang/tang-test-jarB/pom.xml      |   39 +
 .../java/org/apache/reef/tang/examples/B.java   |   23 +
 lang/java/reef-tang/tang/.gitignore             |    2 +
 lang/java/reef-tang/tang/maven-eclipse.xml      |   28 +
 lang/java/reef-tang/tang/pom.xml                |  171 +++
 .../tang/src/main/avro/configuration.avsc       |   37 +
 .../main/java/org/apache/reef/tang/Aspect.java  |   74 +
 .../java/org/apache/reef/tang/BindLocation.java |   38 +
 .../org/apache/reef/tang/ClassHierarchy.java    |   86 ++
 .../org/apache/reef/tang/Configuration.java     |  167 +++
 .../apache/reef/tang/ConfigurationBuilder.java  |  251 ++++
 .../org/apache/reef/tang/Configurations.java    |   59 +
 .../apache/reef/tang/ExternalConstructor.java   |   40 +
 .../org/apache/reef/tang/InjectionFuture.java   |  136 ++
 .../java/org/apache/reef/tang/Injector.java     |  133 ++
 .../apache/reef/tang/JavaClassHierarchy.java    |   67 +
 .../reef/tang/JavaConfigurationBuilder.java     |   98 ++
 .../main/java/org/apache/reef/tang/Tang.java    |  149 ++
 .../tang/annotations/DefaultImplementation.java |   42 +
 .../org/apache/reef/tang/annotations/Name.java  |   23 +
 .../reef/tang/annotations/NamedParameter.java   |   40 +
 .../apache/reef/tang/annotations/Parameter.java |   31 +
 .../org/apache/reef/tang/annotations/Unit.java  |   47 +
 .../reef/tang/annotations/package-info.java     |   23 +
 .../reef/tang/examples/PrintTypeHierarchy.java  |  105 ++
 .../org/apache/reef/tang/examples/Timer.java    |   73 +
 .../org/apache/reef/tang/examples/TimerV1.java  |   66 +
 .../apache/reef/tang/examples/package-info.java |   22 +
 .../apache/reef/tang/examples/timer/Timer.java  |   33 +
 .../reef/tang/examples/timer/TimerImpl.java     |   42 +
 .../reef/tang/examples/timer/TimerMock.java     |   66 +
 .../reef/tang/examples/timer/package-info.java  |   23 +
 .../reef/tang/exceptions/BindException.java     |   43 +
 .../exceptions/ClassHierarchyException.java     |   40 +
 .../tang/exceptions/InjectionException.java     |   44 +
 .../exceptions/NameResolutionException.java     |   40 +
 .../reef/tang/exceptions/ParseException.java    |   36 +
 .../reef/tang/exceptions/package-info.java      |   28 +
 .../formats/AvroConfigurationSerializer.java    |  313 ++++
 .../apache/reef/tang/formats/CommandLine.java   |  218 +++
 .../reef/tang/formats/ConfigurationFile.java    |  253 ++++
 .../reef/tang/formats/ConfigurationModule.java  |  299 ++++
 .../formats/ConfigurationModuleBuilder.java     |  385 +++++
 .../tang/formats/ConfigurationSerializer.java   |  154 ++
 .../java/org/apache/reef/tang/formats/Impl.java |   22 +
 .../apache/reef/tang/formats/OptionalImpl.java  |   22 +
 .../reef/tang/formats/OptionalParameter.java    |   22 +
 .../org/apache/reef/tang/formats/Param.java     |   22 +
 .../reef/tang/formats/ParameterParser.java      |  150 ++
 .../org/apache/reef/tang/formats/Provides.java  |   22 +
 .../apache/reef/tang/formats/RequiredImpl.java  |   22 +
 .../reef/tang/formats/RequiredParameter.java    |   22 +
 .../apache/reef/tang/formats/package-info.java  |   29 +
 .../ConfigurationBuilderImpl.java               |  378 +++++
 .../tang/implementation/ConfigurationImpl.java  |  143 ++
 .../reef/tang/implementation/Constructor.java   |  186 +++
 .../implementation/InjectionFuturePlan.java     |   64 +
 .../reef/tang/implementation/InjectionPlan.java |  161 +++
 .../tang/implementation/ListInjectionPlan.java  |  106 ++
 .../tang/implementation/SetInjectionPlan.java   |  106 ++
 .../tang/implementation/StackBindLocation.java  |   46 +
 .../reef/tang/implementation/Subplan.java       |  188 +++
 .../reef/tang/implementation/TangImpl.java      |  161 +++
 .../implementation/java/ClassHierarchyImpl.java |  448 ++++++
 .../tang/implementation/java/InjectorImpl.java  |  760 ++++++++++
 .../java/JavaConfigurationBuilderImpl.java      |  238 +++
 .../tang/implementation/java/JavaInstance.java  |   75 +
 .../implementation/java/JavaNodeFactory.java    |  333 +++++
 .../tang/implementation/java/package-info.java  |   29 +
 .../reef/tang/implementation/package-info.java  |   27 +
 .../protobuf/ProtocolBufferClassHierarchy.java  |  396 +++++
 .../protobuf/ProtocolBufferInjectionPlan.java   |  148 ++
 .../implementation/protobuf/package-info.java   |   25 +
 .../tang/implementation/types/AbstractNode.java |  127 ++
 .../implementation/types/ClassNodeImpl.java     |  141 ++
 .../types/ConstructorArgImpl.java               |   77 +
 .../types/ConstructorDefImpl.java               |  150 ++
 .../types/NamedParameterNodeImpl.java           |   86 ++
 .../implementation/types/PackageNodeImpl.java   |   43 +
 .../tang/implementation/types/package-info.java |   26 +
 .../java/org/apache/reef/tang/package-info.java |   27 +
 .../org/apache/reef/tang/types/ClassNode.java   |   47 +
 .../apache/reef/tang/types/ConstructorArg.java  |   30 +
 .../apache/reef/tang/types/ConstructorDef.java  |   29 +
 .../reef/tang/types/NamedParameterNode.java     |   36 +
 .../java/org/apache/reef/tang/types/Node.java   |   42 +
 .../org/apache/reef/tang/types/PackageNode.java |   23 +
 .../org/apache/reef/tang/types/Traversable.java |   26 +
 .../apache/reef/tang/types/package-info.java    |   26 +
 .../tang/util/AbstractMonotonicMultiMap.java    |  206 +++
 .../apache/reef/tang/util/MonotonicHashMap.java |   58 +
 .../apache/reef/tang/util/MonotonicHashSet.java |   91 ++
 .../reef/tang/util/MonotonicMultiHashMap.java   |   25 +
 .../reef/tang/util/MonotonicMultiMap.java       |   25 +
 .../org/apache/reef/tang/util/MonotonicSet.java |   91 ++
 .../apache/reef/tang/util/MonotonicTreeMap.java |  119 ++
 .../reef/tang/util/ReflectionUtilities.java     |  397 +++++
 .../java/org/apache/reef/tang/util/Tint.java    |  735 ++++++++++
 .../reef/tang/util/TracingMonotonicMap.java     |   25 +
 .../reef/tang/util/TracingMonotonicTreeMap.java |  146 ++
 .../reef/tang/util/ValidateConfiguration.java   |  150 ++
 .../org/apache/reef/tang/util/package-info.java |   24 +
 .../walk/AbstractClassHierarchyNodeVisitor.java |   79 +
 .../walk/AbstractInjectionPlanNodeVisitor.java  |   80 ++
 .../apache/reef/tang/util/walk/EdgeVisitor.java |   35 +
 .../apache/reef/tang/util/walk/NodeVisitor.java |   35 +
 .../org/apache/reef/tang/util/walk/Walk.java    |   66 +
 .../walk/graphviz/GraphvizConfigVisitor.java    |  244 ++++
 .../graphviz/GraphvizInjectionPlanVisitor.java  |  168 +++
 .../tang/util/walk/graphviz/package-info.java   |   22 +
 .../reef/tang/util/walk/package-info.java       |   22 +
 .../reef-tang/tang/src/main/proto/.gitignore    |    1 +
 .../tang/src/main/proto/class_hierarchy.proto   |  167 +++
 .../tang/src/main/proto/injection_plan.proto    |   38 +
 .../tang/ClassHierarchyDeserializationTest.java |  112 ++
 .../org/apache/reef/tang/TestBindSingleton.java |  420 ++++++
 .../org/apache/reef/tang/TestClassLoaders.java  |  118 ++
 .../apache/reef/tang/TestConfFileParser.java    |  119 ++
 .../reef/tang/TestExternalConstructor.java      |   89 ++
 .../reef/tang/TestImplicitConversions.java      |  167 +++
 .../apache/reef/tang/TestInjectionFuture.java   |  195 +++
 .../org/apache/reef/tang/TestListInjection.java |  344 +++++
 .../reef/tang/TestNamedParameterRoundTrip.java  |  105 ++
 .../org/apache/reef/tang/TestSetInjection.java  |  181 +++
 .../java/org/apache/reef/tang/TestTang.java     | 1356 ++++++++++++++++++
 .../org/apache/reef/tang/TestTweetExample.java  |  120 ++
 ...onfigurationSerializerAvroRoundtripTest.java |   41 +
 ...urationSerializerByteArrayRoundtripTest.java |   42 +
 ...onfigurationSerializerFileRoundtripTest.java |   50 +
 ...figurationSerializerStringRoundtripTest.java |   40 +
 ...gurationSerializerTextFileRoundtripTest.java |   50 +
 .../tang/formats/ConfigurationFileTest.java     |   54 +
 .../reef/tang/formats/NamedParameters.java      |   38 +
 .../reef/tang/formats/TestCommandLine.java      |   79 +
 .../tang/formats/TestConfigurationModule.java   |  445 ++++++
 .../tang/implementation/TestClassHierarchy.java |  642 +++++++++
 .../java/TestConfigurationBuilder.java          |   60 +
 .../java/TestParameterParser.java               |  245 ++++
 .../protobuf/TestClassHierarchyRoundTrip.java   |  401 ++++++
 .../org/apache/reef/tang/test/AnInterface.java  |   29 +
 .../tang/test/AnInterfaceImplementation.java    |   52 +
 .../apache/reef/tang/test/CyclicDependency.java |   56 +
 .../tang/test/CyclicDependencyClassOne.java     |   50 +
 .../tang/test/CyclicDependencyClassTwo.java     |   48 +
 .../java/org/apache/reef/tang/test/Handler.java |   30 +
 .../apache/reef/tang/test/InjectableClass.java  |   47 +
 .../apache/reef/tang/test/ListInterface.java    |   23 +
 .../reef/tang/test/ListInterfaceImplOne.java    |   55 +
 .../reef/tang/test/ListInterfaceImplTwo.java    |   55 +
 .../apache/reef/tang/test/ListOfBaseTypes.java  |   82 ++
 .../reef/tang/test/ListOfImplementations.java   |   55 +
 .../apache/reef/tang/test/ObjectTreeTest.java   |   61 +
 .../reef/tang/test/RootImplementation.java      |  166 +++
 .../test/RootImplementationWithoutList.java     |  155 ++
 .../apache/reef/tang/test/RootInterface.java    |   31 +
 .../apache/reef/tang/test/RoundTripTest.java    |   56 +
 .../org/apache/reef/tang/test/SetInterface.java |   27 +
 .../reef/tang/test/SetInterfaceImplOne.java     |   56 +
 .../reef/tang/test/SetInterfaceImplTwo.java     |   54 +
 .../apache/reef/tang/test/SetOfBaseTypes.java   |   85 ++
 .../reef/tang/test/SetOfImplementations.java    |   55 +
 .../reef/tang/test/TestConfiguration.java       |  110 ++
 .../tang/test/TestConfigurationWithoutList.java |   92 ++
 .../org/apache/reef/tang/test/UnitClass.java    |  119 ++
 .../org/apache/reef/tang/test/package-info.java |   22 +
 .../reef-tang/tang/src/test/resources/Event.bin |  Bin 0 -> 24188 bytes
 .../reef-tang/tang/src/test/resources/Task.bin  |  Bin 0 -> 128600 bytes
 lang/java/reef-tests/pom.xml                    |  161 +++
 .../assembly/test-jar-with-dependencies.xml     |   38 +
 .../apache/reef/tests/TestDriverLauncher.java   |  132 ++
 .../tests/driver/DriverTestStartHandler.java    |   43 +
 .../apache/reef/tests/driver/package-info.java  |   22 +
 .../EvaluatorReuseTestDriver.java               |  118 ++
 .../reef/tests/evaluatorreuse/package-info.java |   23 +
 .../tests/fail/driver/DriverFailOnFail.java     |   98 ++
 .../reef/tests/fail/driver/FailClient.java      |   65 +
 .../reef/tests/fail/driver/FailDriver.java      |  371 +++++
 .../tests/fail/driver/FailDriverDelayedMsg.java |  128 ++
 .../apache/reef/tests/fail/driver/NoopTask.java |  117 ++
 .../org/apache/reef/tests/fail/task/Client.java |   57 +
 .../org/apache/reef/tests/fail/task/Driver.java |  169 +++
 .../apache/reef/tests/fail/task/FailTask.java   |   49 +
 .../reef/tests/fail/task/FailTaskCall.java      |   46 +
 .../reef/tests/fail/task/FailTaskClose.java     |   65 +
 .../reef/tests/fail/task/FailTaskMsg.java       |   65 +
 .../reef/tests/fail/task/FailTaskStart.java     |   65 +
 .../reef/tests/fail/task/FailTaskStop.java      |   79 +
 .../reef/tests/fail/task/FailTaskSuspend.java   |   69 +
 .../driver/ExpectedTaskFailureHandler.java      |   59 +
 .../driver/OnDriverStartedAllocateOne.java      |   48 +
 .../library/exceptions/ClientSideFailure.java   |   40 +
 .../library/exceptions/DriverSideFailure.java   |   42 +
 .../exceptions/ExpectedTaskException.java       |   43 +
 .../exceptions/SimulatedDriverFailure.java      |   41 +
 .../exceptions/SimulatedTaskFailure.java        |   41 +
 .../library/exceptions/TaskSideFailure.java     |   41 +
 .../exceptions/UnexpectedTaskReturnValue.java   |   40 +
 .../apache/reef/tests/library/package-info.java |   22 +
 .../reef/tests/library/tasks/EchoTask.java      |   38 +
 .../reef/tests/library/tasks/NoopTask.java      |   38 +
 .../tests/messaging/driver/DriverMessaging.java |  173 +++
 .../messaging/driver/DriverMessagingDriver.java |   87 ++
 .../messaging/task/TaskMessagingDriver.java     |   98 ++
 .../tests/messaging/task/TaskMessagingTask.java |   83 ++
 .../apache/reef/tests/statepassing/Counter.java |   38 +
 .../tests/statepassing/StatePassingDriver.java  |  126 ++
 .../tests/statepassing/StatePassingTask.java    |   50 +
 .../reef/tests/yarn/failure/FailureDriver.java  |  109 ++
 .../reef/tests/yarn/failure/FailureREEF.java    |  120 ++
 .../org/apache/reef/tests/AllTestsSuite.java    |   54 +
 .../java/org/apache/reef/tests/FailureTest.java |   54 +
 .../apache/reef/tests/LocalTestEnvironment.java |   68 +
 .../apache/reef/tests/MesosTestEnvironment.java |   68 +
 .../apache/reef/tests/ProbabilisticTests.java   |   33 +
 .../org/apache/reef/tests/TestEnvironment.java  |   58 +
 .../apache/reef/tests/TestEnvironmentBase.java  |   39 +
 .../reef/tests/TestEnvironmentFactory.java      |   54 +
 .../java/org/apache/reef/tests/TestUtils.java   |   63 +
 .../apache/reef/tests/YarnTestEnvironment.java  |   60 +
 .../tests/close_eval/CloseEvaluatorDriver.java  |   65 +
 .../tests/close_eval/CloseEvaluatorTest.java    |   68 +
 .../apache/reef/tests/driver/DriverTest.java    |   68 +
 .../tests/evaluatorexit/EvaluatorExitTest.java  |   66 +
 .../evaluatorexit/EvaluatorExitTestDriver.java  |   79 +
 .../evaluatorexit/EvaluatorExitTestTask.java    |   39 +
 .../reef/tests/evaluatorexit/package-info.java  |   22 +
 .../EvaluatorFailureDuringAlarmDriver.java      |  106 ++
 .../evaluatorfailure/EvaluatorFailureTest.java  |   75 +
 .../evaluatorfailure/ExpectedException.java     |   25 +
 .../FailureSchedulingContextStartHandler.java   |   52 +
 .../tests/evaluatorfailure/package-info.java    |   22 +
 .../evaluatorreuse/EvaluatorReuseTest.java      |   72 +
 .../tests/evaluatorsize/EvaluatorSizeTest.java  |   79 +
 .../EvaluatorSizeTestConfiguration.java         |   38 +
 .../evaluatorsize/EvaluatorSizeTestDriver.java  |   97 ++
 .../tests/evaluatorsize/MemorySizeTask.java     |   49 +
 .../reef/tests/evaluatorsize/package-info.java  |   22 +
 .../reef/tests/examples/ExamplesTestSuite.java  |   33 +
 .../reef/tests/examples/TestHelloREEF.java      |   61 +
 .../tests/examples/TestRetainedEvaluators.java  |   81 ++
 .../reef/tests/examples/package-info.java       |   22 +
 .../reef/tests/fail/DriverFailOnFailTest.java   |   71 +
 .../tests/fail/FailDriverDelayedMsgTest.java    |   73 +
 .../apache/reef/tests/fail/FailDriverTest.java  |  133 ++
 .../apache/reef/tests/fail/FailTaskTest.java    |   93 ++
 .../apache/reef/tests/fail/FailTestSuite.java   |   32 +
 .../reef/tests/files/FileResourceTest.java      |  144 ++
 .../tests/files/FileResourceTestDriver.java     |  127 ++
 .../FileResourceTestDriverConfiguration.java    |   40 +
 .../reef/tests/files/FileResourceTestTask.java  |   67 +
 .../FileResourceTestTaskConfiguration.java      |   44 +
 .../apache/reef/tests/files/package-info.java   |   22 +
 .../messaging/driver/DriverMessagingTest.java   |   51 +
 .../tests/messaging/driver/package-info.java    |   22 +
 .../tests/messaging/task/TaskMessagingTest.java |   72 +
 .../reef/tests/messaging/task/package-info.java |   22 +
 .../ActiveContextHandler.java                   |   63 +
 .../AllocatedEvaluatorHandler.java              |   60 +
 .../multipleEventHandlerInstances/Client.java   |   76 +
 .../ClosedContextHandler.java                   |   51 +
 .../CompletedEvaluatorHandler.java              |   52 +
 .../CompletedTaskHandler.java                   |   51 +
 .../EmptyTask.java                              |   39 +
 .../RunningTaskHandler.java                     |   51 +
 .../StartHandler.java                           |   62 +
 .../tests/roguethread/RogueThreadDriver.java    |   50 +
 .../reef/tests/roguethread/RogueThreadTask.java |   44 +
 .../reef/tests/roguethread/RogueThreadTest.java |   70 +
 .../reef/tests/roguethread/package-info.java    |   22 +
 .../tests/statepassing/StatePassingTest.java    |   71 +
 .../reef/tests/statepassing/package-info.java   |   22 +
 .../tests/subcontexts/ContextStartHandler1.java |   39 +
 .../tests/subcontexts/ContextStartHandler2.java |   38 +
 .../tests/subcontexts/ContextStopHandler1.java  |   38 +
 .../tests/subcontexts/ContextStopHandler2.java  |   38 +
 .../tests/subcontexts/SubContextDriver.java     |  143 ++
 .../reef/tests/subcontexts/SubContextTest.java  |   93 ++
 .../reef/tests/subcontexts/package-info.java    |   22 +
 .../tests/taskcounting/TaskCountingDriver.java  |  109 ++
 .../tests/taskcounting/TaskCountingTest.java    |   70 +
 .../reef/tests/taskcounting/package-info.java   |   22 +
 .../tests/taskresubmit/TaskResubmitDriver.java  |   85 ++
 .../tests/taskresubmit/TaskResubmitTest.java    |   72 +
 .../reef/tests/taskresubmit/package-info.java   |   22 +
 lang/java/reef-utils-hadoop/pom.xml             |   45 +
 .../org/apache/reef/util/HadoopEnvironment.java |   37 +
 .../apache/reef/util/logging/DFSHandler.java    |  146 ++
 lang/java/reef-utils/pom.xml                    |   45 +
 .../java/org/apache/reef/util/Optional.java     |  128 ++
 .../java/org/apache/reef/util/package-info.java |   22 +
 .../java/org/apache/reef/util/OptionalTest.java |   99 ++
 lang/java/reef-wake/.gitattributes              |    3 +
 lang/java/reef-wake/.gitignore                  |   16 +
 lang/java/reef-wake/README.md                   |   94 ++
 lang/java/reef-wake/pom.xml                     |   38 +
 lang/java/reef-wake/wake/pom.xml                |  123 ++
 .../org/apache/reef/wake/AbstractEStage.java    |   91 ++
 .../apache/reef/wake/ComparableIdentifier.java  |   27 +
 .../main/java/org/apache/reef/wake/EStage.java  |   27 +
 .../java/org/apache/reef/wake/EventHandler.java |   34 +
 .../java/org/apache/reef/wake/Identifiable.java |   30 +
 .../java/org/apache/reef/wake/Identifier.java   |   54 +
 .../org/apache/reef/wake/IdentifierFactory.java |   31 +
 .../org/apache/reef/wake/IdentifierParser.java  |   55 +
 .../main/java/org/apache/reef/wake/Stage.java   |   25 +
 .../apache/reef/wake/StageConfiguration.java    |   68 +
 .../org/apache/reef/wake/WakeConfiguration.java |   62 +
 .../org/apache/reef/wake/WakeParameters.java    |   46 +
 .../wake/examples/accumulate/CombinerStage.java |  161 +++
 .../reef/wake/examples/join/BlockingJoin.java   |   95 ++
 .../reef/wake/examples/join/EventPrinter.java   |   39 +
 .../wake/examples/join/NonBlockingJoin.java     |  121 ++
 .../reef/wake/examples/join/TupleEvent.java     |   45 +
 .../reef/wake/examples/join/TupleSource.java    |   58 +
 .../reef/wake/examples/join/package-info.java   |   22 +
 .../reef/wake/examples/p2p/EventSource.java     |   33 +
 .../reef/wake/examples/p2p/Pull2Push.java       |   94 ++
 .../reef/wake/examples/p2p/package-info.java    |   22 +
 .../apache/reef/wake/examples/package-info.java |   22 +
 .../wake/exception/WakeRuntimeException.java    |   56 +
 .../reef/wake/exception/package-info.java       |   22 +
 .../reef/wake/impl/BlockingEventHandler.java    |   79 +
 .../wake/impl/BlockingSignalEventHandler.java   |   56 +
 .../wake/impl/DefaultIdentifierFactory.java     |   90 ++
 .../reef/wake/impl/DefaultThreadFactory.java    |   85 ++
 .../apache/reef/wake/impl/ForkPoolStage.java    |  103 ++
 .../IndependentIterationsThreadPoolStage.java   |   80 ++
 .../reef/wake/impl/LoggingEventHandler.java     |   49 +
 .../org/apache/reef/wake/impl/LoggingUtils.java |   52 +
 .../reef/wake/impl/LoggingVoidEventHandler.java |   47 +
 .../reef/wake/impl/MergingEventHandler.java     |  152 ++
 .../wake/impl/MissingStartHandlerHandler.java   |   43 +
 .../reef/wake/impl/MultiEventHandler.java       |   60 +
 .../reef/wake/impl/OpaqueLocalIdentifier.java   |   28 +
 .../apache/reef/wake/impl/PeriodicEvent.java    |   25 +
 .../reef/wake/impl/PubSubEventHandler.java      |  105 ++
 .../reef/wake/impl/SingleThreadStage.java       |  144 ++
 .../org/apache/reef/wake/impl/StageManager.java |   78 +
 .../org/apache/reef/wake/impl/SyncStage.java    |  113 ++
 .../apache/reef/wake/impl/ThreadPoolStage.java  |  223 +++
 .../org/apache/reef/wake/impl/TimerStage.java   |  135 ++
 .../apache/reef/wake/impl/WakeSharedPool.java   |  108 ++
 .../wake/impl/WakeUncaughtExceptionHandler.java |   46 +
 .../org/apache/reef/wake/impl/package-info.java |   22 +
 .../java/org/apache/reef/wake/metrics/EWMA.java |   79 +
 .../reef/wake/metrics/EWMAParameters.java       |   35 +
 .../org/apache/reef/wake/metrics/Histogram.java |   55 +
 .../org/apache/reef/wake/metrics/Meter.java     |  147 ++
 .../reef/wake/metrics/UniformHistogram.java     |   90 ++
 .../apache/reef/wake/metrics/package-info.java  |   22 +
 .../java/org/apache/reef/wake/package-info.java |   22 +
 .../org/apache/reef/wake/profiler/Vertex.java   |  100 ++
 .../apache/reef/wake/profiler/WakeProfiler.java |  321 +++++
 .../java/org/apache/reef/wake/remote/Codec.java |   28 +
 .../org/apache/reef/wake/remote/Decoder.java    |   36 +
 .../reef/wake/remote/DefaultErrorHandler.java   |   38 +
 .../org/apache/reef/wake/remote/Encoder.java    |   36 +
 .../org/apache/reef/wake/remote/NetUtils.java   |  106 ++
 .../reef/wake/remote/RemoteConfiguration.java   |   71 +
 .../reef/wake/remote/RemoteIdentifier.java      |   27 +
 .../wake/remote/RemoteIdentifierFactory.java    |   41 +
 .../apache/reef/wake/remote/RemoteManager.java  |   91 ++
 .../apache/reef/wake/remote/RemoteMessage.java  |   42 +
 .../exception/RemoteRuntimeException.java       |   54 +
 .../wake/remote/exception/package-info.java     |   22 +
 .../apache/reef/wake/remote/impl/ByteCodec.java |   50 +
 .../wake/remote/impl/ConnectFutureTask.java     |   40 +
 ...ltRemoteIdentifierFactoryImplementation.java |   47 +
 .../DefaultRemoteManagerImplementation.java     |  229 +++
 .../wake/remote/impl/DefaultRemoteMessage.java  |   65 +
 .../reef/wake/remote/impl/HandlerContainer.java |  154 ++
 .../reef/wake/remote/impl/MultiCodec.java       |   75 +
 .../reef/wake/remote/impl/MultiDecoder.java     |   72 +
 .../reef/wake/remote/impl/MultiEncoder.java     |   64 +
 .../remote/impl/ObjectSerializableCodec.java    |   72 +
 .../remote/impl/OrderedRemoteReceiverStage.java |  201 +++
 .../wake/remote/impl/ProxyEventHandler.java     |   89 ++
 .../reef/wake/remote/impl/RemoteEvent.java      |  170 +++
 .../reef/wake/remote/impl/RemoteEventCodec.java |   65 +
 .../wake/remote/impl/RemoteEventComparator.java |   37 +
 .../wake/remote/impl/RemoteEventDecoder.java    |   62 +
 .../wake/remote/impl/RemoteEventEncoder.java    |   68 +
 .../remote/impl/RemoteReceiverEventHandler.java |   61 +
 .../wake/remote/impl/RemoteReceiverStage.java   |   99 ++
 .../remote/impl/RemoteSenderEventHandler.java   |  165 +++
 .../wake/remote/impl/RemoteSenderStage.java     |   91 ++
 .../wake/remote/impl/RemoteSeqNumGenerator.java |   49 +
 .../remote/impl/SocketRemoteIdentifier.java     |  111 ++
 .../reef/wake/remote/impl/StringCodec.java      |   50 +
 .../reef/wake/remote/impl/Subscription.java     |   61 +
 .../reef/wake/remote/impl/TransportEvent.java   |  106 ++
 .../apache/reef/wake/remote/impl/Tuple2.java    |   59 +
 .../reef/wake/remote/impl/package-info.java     |   22 +
 .../apache/reef/wake/remote/package-info.java   |   22 +
 .../apache/reef/wake/remote/transport/Link.java |   52 +
 .../wake/remote/transport/LinkListener.java     |   34 +
 .../reef/wake/remote/transport/Transport.java   |   77 +
 .../exception/TransportRuntimeException.java    |   54 +
 .../transport/exception/package-info.java       |   22 +
 .../netty/AbstractNettyEventListener.java       |   99 ++
 .../remote/transport/netty/ByteEncoder.java     |   36 +
 .../netty/ChunkedReadWriteHandler.java          |  191 +++
 .../remote/transport/netty/LinkReference.java   |   48 +
 .../transport/netty/LoggingLinkListener.java    |   46 +
 .../transport/netty/NettyChannelHandler.java    |  114 ++
 .../netty/NettyChannelHandlerFactory.java       |   35 +
 .../netty/NettyChannelInitializer.java          |   52 +
 .../netty/NettyClientEventListener.java         |   56 +
 .../NettyDefaultChannelHandlerFactory.java      |   49 +
 .../transport/netty/NettyEventListener.java     |   57 +
 .../wake/remote/transport/netty/NettyLink.java  |  117 ++
 .../netty/NettyMessagingTransport.java          |  329 +++++
 .../netty/NettyServerEventListener.java         |   65 +
 .../remote/transport/netty/package-info.java    |   22 +
 .../wake/remote/transport/package-info.java     |   22 +
 .../apache/reef/wake/rx/AbstractObserver.java   |   43 +
 .../apache/reef/wake/rx/AbstractRxStage.java    |   86 ++
 .../apache/reef/wake/rx/DynamicObservable.java  |   36 +
 .../org/apache/reef/wake/rx/Observable.java     |   25 +
 .../java/org/apache/reef/wake/rx/Observer.java  |   50 +
 .../java/org/apache/reef/wake/rx/RxStage.java   |   29 +
 .../apache/reef/wake/rx/StaticObservable.java   |   26 +
 .../java/org/apache/reef/wake/rx/Subject.java   |   29 +
 .../exception/ObserverCompletedException.java   |   38 +
 .../reef/wake/rx/exception/package-info.java    |   22 +
 .../apache/reef/wake/rx/impl/RxSyncStage.java   |  104 ++
 .../reef/wake/rx/impl/RxThreadPoolStage.java    |  198 +++
 .../apache/reef/wake/rx/impl/SimpleSubject.java |   73 +
 .../reef/wake/rx/impl/TimeoutSubject.java       |   84 ++
 .../apache/reef/wake/rx/impl/package-info.java  |   22 +
 .../org/apache/reef/wake/rx/package-info.java   |   22 +
 .../reef/wake/storage/FileHandlePool.java       |   31 +
 .../reef/wake/storage/FileIdentifier.java       |   49 +
 .../apache/reef/wake/storage/ReadRequest.java   |   41 +
 .../apache/reef/wake/storage/ReadResponse.java  |   33 +
 .../reef/wake/storage/SequentialFileReader.java |   61 +
 .../reef/wake/storage/StorageIdentifier.java    |   25 +
 .../java/org/apache/reef/wake/time/Clock.java   |  107 ++
 .../java/org/apache/reef/wake/time/Time.java    |   62 +
 .../org/apache/reef/wake/time/event/Alarm.java  |   40 +
 .../apache/reef/wake/time/event/StartTime.java  |   32 +
 .../apache/reef/wake/time/event/StopTime.java   |   32 +
 .../reef/wake/time/event/package-info.java      |   22 +
 .../org/apache/reef/wake/time/package-info.java |   22 +
 .../reef/wake/time/runtime/LogicalTimer.java    |   48 +
 .../reef/wake/time/runtime/RealTimer.java       |   43 +
 .../reef/wake/time/runtime/RuntimeClock.java    |  244 ++++
 .../apache/reef/wake/time/runtime/Timer.java    |   30 +
 .../wake/time/runtime/event/ClientAlarm.java    |   29 +
 .../reef/wake/time/runtime/event/IdleClock.java |   28 +
 .../wake/time/runtime/event/RuntimeAlarm.java   |   30 +
 .../wake/time/runtime/event/RuntimeStart.java   |   29 +
 .../wake/time/runtime/event/RuntimeStop.java    |   40 +
 .../wake/time/runtime/event/package-info.java   |   22 +
 .../reef/wake/time/runtime/package-info.java    |   22 +
 .../wake/src/main/proto/RemoteProtocol.proto    |   35 +
 .../com/microsoft/wake/logging.properties       |   81 ++
 .../wake/test/BlockingEventHandlerTest.java     |  196 +++
 .../test/BlockingSignalEventHandlerTest.java    |  166 +++
 .../reef/wake/test/ForkPoolStageTest.java       |  226 +++
 ...ndependentIterationsThreadPoolStageTest.java |   84 ++
 .../reef/wake/test/MergingEventHandlerTest.java |  237 +++
 .../org/apache/reef/wake/test/MetricsTest.java  |   52 +
 .../wake/test/PubSubThreadPoolStageTest.java    |  115 ++
 .../apache/reef/wake/test/StageManagerTest.java |   48 +
 .../apache/reef/wake/test/SyncStageTest.java    |  130 ++
 .../reef/wake/test/ThreadPoolStageTest.java     |  221 +++
 .../apache/reef/wake/test/TimerStageTest.java   |   82 ++
 .../reef/wake/test/examples/SkipListTest.java   |  378 +++++
 .../wake/test/examples/TestBlockingJoin.java    |   39 +
 .../reef/wake/test/examples/TestCombiner.java   |  129 ++
 .../reef/wake/test/examples/TestJoin.java       |   38 +
 .../wake/test/examples/TestTupleSource.java     |   34 +
 .../org/apache/reef/wake/test/package-info.java |   22 +
 .../reef/wake/test/remote/LargeMsgTest.java     |  141 ++
 .../remote/RemoteIdentifierFactoryTest.java     |   86 ++
 .../wake/test/remote/RemoteManagerTest.java     |  462 ++++++
 .../reef/wake/test/remote/RemoteTest.java       |  211 +++
 .../wake/test/remote/SmallMessagesTest.java     |  161 +++
 .../reef/wake/test/remote/StartEvent.java       |   25 +
 .../apache/reef/wake/test/remote/TestEvent.java |   47 +
 .../reef/wake/test/remote/TestEvent1.java       |   29 +
 .../reef/wake/test/remote/TestEvent2.java       |   30 +
 .../reef/wake/test/remote/TestEventCodec.java   |   52 +
 .../reef/wake/test/remote/TestRemote.java       |   68 +
 .../wake/test/remote/TestRemoteIdentifier.java  |   48 +
 .../wake/test/remote/TransportRaceTest.java     |  104 ++
 .../reef/wake/test/remote/TransportTest.java    |  144 ++
 .../reef/wake/test/remote/package-info.java     |   22 +
 .../org/apache/reef/wake/test/rx/RxTest.java    |   90 ++
 .../wake/test/rx/RxThreadPoolStageTest.java     |  194 +++
 .../reef/wake/test/rx/TimeoutSubjectTest.java   |  143 ++
 .../apache/reef/wake/test/rx/package-info.java  |   22 +
 .../apache/reef/wake/test/time/ClockTest.java   |  205 +++
 .../reef/wake/test/time/package-info.java       |   22 +
 .../org/apache/reef/wake/test/util/Monitor.java |   41 +
 .../reef/wake/test/util/PassThroughEncoder.java |   36 +
 .../reef/wake/test/util/TimeoutHandler.java     |   36 +
 .../reef/wake/test/util/package-info.java       |   22 +
 .../wake/src/test/proto/TestEvent1.proto        |   28 +
 .../wake/src/test/proto/TestProtocol.proto      |   28 +
 lang/java/reef-webserver/pom.xml                |  107 ++
 .../src/main/avro/DriverInfo.avsc               |   43 +
 .../src/main/avro/EvaluatorInfo.avsc            |   45 +
 .../src/main/avro/EvaluatorList.avsc            |   43 +
 .../src/main/avro/webRequest.avsc               |   29 +
 .../webserver/AvroDriverInfoSerializer.java     |   68 +
 .../webserver/AvroEvaluatorInfoSerializer.java  |  101 ++
 .../webserver/AvroEvaluatorListSerializer.java  |   85 ++
 .../reef/webserver/AvroHttpSerializer.java      |  108 ++
 .../reef/webserver/DriverInfoSerializer.java    |   46 +
 .../reef/webserver/EvaluatorInfoSerializer.java |   40 +
 .../reef/webserver/EvaluatorListSerializer.java |   48 +
 .../reef/webserver/HttpEventHandlers.java       |   31 +
 .../org/apache/reef/webserver/HttpHandler.java  |   50 +
 .../webserver/HttpHandlerConfiguration.java     |   43 +
 .../webserver/HttpRuntimeConfiguration.java     |   37 +
 .../reef/webserver/HttpRuntimeStartHandler.java |   68 +
 .../reef/webserver/HttpRuntimeStopHandler.java  |   67 +
 .../org/apache/reef/webserver/HttpServer.java   |   55 +
 .../apache/reef/webserver/HttpServerImpl.java   |  149 ++
 .../webserver/HttpServerReefEventHandler.java   |  388 +++++
 .../reef/webserver/HttpTrackingURLProvider.java |   67 +
 .../org/apache/reef/webserver/JettyHandler.java |  159 ++
 .../apache/reef/webserver/MaxPortNumber.java    |   29 +
 .../apache/reef/webserver/MaxRetryAttempts.java |   29 +
 .../apache/reef/webserver/MinPortNumber.java    |   29 +
 .../reef/webserver/ParsedHttpRequest.java       |  194 +++
 .../org/apache/reef/webserver/PortNumber.java   |   31 +
 .../reef/webserver/ReefEventStateManager.java   |  308 ++++
 .../reef/webserver/TestAvroHttpSerializer.java  |  153 ++
 .../webserver/TestAvroSerializerForHttp.java    |  179 +++
 .../reef/webserver/TestHttpConfiguration.java   |  204 +++
 .../apache/reef/webserver/TestHttpServer.java   |  169 +++
 .../apache/reef/webserver/TestJettyHandler.java |  166 +++
 .../reef/webserver/TestParsedHttpRequest.java   |  101 ++
 .../reef/webserver/TestReefEventHandler.java    |   84 ++
 .../webserver/TestReefEventStateManager.java    |  146 ++
 .../reef/webserver/TestRuntimeStartHandler.java |  104 ++
 .../apache/reef/webserver/TestTrackingUri.java  |  113 ++
 pom.xml                                         |  656 ---------
 reef-annotations/pom.xml                        |   31 -
 .../org/apache/reef/annotations/Optional.java   |   26 -
 .../org/apache/reef/annotations/Provided.java   |   26 -
 .../org/apache/reef/annotations/Unstable.java   |   25 -
 .../reef/annotations/audience/ClientSide.java   |   26 -
 .../reef/annotations/audience/DriverSide.java   |   26 -
 .../annotations/audience/EvaluatorSide.java     |   25 -
 .../reef/annotations/audience/Private.java      |   26 -
 .../reef/annotations/audience/Public.java       |   26 -
 .../annotations/audience/RuntimeAuthor.java     |   26 -
 .../reef/annotations/audience/TaskSide.java     |   26 -
 .../reef/annotations/audience/package-info.java |   22 -
 .../apache/reef/annotations/package-info.java   |   22 -
 .../reef/annotations/semantics/Idempotent.java  |   25 -
 reef-bridge-project/.gitignore                  |   34 -
 reef-bridge-project/pom.xml                     |  101 --
 reef-bridge-project/reef-bridge-clr/pom.xml     |  162 ---
 .../CSharp/CSharp/ClrHandler/ClrHandler.csproj  |   66 -
 .../ClrHandler/Properties/AssemblyInfo.cs       |   49 -
 .../externals/Microsoft.Reef.Driver.dll         |  Bin 123392 -> 0 bytes
 .../CSharp/ClrHandler/externals/msvcr110.dll    |  Bin 849360 -> 0 bytes
 .../ClrHandler/interface/IInteropReturnInfo.cs  |   30 -
 .../CSharp/ClrHandler/interface/ILogger.cs      |   37 -
 .../JavaClrBridge/ActiveContextClr2Java.cpp     |  106 --
 .../AllocatedEvaluatorClr2Java.cpp              |  164 ---
 .../CppBridge/JavaClrBridge/AssemblyInfo.cpp    |   50 -
 .../CppBridge/JavaClrBridge/AssemblyUtil.cpp    |   53 -
 .../Cpp/CppBridge/JavaClrBridge/BinaryUtil.cpp  |  102 --
 .../Cpp/CppBridge/JavaClrBridge/BinaryUtil.h    |   26 -
 .../JavaClrBridge/ClosedContextClr2Java.cpp     |   86 --
 .../CppBridge/JavaClrBridge/Clr2JavaImpl.cpp    |   44 -
 .../Cpp/CppBridge/JavaClrBridge/Clr2JavaImpl.h  |  220 ---
 .../CppBridge/JavaClrBridge/CommonUtilities.cpp |   51 -
 .../CompletedEvaluatorClr2Java.cpp              |   58 -
 .../JavaClrBridge/CompletedTaskClr2Java.cpp     |   69 -
 .../JavaClrBridge/ContextMessageClr2Java.cpp    |   76 -
 .../EvaluatorRequestorClr2Java.cpp              |   69 -
 .../JavaClrBridge/FailedContextClr2Java.cpp     |   94 --
 .../JavaClrBridge/FailedEvaluatorClr2Java.cpp   |   72 -
 .../JavaClrBridge/FailedTaskClr2Java.cpp        |   79 -
 .../JavaClrBridge/HttpServerClr2Java.cpp        |  135 --
 .../CppBridge/JavaClrBridge/InteropAssemblies.h |   40 -
 .../CppBridge/JavaClrBridge/InteropLogger.cpp   |   50 -
 .../Cpp/CppBridge/JavaClrBridge/InteropLogger.h |   47 -
 .../JavaClrBridge/InteropReturnInfo.cpp         |   91 --
 .../CppBridge/JavaClrBridge/InteropReturnInfo.h |   57 -
 .../Cpp/CppBridge/JavaClrBridge/InteropUtil.cpp |  129 --
 .../Cpp/CppBridge/JavaClrBridge/InteropUtil.h   |   65 -
 .../CppBridge/JavaClrBridge/JavaClrBridge.cpp   |  492 -------
 .../Cpp/CppBridge/JavaClrBridge/JavaClrBridge.h |   33 -
 .../CppBridge/JavaClrBridge/JavaClrBridge.sln   |   56 -
 .../JavaClrBridge/JavaClrBridge.vcxproj         |  173 ---
 .../JavaClrBridge/JavaClrBridge.vcxproj.filters |  104 --
 .../CppBridge/JavaClrBridge/ManagedLogger.cpp   |   47 -
 .../main/Cpp/CppBridge/JavaClrBridge/ReadMe.txt |   57 -
 .../JavaClrBridge/RunningTaskClr2Java.cpp       |   90 --
 .../JavaClrBridge/SuspendedTaskClr2Java.cpp     |   83 --
 .../JavaClrBridge/TaskMessageClr2Java.cpp       |   58 -
 reef-bridge-project/reef-bridge-java/pom.xml    |  116 --
 .../reef/javabridge/ActiveContextBridge.java    |   80 --
 .../javabridge/AllocatedEvaluatorBridge.java    |  141 --
 .../reef/javabridge/ClosedContextBridge.java    |   81 --
 .../javabridge/CompletedEvaluatorBridge.java    |   43 -
 .../reef/javabridge/CompletedTaskBridge.java    |   40 -
 .../reef/javabridge/ContextMessageBridge.java   |   56 -
 .../javabridge/EvaluatorRequestorBridge.java    |   76 -
 .../reef/javabridge/FailedContextBridge.java    |   83 --
 .../reef/javabridge/FailedEvaluatorBridge.java  |   47 -
 .../reef/javabridge/FailedTaskBridge.java       |   60 -
 .../reef/javabridge/HttpServerEventBridge.java  |   79 -
 .../apache/reef/javabridge/InteropLogger.java   |   55 -
 .../reef/javabridge/InteropReturnInfo.java      |   52 -
 .../org/apache/reef/javabridge/JavaBridge.java  |   31 -
 .../org/apache/reef/javabridge/LibLoader.java   |  154 --
 .../apache/reef/javabridge/NativeBridge.java    |   32 -
 .../apache/reef/javabridge/NativeInterop.java   |  166 ---
 .../reef/javabridge/RunningTaskBridge.java      |   49 -
 .../reef/javabridge/SuspendedTaskBridge.java    |   54 -
 .../reef/javabridge/TaskMessageBridge.java      |   36 -
 .../org/apache/reef/javabridge/Utilities.java   |   57 -
 .../reef/javabridge/generic/JobClient.java      |  322 -----
 .../reef/javabridge/generic/JobDriver.java      |  724 ----------
 .../apache/reef/javabridge/generic/Launch.java  |  236 ---
 .../reef/javabridge/generic/LaunchHeadless.java |  100 --
 .../reef/javabridge/generic/package-info.java   |   22 -
 .../util/logging/CLRBufferedLogHandler.java     |  167 ---
 .../reef/util/logging/CLRLoggingConfig.java     |   31 -
 .../apache/reef/util/logging/package-info.java  |   22 -
 .../org/apache/reef/clr.logging.properties      |   82 --
 reef-bridge-project/reef-bridge/pom.xml         |  111 --
 reef-checkpoint/maven-eclipse.xml               |   28 -
 reef-checkpoint/pom.xml                         |   68 -
 .../apache/reef/io/checkpoint/CheckpointID.java |   31 -
 .../io/checkpoint/CheckpointNamingService.java  |   33 -
 .../reef/io/checkpoint/CheckpointService.java   |  100 --
 .../reef/io/checkpoint/RandomNameCNS.java       |   49 -
 .../reef/io/checkpoint/SimpleNamingService.java |   55 -
 .../fs/FSCheckPointServiceConfiguration.java    |  110 --
 .../reef/io/checkpoint/fs/FSCheckpointID.java   |   74 -
 .../io/checkpoint/fs/FSCheckpointService.java   |  221 ---
 reef-common/maven-eclipse.xml                   |   28 -
 reef-common/pom.xml                             |  142 --
 reef-common/src/main/conf/log4j.properties      |   40 -
 reef-common/src/main/conf/reef-site.xml         |   21 -
 .../apache/reef/client/ClientConfiguration.java |   83 --
 .../org/apache/reef/client/CompletedJob.java    |   39 -
 .../apache/reef/client/DriverConfiguration.java |  253 ----
 .../org/apache/reef/client/DriverLauncher.java  |  220 ---
 .../reef/client/DriverServiceConfiguration.java |  196 ---
 .../java/org/apache/reef/client/FailedJob.java  |   48 -
 .../org/apache/reef/client/FailedRuntime.java   |   82 --
 .../java/org/apache/reef/client/JobMessage.java |   74 -
 .../org/apache/reef/client/LauncherStatus.java  |  123 --
 .../main/java/org/apache/reef/client/REEF.java  |   55 -
 .../java/org/apache/reef/client/RunningJob.java |   62 -
 .../org/apache/reef/client/package-info.java    |   23 -
 .../client/parameters/JobCompletedHandler.java  |   35 -
 .../client/parameters/JobFailedHandler.java     |   35 -
 .../client/parameters/JobMessageHandler.java    |   35 -
 .../client/parameters/JobRunningHandler.java    |   35 -
 .../parameters/ResourceManagerErrorHandler.java |   35 -
 .../reef/client/parameters/package-info.java    |   22 -
 .../org/apache/reef/common/AbstractFailure.java |  151 --
 .../java/org/apache/reef/common/Failure.java    |   58 -
 .../reef/driver/ContextAndTaskSubmittable.java  |   64 -
 .../apache/reef/driver/ContextSubmittable.java  |   49 -
 .../reef/driver/FlexiblePreemptionEvent.java    |   47 -
 .../org/apache/reef/driver/PreemptionEvent.java |   47 -
 .../apache/reef/driver/PreemptionHandler.java   |   36 -
 .../reef/driver/StrictPreemptionEvent.java      |   37 -
 .../org/apache/reef/driver/TaskSubmittable.java |   40 -
 .../reef/driver/catalog/NodeDescriptor.java     |   42 -
 .../reef/driver/catalog/RackDescriptor.java     |   35 -
 .../reef/driver/catalog/ResourceCatalog.java    |   65 -
 .../reef/driver/client/JobMessageObserver.java  |   44 -
 .../apache/reef/driver/client/package-info.java |   25 -
 .../reef/driver/context/ActiveContext.java      |   71 -
 .../reef/driver/context/ClosedContext.java      |   37 -
 .../apache/reef/driver/context/ContextBase.java |   56 -
 .../driver/context/ContextConfiguration.java    |  109 --
 .../reef/driver/context/ContextMessage.java     |   52 -
 .../reef/driver/context/FailedContext.java      |   44 -
 .../driver/context/ServiceConfiguration.java    |   79 -
 .../driver/evaluator/AllocatedEvaluator.java    |  101 --
 .../driver/evaluator/CompletedEvaluator.java    |   33 -
 .../driver/evaluator/EvaluatorDescriptor.java   |   47 -
 .../reef/driver/evaluator/EvaluatorRequest.java |  171 ---
 .../driver/evaluator/EvaluatorRequestor.java    |   38 -
 .../reef/driver/evaluator/EvaluatorType.java    |   38 -
 .../reef/driver/evaluator/FailedEvaluator.java  |   55 -
 .../org/apache/reef/driver/package-info.java    |   22 -
 .../driver/parameters/ClientCloseHandlers.java  |   35 -
 .../ClientCloseWithMessageHandlers.java         |   35 -
 .../parameters/ClientMessageHandlers.java       |   35 -
 .../parameters/ContextActiveHandlers.java       |   36 -
 .../parameters/ContextClosedHandlers.java       |   36 -
 .../parameters/ContextFailedHandlers.java       |   36 -
 .../parameters/ContextMessageHandlers.java      |   36 -
 .../driver/parameters/DriverIdentifier.java     |   35 -
 .../driver/parameters/DriverIdleSources.java    |   34 -
 .../DriverJobSubmissionDirectory.java           |   32 -
 .../driver/parameters/DriverLocalFiles.java     |   33 -
 .../driver/parameters/DriverLocalLibraries.java |   33 -
 .../reef/driver/parameters/DriverMemory.java    |   31 -
 .../DriverRestartCompletedHandlers.java         |   36 -
 .../DriverRestartContextActiveHandlers.java     |   36 -
 .../driver/parameters/DriverRestartHandler.java |   31 -
 .../DriverRestartTaskRunningHandlers.java       |   36 -
 .../driver/parameters/DriverStartHandler.java   |   33 -
 .../parameters/EvaluatorAllocatedHandlers.java  |   36 -
 .../parameters/EvaluatorCompletedHandlers.java  |   36 -
 .../parameters/EvaluatorDispatcherThreads.java  |   33 -
 .../parameters/EvaluatorFailedHandlers.java     |   36 -
 .../reef/driver/parameters/JobGlobalFiles.java  |   33 -
 .../driver/parameters/JobGlobalLibraries.java   |   33 -
 .../ServiceContextActiveHandlers.java           |   35 -
 .../ServiceContextClosedHandlers.java           |   35 -
 .../ServiceContextFailedHandlers.java           |   35 -
 .../ServiceContextMessageHandlers.java          |   35 -
 .../ServiceDriverRestartCompletedHandlers.java  |   35 -
 ...rviceDriverRestartContextActiveHandlers.java |   35 -
 ...ServiceDriverRestartTaskRunningHandlers.java |   35 -
 .../ServiceEvaluatorAllocatedHandlers.java      |   35 -
 .../ServiceEvaluatorCompletedHandlers.java      |   35 -
 .../ServiceEvaluatorFailedHandlers.java         |   35 -
 .../ServiceTaskCompletedHandlers.java           |   35 -
 .../parameters/ServiceTaskFailedHandlers.java   |   35 -
 .../parameters/ServiceTaskMessageHandlers.java  |   35 -
 .../parameters/ServiceTaskRunningHandlers.java  |   35 -
 .../ServiceTaskSuspendedHandlers.java           |   35 -
 .../parameters/TaskCompletedHandlers.java       |   36 -
 .../driver/parameters/TaskFailedHandlers.java   |   36 -
 .../driver/parameters/TaskMessageHandlers.java  |   36 -
 .../driver/parameters/TaskRunningHandlers.java  |   36 -
 .../parameters/TaskSuspendedHandlers.java       |   36 -
 .../reef/driver/parameters/package-info.java    |   22 -
 .../apache/reef/driver/task/CompletedTask.java  |   46 -
 .../org/apache/reef/driver/task/FailedTask.java |   75 -
 .../apache/reef/driver/task/RunningTask.java    |   73 -
 .../apache/reef/driver/task/SuspendedTask.java  |   41 -
 .../reef/driver/task/TaskConfiguration.java     |   92 --
 .../driver/task/TaskConfigurationOptions.java   |   77 -
 .../apache/reef/driver/task/TaskMessage.java    |   56 -
 .../reef/evaluator/context/ContextMessage.java  |   69 -
 .../context/ContextMessageHandler.java          |   39 -
 .../evaluator/context/ContextMessageSource.java |   39 -
 .../evaluator/context/events/ContextStart.java  |   39 -
 .../evaluator/context/events/ContextStop.java   |   39 -
 .../context/parameters/ContextIdentifier.java   |   29 -
 .../parameters/ContextMessageHandlers.java      |   34 -
 .../parameters/ContextMessageSources.java       |   34 -
 .../parameters/ContextStartHandlers.java        |   35 -
 .../context/parameters/ContextStopHandlers.java |   35 -
 .../evaluator/context/parameters/Services.java  |   35 -
 .../apache/reef/exception/DriverException.java  |   65 -
 .../reef/exception/EvaluatorException.java      |   66 -
 ...aluatorKilledByResourceManagerException.java |   29 -
 .../exception/EvaluatorTimeoutException.java    |   44 -
 .../exception/evaluator/NetworkException.java   |   38 -
 .../exception/evaluator/ServiceException.java   |   53 -
 .../evaluator/ServiceRuntimeException.java      |   75 -
 .../exception/evaluator/StorageException.java   |   36 -
 .../reef/exception/evaluator/package-info.java  |   23 -
 .../org/apache/reef/exception/package-info.java |   22 -
 .../java/org/apache/reef/io/Accumulable.java    |   39 -
 .../java/org/apache/reef/io/Accumulator.java    |   45 -
 .../java/org/apache/reef/io/ExternalMap.java    |   93 --
 .../main/java/org/apache/reef/io/Message.java   |   36 -
 .../java/org/apache/reef/io/PartitionSpec.java  |   49 -
 .../src/main/java/org/apache/reef/io/Spool.java |   60 -
 .../apache/reef/io/SystemTempFileCreator.java   |   66 -
 .../org/apache/reef/io/TempFileCreator.java     |   65 -
 .../src/main/java/org/apache/reef/io/Tuple.java |   67 -
 .../io/WorkingDirectoryTempFileCreator.java     |   76 -
 .../org/apache/reef/io/naming/Identifiable.java |   33 -
 .../apache/reef/io/naming/NameAssignment.java   |   44 -
 .../java/org/apache/reef/io/naming/Naming.java  |   26 -
 .../org/apache/reef/io/naming/NamingLookup.java |   43 -
 .../apache/reef/io/naming/NamingRegistry.java   |   46 -
 .../java/org/apache/reef/io/package-info.java   |   24 -
 .../org/apache/reef/io/serialization/Codec.java |   45 -
 .../reef/io/serialization/Deserializer.java     |   37 -
 .../io/serialization/SerializableCodec.java     |   67 -
 .../reef/io/serialization/Serializer.java       |   38 -
 .../runtime/common/DriverRestartCompleted.java  |   28 -
 .../apache/reef/runtime/common/Launcher.java    |  156 --
 .../runtime/common/client/ClientWireUp.java     |  104 --
 .../client/CommonClientConfigurationModule.java |   28 -
 .../runtime/common/client/CompletedJobImpl.java |   46 -
 .../common/client/JobStatusMessageHandler.java  |   50 -
 .../common/client/JobSubmissionHelper.java      |  180 ---
 .../common/client/REEFImplementation.java       |  110 --
 .../runtime/common/client/RunningJobImpl.java   |  168 ---
 .../reef/runtime/common/client/RunningJobs.java |   55 -
 .../runtime/common/client/RunningJobsImpl.java  |  148 --
 .../common/client/RuntimeErrorProtoHandler.java |   51 -
 .../client/api/ClientRuntimeParameters.java     |   29 -
 .../common/client/api/JobSubmissionHandler.java |   30 -
 .../runtime/common/client/api/package-info.java |   22 -
 .../defaults/DefaultCompletedJobHandler.java    |   47 -
 .../defaults/DefaultFailedJobHandler.java       |   43 -
 .../defaults/DefaultJobMessageHandler.java      |   48 -
 .../defaults/DefaultRunningJobHandler.java      |   47 -
 .../defaults/DefaultRuntimeErrorHandler.java    |   52 -
 .../common/client/defaults/package-info.java    |   22 -
 .../runtime/common/client/package-info.java     |   22 -
 .../common/client/parameters/ClientPresent.java |   33 -
 .../common/driver/DriverExceptionHandler.java   |   53 -
 .../driver/DriverRuntimeConfiguration.java      |   73 -
 .../DriverRuntimeConfigurationOptions.java      |   33 -
 .../driver/DriverRuntimeStartHandler.java       |   80 --
 .../common/driver/DriverRuntimeStopHandler.java |   71 -
 .../runtime/common/driver/DriverSingleton.java  |   18 -
 .../runtime/common/driver/DriverSingletons.java |   90 --
 .../common/driver/DriverStartHandler.java       |   93 --
 .../runtime/common/driver/DriverStatus.java     |   30 -
 .../common/driver/DriverStatusManager.java      |  330 -----
 .../common/driver/EvaluatorRequestorImpl.java   |   95 --
 .../api/AbstractDriverRuntimeConfiguration.java |  124 --
 .../api/DefaultResourceManagerLifeCycle.java    |   18 -
 .../driver/api/ResourceLaunchHandler.java       |   30 -
 .../driver/api/ResourceManagerLifeCycle.java    |   18 -
 .../driver/api/ResourceReleaseHandler.java      |   30 -
 .../driver/api/ResourceRequestHandler.java      |   30 -
 .../common/driver/api/RuntimeParameters.java    |   50 -
 .../runtime/common/driver/api/package-info.java |   22 -
 .../driver/catalog/NodeDescriptorImpl.java      |   78 -
 .../driver/catalog/RackDescriptorImpl.java      |   78 -
 .../driver/catalog/ResourceCatalogImpl.java     |   88 --
 .../common/driver/client/ClientConnection.java  |   82 --
 .../common/driver/client/ClientManager.java     |  148 --
 .../driver/client/JobMessageObserverImpl.java   |   44 -
 .../driver/client/LoggingJobStatusHandler.java  |   42 -
 .../common/driver/client/package-info.java      |   25 -
 .../driver/context/ClosedContextImpl.java       |   88 --
 .../driver/context/ContextControlHandler.java   |   62 -
 .../common/driver/context/ContextFactory.java   |   97 --
 .../driver/context/ContextMessageImpl.java      |   55 -
 .../driver/context/ContextRepresenters.java     |  247 ----
 .../common/driver/context/EvaluatorContext.java |  280 ----
 .../driver/context/FailedContextImpl.java       |   95 --
 .../common/driver/context/package-info.java     |   26 -
 .../defaults/DefaultClientCloseHandler.java     |   46 -
 .../DefaultClientCloseWithMessageHandler.java   |   39 -
 .../defaults/DefaultClientMessageHandler.java   |   42 -
 .../defaults/DefaultContextActiveHandler.java   |   44 -
 .../defaults/DefaultContextClosureHandler.java  |   47 -
 .../defaults/DefaultContextFailureHandler.java  |   44 -
 .../defaults/DefaultContextMessageHandler.java  |   43 -
 .../DefaultDriverRestartCompletedHandler.java   |   44 -
 ...efaultDriverRestartContextActiveHandler.java |   44 -
 .../DefaultDriverRestartTaskRunningHandler.java |   43 -
 .../DefaultEvaluatorAllocationHandler.java      |   44 -
 .../DefaultEvaluatorCompletionHandler.java      |   43 -
 .../DefaultEvaluatorFailureHandler.java         |   41 -
 .../defaults/DefaultTaskCompletionHandler.java  |   47 -
 .../defaults/DefaultTaskFailureHandler.java     |   39 -
 .../defaults/DefaultTaskMessageHandler.java     |   43 -
 .../defaults/DefaultTaskRunningHandler.java     |   43 -
 .../defaults/DefaultTaskSuspensionHandler.java  |   39 -
 .../common/driver/defaults/package-info.java    |   22 -
 .../evaluator/AllocatedEvaluatorImpl.java       |  224 ---
 .../evaluator/CompletedEvaluatorImpl.java       |   49 -
 .../evaluator/EvaluatorControlHandler.java      |  100 --
 .../evaluator/EvaluatorDescriptorImpl.java      |   75 -
 .../EvaluatorHeartBeatSanityChecker.java        |   57 -
 .../evaluator/EvaluatorHeartbeatHandler.java    |   74 -
 .../driver/evaluator/EvaluatorManager.java      |  529 -------
 .../evaluator/EvaluatorManagerFactory.java      |  105 --
 .../evaluator/EvaluatorMessageDispatcher.java   |  247 ----
 .../EvaluatorResourceManagerErrorHandler.java   |   67 -
 .../common/driver/evaluator/EvaluatorState.java |   38 -
 .../evaluator/EvaluatorStatusManager.java       |  106 --
 .../common/driver/evaluator/Evaluators.java     |  128 --
 .../driver/evaluator/FailedEvaluatorImpl.java   |   73 -
 .../common/driver/evaluator/package-info.java   |   26 -
 .../common/driver/idle/ClockIdlenessSource.java |   60 -
 .../common/driver/idle/DriverIdleManager.java   |   73 -
 .../driver/idle/DriverIdlenessSource.java       |   31 -
 .../driver/idle/EventHandlerIdlenessSource.java |   59 -
 .../runtime/common/driver/idle/IdleMessage.java |   61 -
 .../common/driver/idle/package-info.java        |   22 -
 .../runtime/common/driver/package-info.java     |   22 -
 .../resourcemanager/NodeDescriptorHandler.java  |   46 -
 .../ResourceAllocationHandler.java              |   63 -
 .../ResourceManagerErrorHandler.java            |   44 -
 .../resourcemanager/ResourceManagerStatus.java  |  156 --
 .../resourcemanager/ResourceStatusHandler.java  |   71 -
 .../driver/resourcemanager/package-info.java    |   22 -
 .../common/driver/task/CompletedTaskImpl.java   |   60 -
 .../common/driver/task/RunningTaskImpl.java     |  138 --
 .../common/driver/task/SuspendedTaskImpl.java   |   58 -
 .../common/driver/task/TaskMessageImpl.java     |   61 -
 .../common/driver/task/TaskRepresenter.java     |  202 ---
 .../common/driver/task/package-info.java        |   26 -
 .../evaluator/DefaultDriverConnection.java      |   48 -
 .../common/evaluator/DriverConnection.java      |   31 -
 .../evaluator/EvaluatorConfiguration.java       |   68 -
 .../common/evaluator/EvaluatorRuntime.java      |  207 ---
 .../common/evaluator/HeartBeatManager.java      |  173 ---
 .../common/evaluator/PIDStoreStartHandler.java  |   56 -
 .../context/ContextClientCodeException.java     |   78 -
 .../evaluator/context/ContextLifeCycle.java     |   97 --
 .../evaluator/context/ContextManager.java       |  374 -----
 .../evaluator/context/ContextRuntime.java       |  436 ------
 .../evaluator/context/ContextStartImpl.java     |   37 -
 .../evaluator/context/ContextStopImpl.java      |   35 -
 .../evaluator/context/RootContextLauncher.java  |  134 --
 .../defaults/DefaultContextMessageHandler.java  |   45 -
 .../defaults/DefaultContextMessageSource.java   |   44 -
 .../defaults/DefaultContextStartHandler.java    |   43 -
 .../defaults/DefaultContextStopHandler.java     |   43 -
 .../context/defaults/package-info.java          |   22 -
 .../common/evaluator/context/package-info.java  |   22 -
 .../runtime/common/evaluator/package-info.java  |   22 -
 .../parameters/ApplicationIdentifier.java       |   33 -
 .../parameters/DriverRemoteIdentifier.java      |   31 -
 .../parameters/EvaluatorIdentifier.java         |   31 -
 .../evaluator/parameters/HeartbeatPeriod.java   |   31 -
 .../parameters/InitialTaskConfiguration.java    |   31 -
 .../parameters/RootContextConfiguration.java    |   31 -
 .../parameters/RootServiceConfiguration.java    |   31 -
 .../common/evaluator/task/CloseEventImpl.java   |   45 -
 .../evaluator/task/DriverMessageImpl.java       |   44 -
 .../common/evaluator/task/SuspendEventImpl.java |   45 -
 .../evaluator/task/TaskClientCodeException.java |   77 -
 .../evaluator/task/TaskLifeCycleHandlers.java   |   90 --
 .../common/evaluator/task/TaskRuntime.java      |  313 ----
 .../common/evaluator/task/TaskStartImpl.java    |   43 -
 .../common/evaluator/task/TaskStatus.java       |  310 ----
 .../common/evaluator/task/TaskStopImpl.java     |   42 -
 .../task/defaults/DefaultCloseHandler.java      |   41 -
 .../defaults/DefaultDriverMessageHandler.java   |   41 -
 .../task/defaults/DefaultSuspendHandler.java    |   41 -
 .../evaluator/task/defaults/package-info.java   |   22 -
 .../task/exceptions/TaskCallFailure.java        |   37 -
 .../exceptions/TaskCloseHandlerFailure.java     |   37 -
 .../exceptions/TaskMessageHandlerFailure.java   |   37 -
 .../exceptions/TaskStartHandlerFailure.java     |   39 -
 .../task/exceptions/TaskStopHandlerFailure.java |   39 -
 .../exceptions/TaskSuspendHandlerFailure.java   |   37 -
 .../common/evaluator/task/package-info.java     |   22 -
 .../runtime/common/files/ClasspathProvider.java |   83 --
 .../reef/runtime/common/files/JobJarMaker.java  |  136 --
 .../runtime/common/files/REEFFileNames.java     |  216 ---
 .../common/files/RuntimeClasspathProvider.java  |   48 -
 .../reef/runtime/common/files/package-info.java |   22 -
 .../common/launch/CLRLaunchCommandBuilder.java  |   99 --
 .../common/launch/JavaLaunchCommandBuilder.java |  163 ---
 .../reef/runtime/common/launch/LaunchClass.java |  191 ---
 .../common/launch/LaunchCommandBuilder.java     |   66 -
 .../common/launch/LauncherSingletons.java       |   18 -
 .../common/launch/ProfilingStopHandler.java     |   58 -
 .../runtime/common/launch/REEFErrorHandler.java |  101 --
 .../runtime/common/launch/REEFMessageCodec.java |   96 --
 .../launch/REEFUncaughtExceptionHandler.java    |   67 -
 .../runtime/common/launch/package-info.java     |   22 -
 .../parameters/ClockConfigurationPath.java      |   30 -
 .../launch/parameters/ErrorHandlerRID.java      |   37 -
 .../common/launch/parameters/LaunchID.java      |   27 -
 .../common/launch/parameters/package-info.java  |   22 -
 .../reef/runtime/common/package-info.java       |   26 -
 .../common/parameters/DeleteTempFiles.java      |   31 -
 .../runtime/common/parameters/JVMHeapSlack.java |   29 -
 .../common/utils/BroadCastEventHandler.java     |   44 -
 .../common/utils/DefaultExceptionCodec.java     |   64 -
 .../runtime/common/utils/DispatchingEStage.java |  143 --
 .../runtime/common/utils/ExceptionCodec.java    |   50 -
 .../runtime/common/utils/RemoteManager.java     |   76 -
 .../reef/task/HeartBeatTriggerManager.java      |   53 -
 .../main/java/org/apache/reef/task/Task.java    |   48 -
 .../java/org/apache/reef/task/TaskMessage.java  |   67 -
 .../org/apache/reef/task/TaskMessageSource.java |   39 -
 .../org/apache/reef/task/events/CloseEvent.java |   38 -
 .../apache/reef/task/events/DriverMessage.java  |   38 -
 .../apache/reef/task/events/SuspendEvent.java   |   38 -
 .../org/apache/reef/task/events/TaskStart.java  |   37 -
 .../org/apache/reef/task/events/TaskStop.java   |   36 -
 .../main/java/org/apache/reef/util/Builder.java |   35 -
 .../java/org/apache/reef/util/CommandUtils.java |   55 -
 .../org/apache/reef/util/EnvironmentUtils.java  |  153 --
 .../util/ExceptionHandlingEventHandler.java     |   50 -
 .../java/org/apache/reef/util/Exceptions.java   |   42 -
 .../java/org/apache/reef/util/JARFileMaker.java |  114 --
 .../java/org/apache/reef/util/MemoryUtils.java  |  120 --
 .../main/java/org/apache/reef/util/OSUtils.java |  105 --
 .../reef/util/ObjectInstantiationLogger.java    |   33 -
 .../java/org/apache/reef/util/REEFVersion.java  |   84 --
 .../main/java/org/apache/reef/util/SetOnce.java |   51 -
 .../org/apache/reef/util/SingletonAsserter.java |   41 -
 .../java/org/apache/reef/util/ThreadLogger.java |   94 --
 .../org/apache/reef/util/logging/Config.java    |   31 -
 .../apache/reef/util/logging/LogLevelName.java  |   30 -
 .../org/apache/reef/util/logging/LogParser.java |  164 ---
 .../apache/reef/util/logging/LoggingScope.java  |   29 -
 .../reef/util/logging/LoggingScopeFactory.java  |  343 -----
 .../reef/util/logging/LoggingScopeImpl.java     |  104 --
 .../apache/reef/util/logging/LoggingSetup.java  |   37 -
 .../reef/util/logging/ThreadLogFormatter.java   |  141 --
 .../java/org/apache/reef/util/package-info.java |   22 -
 reef-common/src/main/proto/client_runtime.proto |   54 -
 reef-common/src/main/proto/driver_runtime.proto |   89 --
 .../src/main/proto/evaluator_runtime.proto      |   90 --
 reef-common/src/main/proto/reef_protocol.proto  |   42 -
 .../src/main/proto/reef_service_protos.proto    |  116 --
 reef-common/src/main/resources/log4j.properties |   27 -
 .../org/apache/reef/logging.properties          |   85 --
 .../src/main/resources/version.properties       |   18 -
 .../driver/EvaluatorRequestorImplTest.java      |  110 --
 .../common/driver/catalog/CatalogTest.java      |   54 -
 .../org/apache/reef/util/LoggingScopeTest.java  |  100 --
 .../apache/reef/util/SingletonAsserterTest.java |   34 -
 reef-examples-clr/pom.xml                       |  182 ---
 .../apache/reef/examples/helloCLR/HelloCLR.java |   93 --
 .../reef/examples/helloCLR/HelloDriver.java     |  183 ---
 .../reef/examples/helloCLR/package-info.java    |   22 -
 .../examples/retained_evalCLR/JobClient.java    |  317 ----
 .../examples/retained_evalCLR/JobDriver.java    |  489 -------
 .../reef/examples/retained_evalCLR/Launch.java  |  189 ---
 .../examples/retained_evalCLR/package-info.java |   22 -
 reef-examples-hdinsight/pom.xml                 |  128 --
 .../reef/examples/hello/HelloHDInsight.java     |   33 -
 reef-examples/.gitignore                        |    1 -
 reef-examples/pom.xml                           |  365 -----
 .../examples/data/loading/DataLoadingREEF.java  |  128 --
 .../reef/examples/data/loading/LineCounter.java |  126 --
 .../examples/data/loading/LineCountingTask.java |   59 -
 .../apache/reef/examples/hello/HelloDriver.java |   84 --
 .../apache/reef/examples/hello/HelloREEF.java   |   77 -
 .../reef/examples/hello/HelloREEFMesos.java     |   55 -
 .../reef/examples/hello/HelloREEFNoClient.java  |   64 -
 .../reef/examples/hello/HelloReefYarn.java      |   70 -
 .../apache/reef/examples/hello/HelloTask.java   |   39 -
 .../reef/examples/hello/package-info.java       |   22 -
 .../reef/examples/hellohttp/HelloREEFHttp.java  |  112 --
 .../examples/hellohttp/HelloREEFHttpYarn.java   |   52 -
 .../hellohttp/HttpServerShellCmdtHandler.java   |  168 ---
 .../examples/hellohttp/HttpShellJobDriver.java  |  364 -----
 .../apache/reef/examples/library/Command.java   |   29 -
 .../apache/reef/examples/library/ShellTask.java |   73 -
 .../apache/reef/examples/pool/JobDriver.java    |  306 ----
 .../org/apache/reef/examples/pool/Launch.java   |  216 ---
 .../apache/reef/examples/pool/SleepTask.java    |   73 -
 .../apache/reef/examples/pool/package-info.java |   23 -
 .../reef/examples/retained_eval/JobClient.java  |  335 -----
 .../reef/examples/retained_eval/JobDriver.java  |  370 -----
 .../reef/examples/retained_eval/Launch.java     |  185 ---
 .../examples/retained_eval/package-info.java    |   22 -
 .../reef/examples/scheduler/Scheduler.java      |  226 ---
 .../examples/scheduler/SchedulerDriver.java     |  339 -----
 .../scheduler/SchedulerHttpHandler.java         |  107 --
 .../reef/examples/scheduler/SchedulerREEF.java  |  109 --
 .../examples/scheduler/SchedulerREEFYarn.java   |   46 -
 .../examples/scheduler/SchedulerResponse.java   |  114 --
 .../reef/examples/scheduler/TaskEntity.java     |   71 -
 .../reef/examples/scheduler/package-info.java   |   22 -
 .../apache/reef/examples/suspend/Control.java   |  103 --
 .../apache/reef/examples/suspend/Launch.java    |  174 ---
 .../examples/suspend/ObjectWritableCodec.java   |   93 --
 .../reef/examples/suspend/SuspendClient.java    |  172 ---
 .../examples/suspend/SuspendClientControl.java  |   92 --
 .../reef/examples/suspend/SuspendDriver.java    |  340 -----
 .../reef/examples/suspend/SuspendTestTask.java  |  179 ---
 .../reef/examples/suspend/package-info.java     |   22 -
 .../utils/wake/BlockingEventHandler.java        |   63 -
 .../utils/wake/LoggingEventHandler.java         |   58 -
 .../reef/examples/hello/HelloHttpTest.java      |   41 -
 .../suspend/ObjectWritableCodecTest.java        |   50 -
 reef-io/pom.xml                                 |  143 --
 reef-io/src/main/avro/nameservice.avsc          |   64 -
 .../reef/io/data/loading/api/DataLoader.java    |  236 ---
 .../api/DataLoadingDriverConfiguration.java     |   33 -
 .../loading/api/DataLoadingRequestBuilder.java  |  190 ---
 .../io/data/loading/api/DataLoadingService.java |   68 -
 .../reef/io/data/loading/api/DataSet.java       |   43 -
 .../loading/api/ResourceRequestHandler.java     |   64 -
 .../impl/EvaluatorRequestSerializer.java        |   63 -
 .../impl/EvaluatorToPartitionMapper.java        |  154 --
 .../impl/InMemoryInputFormatDataSet.java        |   53 -
 .../data/loading/impl/InputFormatDataSet.java   |  156 --
 .../impl/InputFormatExternalConstructor.java    |   50 -
 .../loading/impl/InputFormatLoadingService.java |  172 ---
 .../impl/InputSplitExternalConstructor.java     |   57 -
 .../impl/JobConfExternalConstructor.java        |   88 --
 .../io/data/loading/impl/NumberedSplit.java     |   65 -
 .../data/loading/impl/WritableSerializer.java   |   93 --
 .../java/org/apache/reef/io/network/Cache.java  |   53 -
 .../org/apache/reef/io/network/Connection.java  |   52 -
 .../reef/io/network/ConnectionFactory.java      |   37 -
 .../org/apache/reef/io/network/Message.java     |   50 -
 .../reef/io/network/TransportFactory.java       |   43 -
 .../exception/NetworkRuntimeException.java      |   54 -
 .../network/exception/ParentDeadException.java  |   48 -
 .../reef/io/network/exception/package-info.java |   19 -
 .../reef/io/network/impl/BindNSToTask.java      |   45 -
 .../network/impl/MessagingTransportFactory.java |   60 -
 .../reef/io/network/impl/NSConnection.java      |  134 --
 .../apache/reef/io/network/impl/NSMessage.java  |   90 --
 .../reef/io/network/impl/NSMessageCodec.java    |  134 --
 .../network/impl/NameServiceCloseHandler.java   |   49 -
 .../reef/io/network/impl/NetworkService.java    |  235 ---
 .../impl/NetworkServiceClosingHandler.java      |   43 -
 .../network/impl/NetworkServiceParameters.java  |   60 -
 .../reef/io/network/impl/StreamingCodec.java    |   35 -
 .../reef/io/network/impl/UnbindNSFromTask.java  |   45 -
 .../reef/io/network/impl/package-info.java      |   19 -
 .../io/network/naming/NameAssignmentTuple.java  |   65 -
 .../reef/io/network/naming/NameCache.java       |   72 -
 .../reef/io/network/naming/NameClient.java      |  212 ---
 .../io/network/naming/NameLookupClient.java     |  257 ----
 .../io/network/naming/NameRegistryClient.java   |  200 ---
 .../reef/io/network/naming/NameServer.java      |   88 --
 .../network/naming/NameServerConfiguration.java |   51 -
 .../reef/io/network/naming/NameServerImpl.java  |  300 ----
 .../io/network/naming/NameServerParameters.java |   40 -
 .../io/network/naming/NamingCodecFactory.java   |   82 --
 .../naming/exception/NamingException.java       |   56 -
 .../exception/NamingRuntimeException.java       |   56 -
 .../network/naming/exception/package-info.java  |   19 -
 .../reef/io/network/naming/package-info.java    |   19 -
 .../network/naming/serialization/AvroUtils.java |   68 -
 .../serialization/NamingLookupRequest.java      |   46 -
 .../serialization/NamingLookupRequestCodec.java |   79 -
 .../serialization/NamingLookupResponse.java     |   48 -
 .../NamingLookupResponseCodec.java              |   94 --
 .../naming/serialization/NamingMessage.java     |   46 -
 .../serialization/NamingRegisterRequest.java    |   46 -
 .../NamingRegisterRequestCodec.java             |   76 -
 .../serialization/NamingRegisterResponse.java   |   44 -
 .../NamingRegisterResponseCodec.java            |   60 -
 .../serialization/NamingUnregisterRequest.java  |   46 -
 .../NamingUnregisterRequestCodec.java           |   72 -
 .../naming/serialization/package-info.java      |   22 -
 .../apache/reef/io/network/package-info.java    |   19 -
 .../apache/reef/io/network/util/ListCodec.java  |   83 --
 .../org/apache/reef/io/network/util/Pair.java   |   42 -
 .../reef/io/network/util/StringCodec.java       |   42 -
 .../reef/io/network/util/StringIdentifier.java  |   80 --
 .../network/util/StringIdentifierFactory.java   |   46 -
 .../reef/io/network/util/package-info.java      |   19 -
 .../reef/io/storage/FramingInputStream.java     |   76 -
 .../reef/io/storage/FramingOutputStream.java    |  134 --
 .../io/storage/FramingTupleDeserializer.java    |  100 --
 .../reef/io/storage/FramingTupleSerializer.java |   86 --
 .../apache/reef/io/storage/MergingIterator.java |   62 -
 .../apache/reef/io/storage/ScratchSpace.java    |   27 -
 .../apache/reef/io/storage/StorageService.java  |   25 -
 .../io/storage/local/CodecFileAccumulable.java  |   52 -
 .../io/storage/local/CodecFileAccumulator.java  |   58 -
 .../io/storage/local/CodecFileIterable.java     |   53 -
 .../io/storage/local/CodecFileIterator.java     |   82 --
 .../io/storage/local/LocalScratchSpace.java     |   87 --
 .../io/storage/local/LocalStorageService.java   |   44 -
 .../io/storage/local/SerializerFileSpool.java   |  101 --
 .../apache/reef/io/storage/ram/CodecRamMap.java |   84 --
 .../org/apache/reef/io/storage/ram/RamMap.java  |   74 -
 .../apache/reef/io/storage/ram/RamSpool.java    |   72 -
 .../reef/io/storage/ram/RamStorageService.java  |   38 -
 .../reef/io/storage/ram/SortingRamSpool.java    |   90 --
 .../reef/io/storage/util/GetAllIterable.java    |   95 --
 .../reef/io/storage/util/IntegerCodec.java      |   35 -
 .../io/storage/util/IntegerDeserializer.java    |   62 -
 .../reef/io/storage/util/IntegerSerializer.java |   62 -
 .../io/storage/util/StringDeserializer.java     |   66 -
 .../reef/io/storage/util/StringSerializer.java  |   65 -
 .../io/storage/util/TupleKeyComparator.java     |   37 -
 reef-io/src/main/proto/ns_protocol.proto        |   32 -
 .../reef/services/network/NameClientTest.java   |  123 --
 .../reef/services/network/NamingTest.java       |  367 -----
 .../services/network/NetworkServiceTest.java    |  495 -------
 .../apache/reef/services/network/TestEvent.java |   38 -
 .../services/network/util/LoggingUtils.java     |   43 -
 .../reef/services/network/util/Monitor.java     |   39 -
 .../reef/services/network/util/StringCodec.java |   34 -
 .../services/network/util/TimeoutHandler.java   |   36 -
 .../services/network/util/package-info.java     |   19 -
 .../reef/services/storage/ExternalMapTest.java  |   94 --
 .../reef/services/storage/FramingTest.java      |  104 --
 .../services/storage/MergingIteratorTest.java   |   54 -
 .../reef/services/storage/SortingSpoolTest.java |  117 --
 .../reef/services/storage/SpoolFileTest.java    |  206 ---
 .../services/storage/TupleSerializerTest.java   |  105 --
 reef-poison/pom.xml                             |   52 -
 .../org/apache/reef/poison/PoisonException.java |   28 -
 .../reef/poison/PoisonedAlarmHandler.java       |   33 -
 .../reef/poison/PoisonedConfiguration.java      |   57 -
 .../context/PoisonedContextStartHandler.java    |   77 -
 .../PoissonPoisonedContextStartHandler.java     |   57 -
 .../reef/poison/context/package-info.java       |   22 -
 .../org/apache/reef/poison/package-info.java    |   22 -
 .../reef/poison/params/CrashProbability.java    |   30 -
 .../apache/reef/poison/params/CrashTimeout.java |   27 -
 .../poison/task/PoisonedTaskStartHandler.java   |   77 -
 .../task/PoissonPoisonedTaskStartHandler.java   |   57 -
 .../apache/reef/poison/task/package-info.java   |   22 -
 reef-runtime-hdinsight/pom.xml                  |   82 --
 .../hdinsight/HDInsightClasspathProvider.java   |   73 -
 .../reef/runtime/hdinsight/cli/HDICLI.java      |  173 ---
 .../reef/runtime/hdinsight/cli/LogFetcher.java  |  134 --
 .../runtime/hdinsight/cli/LogFileEntry.java     |  113 --
 .../reef/runtime/hdinsight/cli/TFileParser.java |   97 --
 .../runtime/hdinsight/cli/package-info.java     |   22 -
 .../runtime/hdinsight/client/AzureUploader.java |  151 --
 .../client/HDInsightDriverConfiguration.java    |   95 --
 .../client/HDInsightJobSubmissionHandler.java   |  180 ---
 .../client/HDInsightRuntimeConfiguration.java   |  123 --
 .../HDInsightRuntimeConfigurationStatic.java    |   53 -
 .../UnsafeHDInsightRuntimeConfiguration.java    |  118 --
 ...safeHDInsightRuntimeConfigurationStatic.java |   50 -
 .../runtime/hdinsight/client/package-info.java  |   22 -
 .../sslhacks/DefaultClientConstructor.java      |   39 -
 .../sslhacks/UnsafeClientConstructor.java       |   72 -
 .../client/sslhacks/UnsafeHostNameVerifier.java |   50 -
 .../client/sslhacks/UnsafeTrustManager.java     |   49 -
 .../client/yarnrest/ApplicationID.java          |   52 -
 .../client/yarnrest/ApplicationResponse.java    |   44 -
 .../client/yarnrest/ApplicationState.java       |  214 ---
 .../client/yarnrest/ApplicationSubmission.java  |  167 ---
 .../client/yarnrest/ContainerInfo.java          |  125 --
 .../client/yarnrest/EnvironmentEntry.java       |   76 -
 .../hdinsight/client/yarnrest/FileResource.java |   89 --
 .../client/yarnrest/HDInsightInstance.java      |  211 ---
 .../client/yarnrest/LocalResourcesEntry.java    |   48 -
 .../hdinsight/client/yarnrest/Resource.java     |   54 -
 .../hdinsight/client/yarnrest/package-info.java |   24 -
 .../reef/runtime/hdinsight/package-info.java    |   22 -
 .../AzureStorageAccountContainerName.java       |   29 -
 .../parameters/AzureStorageAccountKey.java      |   29 -
 .../parameters/AzureStorageAccountName.java     |   29 -
 .../parameters/AzureStorageBaseFolder.java      |   29 -
 .../parameters/HDInsightInstanceURL.java        |   29 -
 .../hdinsight/parameters/HDInsightPassword.java |   29 -
 .../hdinsight/parameters/HDInsightUsername.java |   29 -
 reef-runtime-local/pom.xml                      |   62 -
 .../runtime/local/LocalClasspathProvider.java   |  134 --
 .../reef/runtime/local/client/DriverFiles.java  |  174 ---
 .../client/ExecutorServiceConstructor.java      |   44 -
 .../reef/runtime/local/client/FileSet.java      |  113 --
 .../local/client/LocalJobSubmissionHandler.java |  166 ---
 .../local/client/LocalRuntimeConfiguration.java |   82 --
 .../reef/runtime/local/client/package-info.java |   22 -
 .../client/parameters/DefaultMemorySize.java    |   29 -
 .../client/parameters/DefaultNumberOfCores.java |   29 -
 .../client/parameters/NumberOfProcesses.java    |   29 -
 .../local/client/parameters/RootFolder.java     |   30 -
 .../local/client/parameters/package-info.java   |   22 -
 .../reef/runtime/local/driver/Container.java    |   85 --
 .../runtime/local/driver/ContainerManager.java  |  202 ---
 .../reef/runtime/local/driver/IDMaker.java      |   47 -
 .../local/driver/LocalDriverConfiguration.java  |   81 --
 .../driver/LocalDriverRuntimeConfiguration.java |   30 -
 .../driver/LocalResourceLaunchHandler.java      |   46 -
 .../driver/LocalResourceReleaseHandler.java     |   47 -
 .../driver/LocalResourceRequestHandler.java     |   46 -
 .../runtime/local/driver/ProcessContainer.java  |  178 ---
 .../runtime/local/driver/ResourceManager.java   |  270 ----
 .../runtime/local/driver/ResourceRequest.java   |   63 -
 .../local/driver/ResourceRequestQueue.java      |   70 -
 .../reef/runtime/local/driver/package-info.java |   22 -
 .../local/driver/parameters/GlobalFiles.java    |   31 -
 .../driver/parameters/GlobalLibraries.java      |   31 -
 .../local/driver/parameters/LocalFiles.java     |   31 -
 .../local/driver/parameters/LocalLibraries.java |   31 -
 .../local/driver/parameters/package-info.java   |   22 -
 .../process/LoggingRunnableProcessObserver.java |   44 -
 .../process/ReefRunnableProcessObserver.java    |  125 --
 .../runtime/local/process/RunnableProcess.java  |  277 ----
 .../local/process/RunnableProcessObserver.java  |   39 -
 .../runtime/local/process/package-info.java     |   22 -
 .../local/driver/ResourceRequestQueueTest.java  |   63 -
 .../local/driver/ResourceRequestTest.java       |   61 -
 reef-runtime-mesos/pom.xml                      |   95 --
 .../src/main/avro/EvaluatorControl.avsc         |   47 -
 .../runtime/mesos/MesosClasspathProvider.java   |   92 --
 .../mesos/client/MesosClientConfiguration.java  |   68 -
 .../mesos/client/MesosJobSubmissionHandler.java |  141 --
 .../mesos/client/parameters/MasterIp.java       |   26 -
 .../mesos/client/parameters/RootFolder.java     |   26 -
 .../mesos/driver/MesosDriverConfiguration.java  |   98 --
 .../driver/MesosResourceLaunchHandler.java      |  129 --
 .../driver/MesosResourceReleaseHandler.java     |   42 -
 .../driver/MesosResourceRequestHandler.java     |   42 -
 .../mesos/driver/MesosRuntimeStartHandler.java  |   38 -
 .../mesos/driver/MesosRuntimeStopHandler.java   |   38 -
 .../driver/MesosSchedulerDriverExecutor.java    |   42 -
 .../runtime/mesos/driver/REEFEventHandlers.java |   65 -
 .../reef/runtime/mesos/driver/REEFExecutor.java |   50 -
 .../runtime/mesos/driver/REEFExecutors.java     |   64 -
 .../runtime/mesos/driver/REEFScheduler.java     |  506 -------
 .../mesos/driver/parameters/MesosMasterIp.java  |   26 -
 .../evaluator/EvaluatorControlHandler.java      |   55 -
 .../runtime/mesos/evaluator/REEFExecutor.java   |  249 ----
 .../evaluator/parameters/MesosExecutorId.java   |   26 -
 .../util/HDFSConfigurationConstructor.java      |   35 -
 .../runtime/mesos/util/MesosErrorHandler.java   |   43 -
 .../runtime/mesos/util/MesosRemoteManager.java  |   62 -
 .../mesos/util/MesosRemoteManagerCodec.java     |   68 -
 reef-runtime-yarn/pom.xml                       |   80 --
 .../reef/runtime/yarn/ClassPathBuilder.java     |  109 --
 .../runtime/yarn/YarnClasspathProvider.java     |  140 --
 .../yarn/client/YarnClientConfiguration.java    |   73 -
 .../yarn/client/YarnJobSubmissionHandler.java   |  277 ----
 .../yarn/client/parameters/JobPriority.java     |   29 -
 .../yarn/client/parameters/JobQueue.java        |   29 -
 .../driver/ApplicationMasterRegistration.java   |   62 -
 .../yarn/driver/ContainerRequestCounter.java    |   71 -
 .../reef/runtime/yarn/driver/Containers.java    |  109 --
 .../yarn/driver/DefaultTrackingURLProvider.java |   33 -
 .../yarn/driver/EvaluatorSetupHelper.java       |  147 --
 .../runtime/yarn/driver/GlobalJarUploader.java  |   92 --
 .../runtime/yarn/driver/REEFEventHandlers.java  |   91 --
 .../yarn/driver/TrackingURLProvider.java        |   29 -
 .../yarn/driver/UploaderToJobfolder.java        |   94 --
 .../yarn/driver/YARNResourceLaunchHandler.java  |  125 --
 .../yarn/driver/YARNResourceReleaseHandler.java |   50 -
 .../yarn/driver/YARNRuntimeStartHandler.java    |   42 -
 .../yarn/driver/YARNRuntimeStopHandler.java     |   42 -
 .../yarn/driver/YarnContainerManager.java       |  680 ---------
 .../driver/YarnContainerRequestHandler.java     |   32 -
 .../driver/YarnContainerRequestHandlerImpl.java |   47 -
 .../yarn/driver/YarnDriverConfiguration.java    |   95 --
 .../yarn/driver/YarnResourceRequestHandler.java |  111 --
 .../reef/runtime/yarn/driver/package-info.java  |   22 -
 .../parameters/JobSubmissionDirectory.java      |   29 -
 .../driver/parameters/YarnHeartbeatPeriod.java  |   29 -
 .../yarn/util/YarnConfigurationConstructor.java |   38 -
 .../reef/runtime/yarn/util/YarnTypes.java       |   59 -
 .../driver/YarnResourceRequestHandlerTest.java  |  127 --
 reef-tang/.gitattributes                        |    3 -
 reef-tang/.gitignore                            |   15 -
 reef-tang/README.md                             |  562 --------
 reef-tang/doc/tangdoc.png                       |  Bin 32351 -> 0 bytes
 reef-tang/doc/tooltip.png                       |  Bin 9677 -> 0 bytes
 reef-tang/pom.xml                               |   40 -
 reef-tang/tang-test-jarA/pom.xml                |   31 -
 .../java/org/apache/reef/tang/examples/A.java   |   23 -
 reef-tang/tang-test-jarAB/pom.xml               |   38 -
 .../java/org/apache/reef/tang/examples/A.java   |   25 -
 .../java/org/apache/reef/tang/examples/B.java   |   25 -
 reef-tang/tang-test-jarB-conflictA/pom.xml      |   31 -
 reef-tang/tang-test-jarB/pom.xml                |   39 -
 .../java/org/apache/reef/tang/examples/B.java   |   23 -
 reef-tang/tang/.gitignore                       |    2 -
 reef-tang/tang/maven-eclipse.xml                |   28 -
 reef-tang/tang/pom.xml                          |  171 ---
 reef-tang/tang/src/main/avro/configuration.avsc |   37 -
 .../main/java/org/apache/reef/tang/Aspect.java  |   74 -
 .../java/org/apache/reef/tang/BindLocation.java |   38 -
 .../org/apache/reef/tang/ClassHierarchy.java    |   86 --
 .../org/apache/reef/tang/Configuration.java     |  167 ---
 .../apache/reef/tang/ConfigurationBuilder.java  |  251 ----
 .../org/apache/reef/tang/Configurations.java    |   59 -
 .../apache/reef/tang/ExternalConstructor.java   |   40 -
 .../org/apache/reef/tang/InjectionFuture.java   |  136 --
 .../java/org/apache/reef/tang/Injector.java     |  133 --
 .../apache/reef/tang/JavaClassHierarchy.java    |   67 -
 .../reef/tang/JavaConfigurationBuilder.java     |   98 --
 .../main/java/org/apache/reef/tang/Tang.java    |  149 --
 .../tang/annotations/DefaultImplementation.java |   42 -
 .../org/apache/reef/tang/annotations/Name.java  |   23 -
 .../reef/tang/annotations/NamedParameter.java   |   40 -
 .../apache/reef/tang/annotations/Parameter.java |   31 -
 .../org/apache/reef/tang/annotations/Unit.java  |   47 -
 .../reef/tang/annotations/package-info.java     |   23 -
 .../reef/tang/examples/PrintTypeHierarchy.java  |  105 --
 .../org/apache/reef/tang/examples/Timer.java    |   73 -
 .../org/apache/reef/tang/examples/TimerV1.java  |   66 -
 .../apache/reef/tang/examples/package-info.java |   22 -
 .../apache/reef/tang/examples/timer/Timer.java  |   33 -
 .../reef/tang/examples/timer/TimerImpl.java     |   42 -
 .../reef/tang/examples/timer/TimerMock.java     |   66 -
 .../reef/tang/examples/timer/package-info.java  |   23 -
 .../reef/tang/exceptions/BindException.java     |   43 -
 .../exceptions/ClassHierarchyException.java     |   40 -
 .../tang/exceptions/InjectionException.java     |   44 -
 .../exceptions/NameResolutionException.java     |   40 -
 .../reef/tang/exceptions/ParseException.java    |   36 -
 .../reef/tang/exceptions/package-info.java      |   28 -
 .../formats/AvroConfigurationSerializer.java    |  313 ----
 .../apache/reef/tang/formats/CommandLine.java   |  218 ---
 .../reef/tang/formats/ConfigurationFile.java    |  253 ----
 .../reef/tang/formats/ConfigurationModule.java  |  299 ----
 .../formats/ConfigurationModuleBuilder.java     |  385 -----
 .../tang/formats/ConfigurationSerializer.java   |  154 --
 .../java/org/apache/reef/tang/formats/Impl.java |   22 -
 .../apache/reef/tang/formats/OptionalImpl.java  |   22 -
 .../reef/tang/formats/OptionalParameter.java    |   22 -
 .../org/apache/reef/tang/formats/Param.java     |   22 -
 .../reef/tang/formats/ParameterParser.java      |  150 --
 .../org/apache/reef/tang/formats/Provides.java  |   22 -
 .../apache/reef/tang/formats/RequiredImpl.java  |   22 -
 .../reef/tang/formats/RequiredParameter.java    |   22 -
 .../apache/reef/tang/formats/package-info.java  |   29 -
 .../ConfigurationBuilderImpl.java               |  378 -----
 .../tang/implementation/ConfigurationImpl.java  |  143 --
 .../reef/tang/implementation/Constructor.java   |  186 ---
 .../implementation/InjectionFuturePlan.java     |   64 -
 .../reef/tang/implementation/InjectionPlan.java |  161 ---
 .../tang/implementation/ListInjectionPlan.java  |  106 --
 .../tang/implementation/SetInjectionPlan.java   |  106 --
 .../tang/implementation/StackBindLocation.java  |   46 -
 .../reef/tang/implementation/Subplan.java       |  188 ---
 .../reef/tang/implementation/TangImpl.java      |  161 ---
 .../implementation/java/ClassHierarchyImpl.java |  448 ------
 .../tang/implementation/java/InjectorImpl.java  |  760 ----------
 .../java/JavaConfigurationBuilderImpl.java      |  238 ---
 .../tang/implementation/java/JavaInstance.java  |   75 -
 .../implementation/java/JavaNodeFactory.java    |  333 -----
 .../tang/implementation/java/package-info.java  |   29 -
 .../reef/tang/implementation/package-info.java  |   27 -
 .../protobuf/ProtocolBufferClassHierarchy.java  |  396 -----
 .../protobuf/ProtocolBufferInjectionPlan.java   |  148 --
 .../implementation/protobuf/package-info.java   |   25 -
 .../tang/implementation/types/AbstractNode.java |  127 --
 .../implementation/types/ClassNodeImpl.java     |  141 --
 .../types/ConstructorArgImpl.java               |   77 -
 .../types/ConstructorDefImpl.java               |  150 --
 .../types/NamedParameterNodeImpl.java           |   86 --
 .../implementation/types/PackageNodeImpl.java   |   43 -
 .../tang/implementation/types/package-info.java |   26 -
 .../java/org/apache/reef/tang/package-info.java |   27 -
 .../org/apache/reef/tang/types/ClassNode.java   |   47 -
 .../apache/reef/tang/types/ConstructorArg.java  |   30 -
 .../apache/reef/tang/types/ConstructorDef.java  |   29 -
 .../reef/tang/types/NamedParameterNode.java     |   36 -
 .../java/org/apache/reef/tang/types/Node.java   |   42 -
 .../org/apache/reef/tang/types/PackageNode.java |   23 -
 .../org/apache/reef/tang/types/Traversable.java |   26 -
 .../apache/reef/tang/types/package-info.java    |   26 -
 .../tang/util/AbstractMonotonicMultiMap.java    |  206 ---
 .../apache/reef/tang/util/MonotonicHashMap.java |   58 -
 .../apache/reef/tang/util/MonotonicHashSet.java |   91 --
 .../reef/tang/util/MonotonicMultiHashMap.java   |   25 -
 .../reef/tang/util/MonotonicMultiMap.java       |   25 -
 .../org/apache/reef/tang/util/MonotonicSet.java |   91 --
 .../apache/reef/tang/util/MonotonicTreeMap.java |  119 --
 .../reef/tang/util/ReflectionUtilities.java     |  397 -----
 .../java/org/apache/reef/tang/util/Tint.java    |  735 ----------
 .../reef/tang/util/TracingMonotonicMap.java     |   25 -
 .../reef/tang/util/TracingMonotonicTreeMap.java |  146 --
 .../reef/tang/util/ValidateConfiguration.java   |  150 --
 .../org/apache/reef/tang/util/package-info.java |   24 -
 .../walk/AbstractClassHierarchyNodeVisitor.java |   79 -
 .../walk/AbstractInjectionPlanNodeVisitor.java  |   80 --
 .../apache/reef/tang/util/walk/EdgeVisitor.java |   35 -
 .../apache/reef/tang/util/walk/NodeVisitor.java |   35 -
 .../org/apache/reef/tang/util/walk/Walk.java    |   66 -
 .../walk/graphviz/GraphvizConfigVisitor.java    |  244 ----
 .../graphviz/GraphvizInjectionPlanVisitor.java  |  168 ---
 .../tang/util/walk/graphviz/package-info.java   |   22 -
 .../reef/tang/util/walk/package-info.java       |   22 -
 reef-tang/tang/src/main/proto/.gitignore        |    1 -
 .../tang/src/main/proto/class_hierarchy.proto   |  167 ---
 .../tang/src/main/proto/injection_plan.proto    |   38 -
 .../tang/ClassHierarchyDeserializationTest.java |  112 --
 .../org/apache/reef/tang/TestBindSingleton.java |  420 ------
 .../org/apache/reef/tang/TestClassLoaders.java  |  118 --
 .../apache/reef/tang/TestConfFileParser.java    |  119 --
 .../reef/tang/TestExternalConstructor.java      |   89 --
 .../reef/tang/TestImplicitConversions.java      |  167 ---
 .../apache/reef/tang/TestInjectionFuture.java   |  195 ---
 .../org/apache/reef/tang/TestListInjection.java |  344 -----
 .../reef/tang/TestNamedParameterRoundTrip.java  |  105 --
 .../org/apache/reef/tang/TestSetInjection.java  |  181 ---
 .../java/org/apache/reef/tang/TestTang.java     | 1356 ------------------
 .../org/apache/reef/tang/TestTweetExample.java  |  120 --
 ...onfigurationSerializerAvroRoundtripTest.java |   41 -
 ...urationSerializerByteArrayRoundtripTest.java |   42 -
 ...onfigurationSerializerFileRoundtripTest.java |   50 -
 ...figurationSerializerStringRoundtripTest.java |   40 -
 ...gurationSerializerTextFileRoundtripTest.java |   50 -
 .../tang/formats/ConfigurationFileTest.java     |   54 -
 .../reef/tang/formats/NamedParameters.java      |   38 -
 .../reef/tang/formats/TestCommandLine.java      |   79 -
 .../tang/formats/TestConfigurationModule.java   |  445 ------
 .../tang/implementation/TestClassHierarchy.java |  642 ---------
 .../java/TestConfigurationBuilder.java          |   60 -
 .../java/TestParameterParser.java               |  245 ----
 .../protobuf/TestClassHierarchyRoundTrip.java   |  401 ------
 .../org/apache/reef/tang/test/AnInterface.java  |   29 -
 .../tang/test/AnInterfaceImplementation.java    |   52 -
 .../apache/reef/tang/test/CyclicDependency.java |   56 -
 .../tang/test/CyclicDependencyClassOne.java     |   50 -
 .../tang/test/CyclicDependencyClassTwo.java     |   48 -
 .../java/org/apache/reef/tang/test/Handler.java |   30 -
 .../apache/reef/tang/test/InjectableClass.java  |   47 -
 .../apache/reef/tang/test/ListInterface.java    |   23 -
 .../reef/tang/test/ListInterfaceImplOne.java    |   55 -
 .../reef/tang/test/ListInterfaceImplTwo.java    |   55 -
 .../apache/reef/tang/test/ListOfBaseTypes.java  |   82 --
 .../reef/tang/test/ListOfImplementations.java   |   55 -
 .../apache/reef/tang/test/ObjectTreeTest.java   |   61 -
 .../reef/tang/test/RootImplementation.java      |  166 ---
 .../test/RootImplementationWithoutList.java     |  155 --
 .../apache/reef/tang/test/RootInterface.java    |   31 -
 .../apache/reef/tang/test/RoundTripTest.java    |   56 -
 .../org/apache/reef/tang/test/SetInterface.java |   27 -
 .../reef/tang/test/SetInterfaceImplOne.java     |   56 -
 .../reef/tang/test/SetInterfaceImplTwo.java     |   54 -
 .../apache/reef/tang/test/SetOfBaseTypes.java   |   85 --
 .../reef/tang/test/SetOfImplementations.java    |   55 -
 .../reef/tang/test/TestConfiguration.java       |  110 --
 .../tang/test/TestConfigurationWithoutList.java |   92 --
 .../org/apache/reef/tang/test/UnitClass.java    |  119 --
 .../org/apache/reef/tang/test/package-info.java |   22 -
 reef-tang/tang/src/test/resources/Event.bin     |  Bin 24188 -> 0 bytes
 reef-tang/tang/src/test/resources/Task.bin      |  Bin 128600 -> 0 bytes
 reef-tests/pom.xml                              |  161 ---
 .../assembly/test-jar-with-dependencies.xml     |   38 -
 .../apache/reef/tests/TestDriverLauncher.java   |  132 --
 .../tests/driver/DriverTestStartHandler.java    |   43 -
 .../apache/reef/tests/driver/package-info.java  |   22 -
 .../EvaluatorReuseTestDriver.java               |  118 --
 .../reef/tests/evaluatorreuse/package-info.java |   23 -
 .../tests/fail/driver/DriverFailOnFail.java     |   98 --
 .../reef/tests/fail/driver/FailClient.java      |   65 -
 .../reef/tests/fail/driver/FailDriver.java      |  371 -----
 .../tests/fail/driver/FailDriverDelayedMsg.java |  128 --
 .../apache/reef/tests/fail/driver/NoopTask.java |  117 --
 .../org/apache/reef/tests/fail/task/Client.java |   57 -
 .../org/apache/reef/tests/fail/task/Driver.java |  169 ---
 .../apache/reef/tests/fail/task/FailTask.java   |   49 -
 .../reef/tests/fail/task/FailTaskCall.java      |   46 -
 .../reef/tests/fail/task/FailTaskClose.java     |   65 -
 .../reef/tests/fail/task/FailTaskMsg.java       |   65 -
 .../reef/tests/fail/task/FailTaskStart.java     |   65 -
 .../reef/tests/fail/task/FailTaskStop.java      |   79 -
 .../reef/tests/fail/task/FailTaskSuspend.java   |   69 -
 .../driver/ExpectedTaskFailureHandler.java      |   59 -
 .../driver/OnDriverStartedAllocateOne.java      |   48 -
 .../library/exceptions/ClientSideFailure.java   |   40 -
 .../library/exceptions/DriverSideFailure.java   |   42 -
 .../exceptions/ExpectedTaskException.java       |   43 -
 .../exceptions/SimulatedDriverFailure.java      |   41 -
 .../exceptions/SimulatedTaskFailure.java        |   41 -
 .../library/exceptions/TaskSideFailure.java     |   41 -
 .../exceptions/UnexpectedTaskReturnValue.java   |   40 -
 .../apache/reef/tests/library/package-info.java |   22 -
 .../reef/tests/library/tasks/EchoTask.java      |   38 -
 .../reef/tests/library/tasks/NoopTask.java      |   38 -
 .../tests/messaging/driver/DriverMessaging.java |  173 ---
 .../messaging/driver/DriverMessagingDriver.java |   87 --
 .../messaging/task/TaskMessagingDriver.java     |   98 --
 .../tests/messaging/task/TaskMessagingTask.java |   83 --
 .../apache/reef/tests/statepassing/Counter.java |   38 -
 .../tests/statepassing/StatePassingDriver.java  |  126 --
 .../tests/statepassing/StatePassingTask.java    |   50 -
 .../reef/tests/yarn/failure/FailureDriver.java  |  109 --
 .../reef/tests/yarn/failure/FailureREEF.java    |  120 --
 .../org/apache/reef/tests/AllTestsSuite.java    |   54 -
 .../java/org/apache/reef/tests/FailureTest.java |   54 -
 .../apache/reef/tests/LocalTestEnvironment.java |   68 -
 .../apache/reef/tests/MesosTestEnvironment.java |   68 -
 .../apache/reef/tests/ProbabilisticTests.java   |   33 -
 .../org/apache/reef/tests/TestEnvironment.java  |   58 -
 .../apache/reef/tests/TestEnvironmentBase.java  |   39 -
 .../reef/tests/TestEnvironmentFactory.java      |   54 -
 .../java/org/apache/reef/tests/TestUtils.java   |   63 -
 .../apache/reef/tests/YarnTestEnvironment.java  |   60 -
 .../tests/close_eval/CloseEvaluatorDriver.java  |   65 -
 .../tests/close_eval/CloseEvaluatorTest.java    |   68 -
 .../apache/reef/tests/driver/DriverTest.java    |   68 -
 .../tests/evaluatorexit/EvaluatorExitTest.java  |   66 -
 .../evaluatorexit/EvaluatorExitTestDriver.java  |   79 -
 .../evaluatorexit/EvaluatorExitTestTask.java    |   39 -
 .../reef/tests/evaluatorexit/package-info.java  |   22 -
 .../EvaluatorFailureDuringAlarmDriver.java      |  106 --
 .../evaluatorfailure/EvaluatorFailureTest.java  |   75 -
 .../evaluatorfailure/ExpectedException.java     |   25 -
 .../FailureSchedulingContextStartHandler.java   |   52 -
 .../tests/evaluatorfailure/package-info.java    |   22 -
 .../evaluatorreuse/EvaluatorReuseTest.java      |   72 -
 .../tests/evaluatorsize/EvaluatorSizeTest.java  |   79 -
 .../EvaluatorSizeTestConfiguration.java         |   38 -
 .../evaluatorsize/EvaluatorSizeTestDriver.java  |   97 --
 .../tests/evaluatorsize/MemorySizeTask.java     |   49 -
 .../reef/tests/evaluatorsize/package-info.java  |   22 -
 .../reef/tests/examples/ExamplesTestSuite.java  |   33 -
 .../reef/tests/examples/TestHelloREEF.java      |   61 -
 .../tests/examples/TestRetainedEvaluators.java  |   81 --
 .../reef/tests/examples/package-info.java       |   22 -
 .../reef/tests/fail/DriverFailOnFailTest.java   |   71 -
 .../tests/fail/FailDriverDelayedMsgTest.java    |   73 -
 .../apache/reef/tests/fail/FailDriverTest.java  |  133 --
 .../apache/reef/tests/fail/FailTaskTest.java    |   93 --
 .../apache/reef/tests/fail/FailTestSuite.java   |   32 -
 .../reef/tests/files/FileResourceTest.java      |  144 --
 .../tests/files/FileResourceTestDriver.java     |  127 --
 .../FileResourceTestDriverConfiguration.java    |   40 -
 .../reef/tests/files/FileResourceTestTask.java  |   67 -
 .../FileResourceTestTaskConfiguration.java      |   44 -
 .../apache/reef/tests/files/package-info.java   |   22 -
 .../messaging/driver/DriverMessagingTest.java   |   51 -
 .../tests/messaging/driver/package-info.java    |   22 -
 .../tests/messaging/task/TaskMessagingTest.java |   72 -
 .../reef/tests/messaging/task/package-info.java |   22 -
 .../ActiveContextHandler.java                   |   63 -
 .../AllocatedEvaluatorHandler.java              |   60 -
 .../multipleEventHandlerInstances/Client.java   |   76 -
 .../ClosedContextHandler.java                   |   51 -
 .../CompletedEvaluatorHandler.java              |   52 -
 .../CompletedTaskHandler.java                   |   51 -
 .../EmptyTask.java                              |   39 -
 .../RunningTaskHandler.java                     |   51 -
 .../StartHandler.java                           |   62 -
 .../tests/roguethread/RogueThreadDriver.java    |   50 -
 .../reef/tests/roguethread/RogueThreadTask.java |   44 -
 .../reef/tests/roguethread/RogueThreadTest.java |   70 -
 .../reef/tests/roguethread/package-info.java    |   22 -
 .../tests/statepassing/StatePassingTest.java    |   71 -
 .../reef/tests/statepassing/package-info.java   |   22 -
 .../tests/subcontexts/ContextStartHandler1.java |   39 -
 .../tests/subcontexts/ContextStartHandler2.java |   38 -
 .../tests/subcontexts/ContextStopHandler1.java  |   38 -
 .../tests/subcontexts/ContextStopHandler2.java  |   38 -
 .../tests/subcontexts/SubContextDriver.java     |  143 --
 .../reef/tests/subcontexts/SubContextTest.java  |   93 --
 .../reef/tests/subcontexts/package-info.java    |   22 -
 .../tests/taskcounting/TaskCountingDriver.java  |  109 --
 .../tests/taskcounting/TaskCountingTest.java    |   70 -
 .../reef/tests/taskcounting/package-info.java   |   22 -
 .../tests/taskresubmit/TaskResubmitDriver.java  |   85 --
 .../tests/taskresubmit/TaskResubmitTest.java    |   72 -
 .../reef/tests/taskresubmit/package-info.java   |   22 -
 reef-utils-hadoop/pom.xml                       |   45 -
 .../org/apache/reef/util/HadoopEnvironment.java |   37 -
 .../apache/reef/util/logging/DFSHandler.java    |  146 --
 reef-utils/pom.xml                              |   45 -
 .../java/org/apache/reef/util/Optional.java     |  128 --
 .../java/org/apache/reef/util/package-info.java |   22 -
 .../java/org/apache/reef/util/OptionalTest.java |   99 --
 reef-wake/.gitattributes                        |    3 -
 reef-wake/.gitignore                            |   16 -
 reef-wake/README.md                             |   94 --
 reef-wake/pom.xml                               |   38 -
 reef-wake/wake/pom.xml                          |  123 --
 .../org/apache/reef/wake/AbstractEStage.java    |   91 --
 .../apache/reef/wake/ComparableIdentifier.java  |   27 -
 .../main/java/org/apache/reef/wake/EStage.java  |   27 -
 .../java/org/apache/reef/wake/EventHandler.java |   34 -
 .../java/org/apache/reef/wake/Identifiable.java |   30 -
 .../java/org/apache/reef/wake/Identifier.java   |   54 -
 .../org/apache/reef/wake/IdentifierFactory.java |   31 -
 .../org/apache/reef/wake/IdentifierParser.java  |   55 -
 .../main/java/org/apache/reef/wake/Stage.java   |   25 -
 .../apache/reef/wake/StageConfiguration.java    |   68 -
 .../org/apache/reef/wake/WakeConfiguration.java |   62 -
 .../org/apache/reef/wake/WakeParameters.java    |   46 -
 .../wake/examples/accumulate/CombinerStage.java |  161 ---
 .../reef/wake/examples/join/BlockingJoin.java   |   95 --
 .../reef/wake/examples/join/EventPrinter.java   |   39 -
 .../wake/examples/join/NonBlockingJoin.java     |  121 --
 .../reef/wake/examples/join/TupleEvent.java     |   45 -
 .../reef/wake/examples/join/TupleSource.java    |   58 -
 .../reef/wake/examples/join/package-info.java   |   22 -
 .../reef/wake/examples/p2p/EventSource.java     |   33 -
 .../reef/wake/examples/p2p/Pull2Push.java       |   94 --
 .../reef/wake/examples/p2p/package-info.java    |   22 -
 .../apache/reef/wake/examples/package-info.java |   22 -
 .../wake/exception/WakeRuntimeException.java    |   56 -
 .../reef/wake/exception/package-info.java       |   22 -
 .../reef/wake/impl/BlockingEventHandler.java    |   79 -
 .../wake/impl/BlockingSignalEventHandler.java   |   56 -
 .../wake/impl/DefaultIdentifierFactory.java     |   90 --
 .../reef/wake/impl/DefaultThreadFactory.java    |   85 --
 .../apache/reef/wake/impl/ForkPoolStage.java    |  103 --
 .../IndependentIterationsThreadPoolStage.java   |   80 --
 .../reef/wake/impl/LoggingEventHandler.java     |   49 -
 .../org/apache/reef/wake/impl/LoggingUtils.java |   52 -
 .../reef/wake/impl/LoggingVoidEventHandler.java |   47 -
 .../reef/wake/impl/MergingEventHandler.java     |  152 --
 .../wake/impl/MissingStartHandlerHandler.java   |   43 -
 .../reef/wake/impl/MultiEventHandler.java       |   60 -
 .../reef/wake/impl/OpaqueLocalIdentifier.java   |   28 -
 .../apache/reef/wake/impl/PeriodicEvent.java    |   25 -
 .../reef/wake/impl/PubSubEventHandler.java      |  105 --
 .../reef/wake/impl/SingleThreadStage.java       |  144 --
 .../org/apache/reef/wake/impl/StageManager.java |   78 -
 .../org/apache/reef/wake/impl/SyncStage.java    |  113 --
 .../apache/reef/wake/impl/ThreadPoolStage.java  |  223 ---
 .../org/apache/reef/wake/impl/TimerStage.java   |  135 --
 .../apache/reef/wake/impl/WakeSharedPool.java   |  108 --
 .../wake/impl/WakeUncaughtExceptionHandler.java |   46 -
 .../org/apache/reef/wake/impl/package-info.java |   22 -
 .../java/org/apache/reef/wake/metrics/EWMA.java |   79 -
 .../reef/wake/metrics/EWMAParameters.java       |   35 -
 .../org/apache/reef/wake/metrics/Histogram.java |   55 -
 .../org/apache/reef/wake/metrics/Meter.java     |  147 --
 .../reef/wake/metrics/UniformHistogram.java     |   90 --
 .../apache/reef/wake/metrics/package-info.java  |   22 -
 .../java/org/apache/reef/wake/package-info.java |   22 -
 .../org/apache/reef/wake/profiler/Vertex.java   |  100 --
 .../apache/reef/wake/profiler/WakeProfiler.java |  321 -----
 .../java/org/apache/reef/wake/remote/Codec.java |   28 -
 .../org/apache/reef/wake/remote/Decoder.java    |   36 -
 .../reef/wake/remote/DefaultErrorHandler.java   |   38 -
 .../org/apache/reef/wake/remote/Encoder.java    |   36 -
 .../org/apache/reef/wake/remote/NetUtils.java   |  106 --
 .../reef/wake/remote/RemoteConfiguration.java   |   71 -
 .../reef/wake/remote/RemoteIdentifier.java      |   27 -
 .../wake/remote/RemoteIdentifierFactory.java    |   41 -
 .../apache/reef/wake/remote/RemoteManager.java  |   91 --
 .../apache/reef/wake/remote/RemoteMessage.java  |   42 -
 .../exception/RemoteRuntimeException.java       |   54 -
 .../wake/remote/exception/package-info.java     |   22 -
 .../apache/reef/wake/remote/impl/ByteCodec.java |   50 -
 .../wake/remote/impl/ConnectFutureTask.java     |   40 -
 ...ltRemoteIdentifierFactoryImplementation.java |   47 -
 .../DefaultRemoteManagerImplementation.java     |  229 ---
 .../wake/remote/impl/DefaultRemoteMessage.java  |   65 -
 .../reef/wake/remote/impl/HandlerContainer.java |  154 --
 .../reef/wake/remote/impl/MultiCodec.java       |   75 -
 .../reef/wake/remote/impl/MultiDecoder.java     |   72 -
 .../reef/wake/remote/impl/MultiEncoder.java     |   64 -
 .../remote/impl/ObjectSerializableCodec.java    |   72 -
 .../remote/impl/OrderedRemoteReceiverStage.java |  201 ---
 .../wake/remote/impl/ProxyEventHandler.java     |   89 --
 .../reef/wake/remote/impl/RemoteEvent.java      |  170 ---
 .../reef/wake/remote/impl/RemoteEventCodec.java |   65 -
 .../wake/remote/impl/RemoteEventComparator.java |   37 -
 .../wake/remote/impl/RemoteEventDecoder.java    |   62 -
 .../wake/remote/impl/RemoteEventEncoder.java    |   68 -
 .../remote/impl/RemoteReceiverEventHandler.java |   61 -
 .../wake/remote/impl/RemoteReceiverStage.java   |   99 --
 .../remote/impl/RemoteSenderEventHandler.java   |  165 ---
 .../wake/remote/impl/RemoteSenderStage.java     |   91 --
 .../wake/remote/impl/RemoteSeqNumGenerator.java |   49 -
 .../remote/impl/SocketRemoteIdentifier.java     |  111 --
 .../reef/wake/remote/impl/StringCodec.java      |   50 -
 .../reef/wake/remote/impl/Subscription.java     |   61 -
 .../reef/wake/remote/impl/TransportEvent.java   |  106 --
 .../apache/reef/wake/remote/impl/Tuple2.java    |   59 -
 .../reef/wake/remote/impl/package-info.java     |   22 -
 .../apache/reef/wake/remote/package-info.java   |   22 -
 .../apache/reef/wake/remote/transport/Link.java |   52 -
 .../wake/remote/transport/LinkListener.java     |   34 -
 .../reef/wake/remote/transport/Transport.java   |   77 -
 .../exception/TransportRuntimeException.java    |   54 -
 .../transport/exception/package-info.java       |   22 -
 .../netty/AbstractNettyEventListener.java       |   99 --
 .../remote/transport/netty/ByteEncoder.java     |   36 -
 .../netty/ChunkedReadWriteHandler.java          |  191 ---
 .../remote/transport/netty/LinkReference.java   |   48 -
 .../transport/netty/LoggingLinkListener.java    |   46 -
 .../transport/netty/NettyChannelHandler.java    |  114 --
 .../netty/NettyChannelHandlerFactory.java       |   35 -
 .../netty/NettyChannelInitializer.java          |   52 -
 .../netty/NettyClientEventListener.java         |   56 -
 .../NettyDefaultChannelHandlerFactory.java      |   49 -
 .../transport/netty/NettyEventListener.java     |   57 -
 .../wake/remote/transport/netty/NettyLink.java  |  117 --
 .../netty/NettyMessagingTransport.java          |  329 -----
 .../netty/NettyServerEventListener.java         |   65 -
 .../remote/transport/netty/package-info.java    |   22 -
 .../wake/remote/transport/package-info.java     |   22 -
 .../apache/reef/wake/rx/AbstractObserver.java   |   43 -
 .../apache/reef/wake/rx/AbstractRxStage.java    |   86 --
 .../apache/reef/wake/rx/DynamicObservable.java  |   36 -
 .../org/apache/reef/wake/rx/Observable.java     |   25 -
 .../java/org/apache/reef/wake/rx/Observer.java  |   50 -
 .../java/org/apache/reef/wake/rx/RxStage.java   |   29 -
 .../apache/reef/wake/rx/StaticObservable.java   |   26 -
 .../java/org/apache/reef/wake/rx/Subject.java   |   29 -
 .../exception/ObserverCompletedException.java   |   38 -
 .../reef/wake/rx/exception/package-info.java    |   22 -
 .../apache/reef/wake/rx/impl/RxSyncStage.java   |  104 --
 .../reef/wake/rx/impl/RxThreadPoolStage.java    |  198 ---
 .../apache/reef/wake/rx/impl/SimpleSubject.java |   73 -
 .../reef/wake/rx/impl/TimeoutSubject.java       |   84 --
 .../apache/reef/wake/rx/impl/package-info.java  |   22 -
 .../org/apache/reef/wake/rx/package-info.java   |   22 -
 .../reef/wake/storage/FileHandlePool.java       |   31 -
 .../reef/wake/storage/FileIdentifier.java       |   49 -
 .../apache/reef/wake/storage/ReadRequest.java   |   41 -
 .../apache/reef/wake/storage/ReadResponse.java  |   33 -
 .../reef/wake/storage/SequentialFileReader.java |   61 -
 .../reef/wake/storage/StorageIdentifier.java    |   25 -
 .../java/org/apache/reef/wake/time/Clock.java   |  107 --
 .../java/org/apache/reef/wake/time/Time.java    |   62 -
 .../org/apache/reef/wake/time/event/Alarm.java  |   40 -
 .../apache/reef/wake/time/event/StartTime.java  |   32 -
 .../apache/reef/wake/time/event/StopTime.java   |   32 -
 .../reef/wake/time/event/package-info.java      |   22 -
 .../org/apache/reef/wake/time/package-info.java |   22 -
 .../reef/wake/time/runtime/LogicalTimer.java    |   48 -
 .../reef/wake/time/runtime/RealTimer.java       |   43 -
 .../reef/wake/time/runtime/RuntimeClock.java    |  244 ----
 .../apache/reef/wake/time/runtime/Timer.java    |   30 -
 .../wake/time/runtime/event/ClientAlarm.java    |   29 -
 .../reef/wake/time/runtime/event/IdleClock.java |   28 -
 .../wake/time/runtime/event/RuntimeAlarm.java   |   30 -
 .../wake/time/runtime/event/RuntimeStart.java   |   29 -
 .../wake/time/runtime/event/RuntimeStop.java    |   40 -
 .../wake/time/runtime/event/package-info.java   |   22 -
 .../reef/wake/time/runtime/package-info.java    |   22 -
 .../wake/src/main/proto/RemoteProtocol.proto    |   35 -
 .../com/microsoft/wake/logging.properties       |   81 --
 .../wake/test/BlockingEventHandlerTest.java     |  196 ---
 .../test/BlockingSignalEventHandlerTest.java    |  166 ---
 .../reef/wake/test/ForkPoolStageTest.java       |  226 ---
 ...ndependentIterationsThreadPoolStageTest.java |   84 --
 .../reef/wake/test/MergingEventHandlerTest.java |  237 ---
 .../org/apache/reef/wake/test/MetricsTest.java  |   52 -
 .../wake/test/PubSubThreadPoolStageTest.java    |  115 --
 .../apache/reef/wake/test/StageManagerTest.java |   48 -
 .../apache/reef/wake/test/SyncStageTest.java    |  130 --
 .../reef/wake/test/ThreadPoolStageTest.java     |  221 ---
 .../apache/reef/wake/test/TimerStageTest.java   |   82 --
 .../reef/wake/test/examples/SkipListTest.java   |  378 -----
 .../wake/test/examples/TestBlockingJoin.java    |   39 -
 .../reef/wake/test/examples/TestCombiner.java   |  129 --
 .../reef/wake/test/examples/TestJoin.java       |   38 -
 .../wake/test/examples/TestTupleSource.java     |   34 -
 .../org/apache/reef/wake/test/package-info.java |   22 -
 .../reef/wake/test/remote/LargeMsgTest.java     |  141 --
 .../remote/RemoteIdentifierFactoryTest.java     |   86 --
 .../wake/test/remote/RemoteManagerTest.java     |  462 ------
 .../reef/wake/test/remote/RemoteTest.java       |  211 ---
 .../wake/test/remote/SmallMessagesTest.java     |  161 ---
 .../reef/wake/test/remote/StartEvent.java       |   25 -
 .../apache/reef/wake/test/remote/TestEvent.java |   47 -
 .../reef/wake/test/remote/TestEvent1.java       |   29 -
 .../reef/wake/test/remote/TestEvent2.java       |   30 -
 .../reef/wake/test/remote/TestEventCodec.java   |   52 -
 .../reef/wake/test/remote/TestRemote.java       |   68 -
 .../wake/test/remote/TestRemoteIdentifier.java  |   48 -
 .../wake/test/remote/TransportRaceTest.java     |  104 --
 .../reef/wake/test/remote/TransportTest.java    |  144 --
 .../reef/wake/test/remote/package-info.java     |   22 -
 .../org/apache/reef/wake/test/rx/RxTest.java    |   90 --
 .../wake/test/rx/RxThreadPoolStageTest.java     |  194 ---
 .../reef/wake/test/rx/TimeoutSubjectTest.java   |  143 --
 .../apache/reef/wake/test/rx/package-info.java  |   22 -
 .../apache/reef/wake/test/time/ClockTest.java   |  205 ---
 .../reef/wake/test/time/package-info.java       |   22 -
 .../org/apache/reef/wake/test/util/Monitor.java |   41 -
 .../reef/wake/test/util/PassThroughEncoder.java |   36 -
 .../reef/wake/test/util/TimeoutHandler.java     |   36 -
 .../reef/wake/test/util/package-info.java       |   22 -
 reef-wake/wake/src/test/proto/TestEvent1.proto  |   28 -
 .../wake/src/test/proto/TestProtocol.proto      |   28 -
 reef-webserver/pom.xml                          |  107 --
 reef-webserver/src/main/avro/DriverInfo.avsc    |   43 -
 reef-webserver/src/main/avro/EvaluatorInfo.avsc |   45 -
 reef-webserver/src/main/avro/EvaluatorList.avsc |   43 -
 reef-webserver/src/main/avro/webRequest.avsc    |   29 -
 .../webserver/AvroDriverInfoSerializer.java     |   68 -
 .../webserver/AvroEvaluatorInfoSerializer.java  |  101 --
 .../webserver/AvroEvaluatorListSerializer.java  |   85 --
 .../reef/webserver/AvroHttpSerializer.java      |  108 --
 .../reef/webserver/DriverInfoSerializer.java    |   46 -
 .../reef/webserver/EvaluatorInfoSerializer.java |   40 -
 .../reef/webserver/EvaluatorListSerializer.java |   48 -
 .../reef/webserver/HttpEventHandlers.java       |   31 -
 .../org/apache/reef/webserver/HttpHandler.java  |   50 -
 .../webserver/HttpHandlerConfiguration.java     |   43 -
 .../webserver/HttpRuntimeConfiguration.java     |   37 -
 .../reef/webserver/HttpRuntimeStartHandler.java |   68 -
 .../reef/webserver/HttpRuntimeStopHandler.java  |   67 -
 .../org/apache/reef/webserver/HttpServer.java   |   55 -
 .../apache/reef/webserver/HttpServerImpl.java   |  149 --
 .../webserver/HttpServerReefEventHandler.java   |  388 -----
 .../reef/webserver/HttpTrackingURLProvider.java |   67 -
 .../org/apache/reef/webserver/JettyHandler.java |  159 --
 .../apache/reef/webserver/MaxPortNumber.java    |   29 -
 .../apache/reef/webserver/MaxRetryAttempts.java |   29 -
 .../apache/reef/webserver/MinPortNumber.java    |   29 -
 .../reef/webserver/ParsedHttpRequest.java       |  194 ---
 .../org/apache/reef/webserver/PortNumber.java   |   31 -
 .../reef/webserver/ReefEventStateManager.java   |  308 ----
 .../reef/webserver/TestAvroHttpSerializer.java  |  153 --
 .../webserver/TestAvroSerializerForHttp.java    |  179 ---
 .../reef/webserver/TestHttpConfiguration.java   |  204 ---
 .../apache/reef/webserver/TestHttpServer.java   |  169 ---
 .../apache/reef/webserver/TestJettyHandler.java |  166 ---
 .../reef/webserver/TestParsedHttpRequest.java   |  101 --
 .../reef/webserver/TestReefEventHandler.java    |   84 --
 .../webserver/TestReefEventStateManager.java    |  146 --
 .../reef/webserver/TestRuntimeStartHandler.java |  104 --
 .../apache/reef/webserver/TestTrackingUri.java  |  113 --
 2682 files changed, 110107 insertions(+), 110107 deletions(-)
----------------------------------------------------------------------



[32/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/resources/org/apache/reef/logging.properties
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/resources/org/apache/reef/logging.properties b/lang/java/reef-common/src/main/resources/org/apache/reef/logging.properties
new file mode 100644
index 0000000..a5ab8dc
--- /dev/null
+++ b/lang/java/reef-common/src/main/resources/org/apache/reef/logging.properties
@@ -0,0 +1,85 @@
+#
+# 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.
+#
+
+# Properties file which configures the operation of the JDK
+# logging facility.
+
+# The system will look for this config file, first using
+# a System property specified at startup:
+#
+# >java -Djava.utils.logging.config.file=myLoggingConfigFilePath
+#
+# If this property is not specified, then the config file is
+# retrieved from its default location at:
+#
+# JDK_HOME/jre/lib/logging.properties
+
+# Global logging properties.
+# ------------------------------------------
+# The set of handlers to be loaded upon startup.
+# Comma-separated list of class names.
+# (? LogManager docs say no comma here, but JDK example has comma.)
+# handlers=java.utils.logging.FileHandler, java.utils.logging.ConsoleHandler
+handlers=java.util.logging.ConsoleHandler
+
+# java.util.logging.SimpleFormatter.format=%1$tF %1$tT,%1$tL %4$s %2$s - %5$s%6$s%n
+
+org.apache.reef.util.logging.ThreadLogFormatter.format=%1$tF %1$tT,%1$tL %4$s %2$s %7$s | %5$s%6$s%n
+org.apache.reef.util.logging.ThreadLogFormatter.dropPrefix=com.microsoft.,org.apache.
+
+# Default global logging level.
+# Loggers and Handlers may override this level
+.level=ALL
+
+# Loggers
+# ------------------------------------------
+# Loggers are usually attached to packages.
+# Here, the level for each package is specified.
+# The global level is used by default, so levels
+# specified here simply act as an override.
+
+# org.apache.reef.examples.level=FINEST
+# org.apache.reef.tang.level=INFO
+
+# Handlers
+# -----------------------------------------
+
+# --- ConsoleHandler ---
+# Override of global logging level
+java.util.logging.ConsoleHandler.level=FINEST
+java.util.logging.ConsoleHandler.formatter=org.apache.reef.util.logging.ThreadLogFormatter
+
+# --- FileHandler ---
+# Override of global logging level
+java.util.logging.FileHandler.level=FINEST
+
+# Naming style for the output file:
+# (The output file is placed in the directory
+# defined by the "user.home" System property.)
+java.util.logging.FileHandler.pattern=%h/reef.%u.log
+
+# Limiting size of output file in bytes:
+java.util.logging.FileHandler.limit=512000
+
+# Number of output files to cycle through, by appending an
+# integer to the base file name:
+java.util.logging.FileHandler.count=100
+
+# Style of output (Simple or XML):
+java.util.logging.FileHandler.formatter=org.apache.reef.util.logging.ThreadLogFormatter

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/resources/version.properties
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/resources/version.properties b/lang/java/reef-common/src/main/resources/version.properties
new file mode 100644
index 0000000..846f2a0
--- /dev/null
+++ b/lang/java/reef-common/src/main/resources/version.properties
@@ -0,0 +1,18 @@
+ # 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.
+
+version=${pom.version}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/test/java/org/apache/reef/runtime/common/driver/EvaluatorRequestorImplTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/test/java/org/apache/reef/runtime/common/driver/EvaluatorRequestorImplTest.java b/lang/java/reef-common/src/test/java/org/apache/reef/runtime/common/driver/EvaluatorRequestorImplTest.java
new file mode 100644
index 0000000..ddbd83b
--- /dev/null
+++ b/lang/java/reef-common/src/test/java/org/apache/reef/runtime/common/driver/EvaluatorRequestorImplTest.java
@@ -0,0 +1,110 @@
+/**
+ * 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.reef.runtime.common.driver;
+
+import org.apache.reef.driver.catalog.ResourceCatalog;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.api.ResourceRequestHandler;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.util.logging.LoggingScopeFactory;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+
+/**
+ * Tests for EvaluatorRequestorImpl.
+ */
+public class EvaluatorRequestorImplTest {
+  private final ResourceCatalog resourceCatalog = mock(ResourceCatalog.class);
+  private LoggingScopeFactory loggingScopeFactory;
+
+  @Before
+  public void setUp() throws InjectionException {
+    loggingScopeFactory = Tang.Factory.getTang().newInjector().getInstance(LoggingScopeFactory.class);
+  }
+
+  /**
+   * If only memory, no count is given, 1 evaluator should be requested.
+   */
+  @Test
+  public void testMemoryOnly() {
+    final int memory = 777;
+    final DummyRequestHandler requestHandler = new DummyRequestHandler();
+    final EvaluatorRequestor evaluatorRequestor = new EvaluatorRequestorImpl(resourceCatalog, requestHandler, loggingScopeFactory);
+    evaluatorRequestor.submit(EvaluatorRequest.newBuilder().setMemory(memory).build());
+    Assert.assertEquals("Memory request did not make it", requestHandler.get().getMemorySize(), memory);
+    Assert.assertEquals("Number of requests did not make it", requestHandler.get().getResourceCount(), 1);
+  }
+
+  /**
+   * Checks whether memory and count make it correctly.
+   */
+  @Test
+  public void testMemoryAndCount() {
+    final int memory = 777;
+    final int count = 9;
+    final DummyRequestHandler requestHandler = new DummyRequestHandler();
+    final EvaluatorRequestor evaluatorRequestor = new EvaluatorRequestorImpl(resourceCatalog, requestHandler, loggingScopeFactory);
+    evaluatorRequestor.submit(EvaluatorRequest.newBuilder().setMemory(memory).setNumber(count).build());
+    Assert.assertEquals("Memory request did not make it", requestHandler.get().getMemorySize(), memory);
+    Assert.assertEquals("Number of requests did not make it", requestHandler.get().getResourceCount(), count);
+  }
+
+  /**
+   * Expect an IllegalArgumentException when a non-positive memory amount is passed.
+   */
+  @Test(expected = IllegalArgumentException.class)
+  public void testIllegalMemory() {
+    final int memory = 0;
+    final int count = 1;
+    final DummyRequestHandler requestHandler = new DummyRequestHandler();
+    final EvaluatorRequestor evaluatorRequestor = new EvaluatorRequestorImpl(resourceCatalog, requestHandler, loggingScopeFactory);
+    evaluatorRequestor.submit(EvaluatorRequest.newBuilder().setMemory(memory).setNumberOfCores(1).setNumber(count).build());
+  }
+
+  /**
+   * Expect an IllegalArgumentException when a non-positive evaluator count is passed.
+   */
+  @Test(expected = IllegalArgumentException.class)
+  public void testIllegalCount() {
+    final int memory = 128;
+    final int count = 0;
+    final DummyRequestHandler requestHandler = new DummyRequestHandler();
+    final EvaluatorRequestor evaluatorRequestor = new EvaluatorRequestorImpl(resourceCatalog, requestHandler, loggingScopeFactory);
+    evaluatorRequestor.submit(EvaluatorRequest.newBuilder().setMemory(memory).setNumberOfCores(1).setNumber(count).build());
+  }
+
+  private class DummyRequestHandler implements ResourceRequestHandler {
+    private DriverRuntimeProtocol.ResourceRequestProto request;
+
+    @Override
+    public void onNext(DriverRuntimeProtocol.ResourceRequestProto resourceRequestProto) {
+      this.request = resourceRequestProto;
+    }
+
+    public DriverRuntimeProtocol.ResourceRequestProto get() {
+      return this.request;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/test/java/org/apache/reef/runtime/common/driver/catalog/CatalogTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/test/java/org/apache/reef/runtime/common/driver/catalog/CatalogTest.java b/lang/java/reef-common/src/test/java/org/apache/reef/runtime/common/driver/catalog/CatalogTest.java
new file mode 100644
index 0000000..66203b2
--- /dev/null
+++ b/lang/java/reef-common/src/test/java/org/apache/reef/runtime/common/driver/catalog/CatalogTest.java
@@ -0,0 +1,54 @@
+/**
+ * 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.reef.runtime.common.driver.catalog;
+
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.junit.Assert;
+import org.junit.Test;
+
+public final class CatalogTest {
+
+
+  /**
+   * Basic catalog test that addes some nodes and checks
+   * that they exist.
+   */
+  @Test
+  public final void TestResourceCatalog() {
+    final int nodes = 10;
+    final ResourceCatalogImpl catalog = new ResourceCatalogImpl();
+
+    for (int i = 0; i < nodes; i++) {
+      catalog.handle(DriverRuntimeProtocol.NodeDescriptorProto.newBuilder()
+          .setRackName("test-rack")
+          .setHostName("test-" + i)
+          .setPort(0)
+          .setIdentifier("test-" + i)
+          .setMemorySize(512)
+          .build());
+    }
+
+    for (int i = 0; i < nodes; i++) {
+      Assert.assertNotNull(catalog.getNode("test-" + i));
+    }
+
+    Assert.assertTrue(catalog.getRacks().size() == 1);
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/test/java/org/apache/reef/util/LoggingScopeTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/test/java/org/apache/reef/util/LoggingScopeTest.java b/lang/java/reef-common/src/test/java/org/apache/reef/util/LoggingScopeTest.java
new file mode 100644
index 0000000..fdb2aa1
--- /dev/null
+++ b/lang/java/reef-common/src/test/java/org/apache/reef/util/LoggingScopeTest.java
@@ -0,0 +1,100 @@
+/**
+ * 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.reef.util;
+
+import org.apache.reef.tang.ConfigurationBuilder;
+import org.apache.reef.tang.ExternalConstructor;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.util.logging.*;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Test LoggingScope
+ */
+public class LoggingScopeTest {
+
+  private LoggingScopeFactory logFactory;
+
+  @Before
+  public void setUp() throws InjectionException {
+    final ConfigurationBuilder b = Tang.Factory.getTang().newConfigurationBuilder()
+        .bindNamedParameter(LogLevelName.class, "INFO");
+
+    final Injector i = Tang.Factory.getTang().newInjector(b.build());
+    logFactory = i.getInstance(LoggingScopeFactory.class);
+  }
+
+  /**
+   * Test getNewLoggingScope() in LoggingScopeFactory that injects LoggingScope object
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testGetNewLoggingScope() throws InjectionException {
+    try (final LoggingScope ls = logFactory.getNewLoggingScope("test")) {
+       Assert.assertTrue(true);
+    }
+  }
+
+  /**
+   * Test getNewLoggingScope() in LoggingScopeFactory that injects LoggingScope object with param as a parameter
+   * @throws InjectionException
+   */
+  @Test
+  public void testGetNewLoggingScopeWithParam() throws InjectionException {
+    try (final LoggingScope ls = logFactory.getNewLoggingScope("test first string = {0}, second = {1}", new Object[] { "first", "second" })) {
+      Assert.assertTrue(true);
+    }
+  }
+
+  /**
+   * Test calling predefined method in LoggingScopeFactory
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testLoggingScopeFactory() {
+    try (final LoggingScope ls = logFactory.activeContextReceived("test")) {
+      Assert.assertTrue(true);
+    }
+  }
+
+  /**
+   * Use default log level in injecting LoggingScopeFactory constructor
+   * @throws InjectionException
+   */
+  @Test
+  public void testLoggingScopeFactoryWithDefaultLogLevel() throws InjectionException {
+    final Injector i = Tang.Factory.getTang().newInjector(Tang.Factory.getTang().newConfigurationBuilder().build());
+    final LoggingScopeFactory logFactory = i.getInstance(LoggingScopeFactory.class);
+
+    try (final LoggingScope ls = logFactory.activeContextReceived("test")) {
+      Assert.assertTrue(true);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/test/java/org/apache/reef/util/SingletonAsserterTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/test/java/org/apache/reef/util/SingletonAsserterTest.java b/lang/java/reef-common/src/test/java/org/apache/reef/util/SingletonAsserterTest.java
new file mode 100644
index 0000000..5cecec6
--- /dev/null
+++ b/lang/java/reef-common/src/test/java/org/apache/reef/util/SingletonAsserterTest.java
@@ -0,0 +1,34 @@
+/**
+ * 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.reef.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.List;
+
+public final class SingletonAsserterTest {
+
+  @Test
+  public void testSingletonAsserter() {
+    Assert.assertTrue(SingletonAsserter.assertSingleton(SingletonAsserterTest.class));
+    Assert.assertTrue(SingletonAsserter.assertSingleton(List.class));
+    Assert.assertFalse(SingletonAsserter.assertSingleton(List.class));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-clr/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-clr/pom.xml b/lang/java/reef-examples-clr/pom.xml
new file mode 100644
index 0000000..94bda88
--- /dev/null
+++ b/lang/java/reef-examples-clr/pom.xml
@@ -0,0 +1,182 @@
+<?xml version="1.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.
+-->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+         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>
+    <artifactId>reef-examples-clr</artifactId>
+    <name>REEF Examples CLR</name>
+    <description>Examples that use the JVM/CLR interop of REEF.</description>
+
+    <parent>
+        <groupId>org.apache.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <dependencies>
+        <!-- REEF -->
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-local</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-yarn</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-io</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-checkpoint</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-webserver</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-examples</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <!-- End of REEF -->
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-jdk14</artifactId>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-shade-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>shade</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <outputFile>
+                        ${project.build.directory}/${project.artifactId}-${project.version}-shaded.jar
+                    </outputFile>
+                    <filters>
+                        <filter>
+                            <artifact>*:*</artifact>
+                            <excludes>
+                                <exclude>yarn-default.xml</exclude>
+                                <exclude>yarn-version-info.properties</exclude>
+                                <exclude>core-default.xml</exclude>
+                                <exclude>LICENSE</exclude>
+                                <exclude>META-INF/*</exclude>
+                            </excludes>
+                        </filter>
+                    </filters>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+
+    <profiles>
+
+
+        <profile>
+            <id>RetainedEvalCLR</id>
+            <build>
+                <defaultGoal>exec:exec</defaultGoal>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <configuration>
+                            <executable>java</executable>
+                            <arguments>
+                                <argument>-classpath</argument>
+                                <classpath/>
+                                <argument>-Djava.util.logging.config.class=org.apache.reef.util.logging.Config
+                                </argument>
+                                <argument>-Dcom.microsoft.reef.runtime.local.folder=${project.build.directory}
+                                </argument>
+                                <argument>org.apache.reef.examples.retained_evalCLR.Launch</argument>
+                                <argument>dotnetDistributedShell</argument>
+                                <!-- <argument>-cmd</argument>
+                                <argument>date</argument>
+                                <argument>-num_runs</argument>
+                                <argument>20</argument>
+                                <argument>-local</argument>
+                                <argument>true</argument> -->
+                            </arguments>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+
+        <profile>
+            <id>HelloCLR</id>
+            <build>
+                <defaultGoal>exec:exec</defaultGoal>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <configuration>
+                            <executable>java</executable>
+                            <arguments>
+                                <argument>-classpath</argument>
+                                <classpath/>
+                                <argument>-Djava.util.logging.config.class=org.apache.reef.util.logging.Config
+                                </argument>
+                                <!-- <argument>-Dlog4j.debug=true</argument> -->
+                                <argument>-Dcom.microsoft.reef.runtime.local.folder=${project.build.directory}
+                                </argument>
+                                <argument>org.apache.reef.examples.helloCLR.HelloCLR</argument>
+                                <argument>dotnetHello</argument>
+                            </arguments>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/HelloCLR.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/HelloCLR.java b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/HelloCLR.java
new file mode 100644
index 0000000..f8ff247
--- /dev/null
+++ b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/HelloCLR.java
@@ -0,0 +1,93 @@
+/**
+ * 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.reef.examples.helloCLR;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.OptionalParameter;
+import org.apache.reef.util.EnvironmentUtils;
+
+import java.io.File;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The Client for Hello REEF example.
+ */
+public final class HelloCLR {
+
+  /**
+   * The name of the class hierarchy file.
+   */
+  // TODO: Make this a config option
+  public static final String CLASS_HIERARCHY_FILENAME = "HelloTask.bin";
+
+  private static final Logger LOG = Logger.getLogger(HelloCLR.class.getName());
+
+  /**
+   * Number of milliseconds to wait for the job to complete.
+   */
+  private static final int JOB_TIMEOUT = 1000000; // 1000 sec.
+
+  private static ConfigurationModule addAll(final ConfigurationModule conf, final OptionalParameter<String> param, final File folder) {
+    ConfigurationModule result = conf;
+    for (final File f : folder.listFiles()) {
+      if (f.canRead() && f.exists() && f.isFile()) {
+        result = result.set(param, f.getAbsolutePath());
+      }
+    }
+    return result;
+  }
+
+  public static LauncherStatus runHelloCLR(final Configuration runtimeConf, final int timeOut, final File clrFolder)
+      throws BindException, InjectionException {
+
+    ConfigurationModule driverConf =
+        addAll(DriverConfiguration.CONF, DriverConfiguration.GLOBAL_FILES, clrFolder)
+            .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(HelloDriver.class))
+            .set(DriverConfiguration.DRIVER_IDENTIFIER, "HelloCLR")
+            .set(DriverConfiguration.ON_DRIVER_STARTED, HelloDriver.StartHandler.class)
+            .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HelloDriver.EvaluatorAllocatedHandler.class);
+
+    return DriverLauncher.getLauncher(runtimeConf).run(driverConf.build(), timeOut);
+  }
+
+  /**
+   * Start Hello REEF job. Runs method runHelloReef().
+   *
+   * @param args command line parameters.
+   * @throws org.apache.reef.tang.exceptions.BindException      configuration error.
+   * @throws org.apache.reef.tang.exceptions.InjectionException configuration error.
+   */
+  public static void main(final String[] args) throws BindException, InjectionException {
+    final Configuration runtimeConfiguration = LocalRuntimeConfiguration.CONF
+        .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, 2)
+        .build();
+
+    final File dotNetFolder = new File(args[0]).getAbsoluteFile();
+    final LauncherStatus status = runHelloCLR(runtimeConfiguration, JOB_TIMEOUT, dotNetFolder);
+    LOG.log(Level.INFO, "REEF job completed: {0}", status);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/HelloDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/HelloDriver.java b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/HelloDriver.java
new file mode 100644
index 0000000..74fb131
--- /dev/null
+++ b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/HelloDriver.java
@@ -0,0 +1,183 @@
+/**
+ * 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.reef.examples.helloCLR;
+
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.driver.evaluator.EvaluatorType;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.examples.hello.HelloTask;
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.ConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.implementation.protobuf.ProtocolBufferClassHierarchy;
+import org.apache.reef.tang.proto.ClassHierarchyProto;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The Driver code for the Hello REEF Application
+ */
+@Unit
+public final class HelloDriver {
+
+  private static final Logger LOG = Logger.getLogger(HelloDriver.class.getName());
+
+  private final EvaluatorRequestor requestor;
+
+  private int nJVMTasks = 1;  // guarded by this
+  private int nCLRTasks = 1;  // guarded by this
+
+
+  /**
+   * Job driver constructor - instantiated via TANG.
+   *
+   * @param requestor evaluator requestor object used to create new evaluator containers.
+   */
+  @Inject
+  public HelloDriver(final EvaluatorRequestor requestor) {
+    this.requestor = requestor;
+  }
+
+  /**
+   * Makes a task configuration for the CLR Task.
+   *
+   * @param taskId
+   * @return task configuration for the CLR Task.
+   * @throws BindException
+   */
+  private static final Configuration getCLRTaskConfiguration(final String taskId) throws BindException {
+    final ConfigurationBuilder taskConfigurationBuilder = Tang.Factory.getTang()
+        .newConfigurationBuilder(loadClassHierarchy());
+    taskConfigurationBuilder.bind("Microsoft.Reef.Tasks.TaskConfigurationOptions+Identifier, Microsoft.Reef.Tasks.ITask, Version=1.0.0.0, Culture=neutral, PublicKeyToken=69c3241e6f0468ca", taskId);
+    taskConfigurationBuilder.bind("Microsoft.Reef.Tasks.ITask, Microsoft.Reef.Tasks.ITask, Version=1.0.0.0, Culture=neutral, PublicKeyToken=69c3241e6f0468ca", "Microsoft.Reef.Tasks.HelloTask, Microsoft.Reef.Tasks.HelloTask, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
+
+    return taskConfigurationBuilder.build();
+  }
+
+  /**
+   * Loads the class hierarchy.
+   *
+   * @return
+   */
+  private static ClassHierarchy loadClassHierarchy() {
+    try (final InputStream chin = new FileInputStream(HelloCLR.CLASS_HIERARCHY_FILENAME)) {
+      final ClassHierarchyProto.Node root = ClassHierarchyProto.Node.parseFrom(chin); // A
+      final ClassHierarchy ch = new ProtocolBufferClassHierarchy(root);
+      return ch;
+    } catch (final IOException e) {
+      final String message = "Unable to load class hierarchy.";
+      LOG.log(Level.SEVERE, message, e);
+      throw new RuntimeException(message, e);
+    }
+  }
+
+  /**
+   * Uses the AllocatedEvaluator to launch a CLR task.
+   *
+   * @param allocatedEvaluator
+   */
+  final void onNextCLR(final AllocatedEvaluator allocatedEvaluator) {
+    try {
+      allocatedEvaluator.setType(EvaluatorType.CLR);
+      final Configuration contextConfiguration = ContextConfiguration.CONF
+          .set(ContextConfiguration.IDENTIFIER, "HelloREEFContext")
+          .build();
+
+      final Configuration taskConfiguration = getCLRTaskConfiguration("Hello_From_CLR");
+
+      allocatedEvaluator.submitContextAndTask(contextConfiguration, taskConfiguration);
+    } catch (final BindException ex) {
+      final String message = "Unable to setup Task or Context configuration.";
+      LOG.log(Level.SEVERE, message, ex);
+      throw new RuntimeException(message, ex);
+    }
+  }
+
+  /**
+   * Uses the AllocatedEvaluator to launch a JVM task.
+   *
+   * @param allocatedEvaluator
+   */
+  final void onNextJVM(final AllocatedEvaluator allocatedEvaluator) {
+    try {
+      allocatedEvaluator.setType(EvaluatorType.JVM);
+      final Configuration contextConfiguration = ContextConfiguration.CONF
+          .set(ContextConfiguration.IDENTIFIER, "HelloREEFContext")
+          .build();
+
+      final Configuration taskConfiguration = TaskConfiguration.CONF
+          .set(TaskConfiguration.IDENTIFIER, "HelloREEFTask")
+          .set(TaskConfiguration.TASK, HelloTask.class)
+          .build();
+
+      allocatedEvaluator.submitContextAndTask(contextConfiguration, taskConfiguration);
+    } catch (final BindException ex) {
+      final String message = "Unable to setup Task or Context configuration.";
+      LOG.log(Level.SEVERE, message, ex);
+      throw new RuntimeException(message, ex);
+    }
+  }
+
+  /**
+   * Handles the StartTime event: Request as single Evaluator.
+   */
+  final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime startTime) {
+      LOG.log(Level.INFO, "StartTime: ", startTime);
+      HelloDriver.this.requestor.submit(EvaluatorRequest.newBuilder()
+          .setNumber(nCLRTasks + nJVMTasks)
+          .setMemory(128)
+          .setNumberOfCores(1)
+          .build());
+    }
+  }
+
+  /**
+   * Handles AllocatedEvaluator: Submit an empty context and the HelloTask
+   */
+  final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+      synchronized (HelloDriver.this) {
+        if (HelloDriver.this.nJVMTasks > 0) {
+          HelloDriver.this.onNextJVM(allocatedEvaluator);
+          HelloDriver.this.nJVMTasks -= 1;
+        } else if (HelloDriver.this.nCLRTasks > 0) {
+          HelloDriver.this.onNextCLR(allocatedEvaluator);
+          HelloDriver.this.nCLRTasks -= 1;
+        }
+      }
+    }
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/package-info.java b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/package-info.java
new file mode 100644
index 0000000..bf381b1
--- /dev/null
+++ b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * The Hello REEF example for the CLR.
+ */
+package org.apache.reef.examples.helloCLR;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/JobClient.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/JobClient.java b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/JobClient.java
new file mode 100644
index 0000000..8823c87
--- /dev/null
+++ b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/JobClient.java
@@ -0,0 +1,317 @@
+/**
+ * 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.reef.examples.retained_evalCLR;
+
+import org.apache.reef.client.*;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.util.EnvironmentUtils;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+
+import javax.inject.Inject;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Retained Evaluator Shell Client.
+ */
+@Unit
+public class JobClient {
+
+  /**
+   * Standard java logger.
+   */
+  private static final Logger LOG = Logger.getLogger(JobClient.class.getName());
+
+  /**
+   * Codec to translate messages to and from the job driver
+   */
+  private static final ObjectSerializableCodec<String> CODEC = new ObjectSerializableCodec<>();
+
+  /**
+   * Reference to the REEF framework.
+   * This variable is injected automatically in the constructor.
+   */
+  private final REEF reef;
+
+  /**
+   * Shell command to submitTask to the job driver.
+   */
+  private final String command;
+  /**
+   * If true, take commands from stdin; otherwise, use -cmd parameter in batch mode.
+   */
+  private final boolean isInteractive;
+  /**
+   * Total number of experiments to run.
+   */
+  private final int maxRuns;
+  /**
+   * Command prompt reader for the interactive mode (stdin).
+   */
+  private final BufferedReader prompt;
+  /**
+   * Job Driver configuration.
+   */
+  private Configuration driverConfiguration;
+  private ConfigurationModule driverConfigModule;
+  /**
+   * A reference to the running job that allows client to send messages back to the job driver
+   */
+  private RunningJob runningJob;
+
+  /**
+   * Start timestamp of the current task.
+   */
+  private long startTime = 0;
+
+  /**
+   * Total time spent performing tasks in Evaluators.
+   */
+  private long totalTime = 0;
+
+  /**
+   * Number of experiments ran so far.
+   */
+  private int numRuns = 0;
+
+  /**
+   * Set to false when job driver is done.
+   */
+  private boolean isBusy = true;
+
+  /**
+   * Retained Evaluator client.
+   * Parameters are injected automatically by TANG.
+   *
+   * @param command Shell command to run on each Evaluator.
+   * @param reef    Reference to the REEF framework.
+   */
+  @Inject
+  JobClient(final REEF reef,
+            @Parameter(Launch.Command.class) final String command,
+            @Parameter(Launch.NumRuns.class) final Integer numRuns) throws BindException {
+
+    this.reef = reef;
+    this.command = command;
+    this.maxRuns = numRuns;
+
+    // If command is not set, switch to interactive mode. (Yes, we compare pointers here)
+    this.isInteractive = this.command ==
+        Launch.Command.class.getAnnotation(NamedParameter.class).default_value();
+
+    this.prompt = this.isInteractive ? new BufferedReader(new InputStreamReader(System.in)) : null;
+
+    this.driverConfigModule = DriverConfiguration.CONF
+        .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(JobDriver.class))
+        .set(DriverConfiguration.DRIVER_IDENTIFIER, "eval-" + System.currentTimeMillis())
+        .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, JobDriver.AllocatedEvaluatorHandler.class)
+        .set(DriverConfiguration.ON_EVALUATOR_FAILED, JobDriver.FailedEvaluatorHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_ACTIVE, JobDriver.ActiveContextHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_CLOSED, JobDriver.ClosedContextHandler.class)
+        .set(DriverConfiguration.ON_CONTEXT_FAILED, JobDriver.FailedContextHandler.class)
+        .set(DriverConfiguration.ON_TASK_COMPLETED, JobDriver.CompletedTaskHandler.class)
+        .set(DriverConfiguration.ON_CLIENT_MESSAGE, JobDriver.ClientMessageHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_STARTED, JobDriver.StartHandler.class)
+        .set(DriverConfiguration.ON_DRIVER_STOP, JobDriver.StopHandler.class);
+  }
+
+  private void addCLRFiles(final File folder) throws BindException {
+    ConfigurationModule result = this.driverConfigModule;
+    for (final File f : folder.listFiles()) {
+      if (f.canRead() && f.exists() && f.isFile()) {
+        result = result.set(DriverConfiguration.GLOBAL_FILES, f.getAbsolutePath());
+      }
+    }
+
+    this.driverConfigModule = result;
+    this.driverConfiguration = this.driverConfigModule.build();
+  }
+
+  /**
+   * Launch the job driver.
+   *
+   * @throws BindException configuration error.
+   */
+  public void submit(File clrFolder) {
+    try {
+      addCLRFiles(clrFolder);
+    } catch (final BindException e) {
+      LOG.log(Level.FINE, "Failed to bind", e);
+    }
+    this.reef.submit(this.driverConfiguration);
+  }
+
+  /**
+   * Send command to the job driver. Record timestamp when the command was sent.
+   * If this.command is set, use it; otherwise, ask user for the command.
+   */
+  private synchronized void submitTask() {
+    if (this.isInteractive) {
+      String cmd;
+      try {
+        do {
+          System.out.print("\nRE> ");
+          cmd = this.prompt.readLine();
+        } while (cmd != null && cmd.trim().isEmpty());
+      } catch (final IOException ex) {
+        LOG.log(Level.FINE, "Error reading from stdin: {0}", ex);
+        cmd = null;
+      }
+      if (cmd == null || cmd.equals("exit")) {
+        this.runningJob.close();
+        stopAndNotify();
+      } else {
+        this.submitTask(cmd);
+      }
+    } else {
+      // non-interactive batch mode:
+      this.submitTask(this.command);
+    }
+  }
+
+  /**
+   * Send command to the job driver. Record timestamp when the command was sent.
+   *
+   * @param cmd shell command to execute in all Evaluators.
+   */
+  private synchronized void submitTask(final String cmd) {
+    LOG.log(Level.INFO, "Submit task {0} \"{1}\" to {2}",
+        new Object[]{this.numRuns + 1, cmd, this.runningJob});
+    this.startTime = System.currentTimeMillis();
+    this.runningJob.send(CODEC.encode(cmd));
+  }
+
+  /**
+   * Notify the process in waitForCompletion() method that the main process has finished.
+   */
+  private synchronized void stopAndNotify() {
+    this.runningJob = null;
+    this.isBusy = false;
+    this.notify();
+  }
+
+  /**
+   * Wait for the job driver to complete. This method is called from Launcher.main()
+   */
+  public void waitForCompletion() {
+    while (this.isBusy) {
+      LOG.info("Waiting for the Job Driver to complete.");
+      try {
+        synchronized (this) {
+          this.wait();
+        }
+      } catch (final InterruptedException ex) {
+        LOG.log(Level.WARNING, "Waiting for result interrupted.", ex);
+      }
+    }
+    this.reef.close();
+  }
+
+  /**
+   * Receive notification from the job driver that the job is running.
+   */
+  final class RunningJobHandler implements EventHandler<RunningJob> {
+    @Override
+    public void onNext(final RunningJob job) {
+      LOG.log(Level.INFO, "Running job: {0}", job.getId());
+      synchronized (JobClient.this) {
+        JobClient.this.runningJob = job;
+        JobClient.this.submitTask();
+      }
+    }
+  }
+
+  /**
+   * Receive message from the job driver.
+   * There is only one message, which comes at the end of the driver execution
+   * and contains shell command output on each node.
+   */
+  final class JobMessageHandler implements EventHandler<JobMessage> {
+    @Override
+    public void onNext(final JobMessage message) {
+      synchronized (JobClient.this) {
+
+        final String result = CODEC.decode(message.get());
+        final long jobTime = System.currentTimeMillis() - startTime;
+        totalTime += jobTime;
+        ++numRuns;
+
+        LOG.log(Level.INFO, "Task {0} completed in {1} msec.:\n{2}",
+            new Object[]{numRuns, jobTime, result});
+
+        System.out.println(result);
+
+        if (runningJob != null) {
+          if (isInteractive || numRuns < maxRuns) {
+            submitTask();
+          } else {
+            LOG.log(Level.INFO,
+                "All {0} tasks complete; Average task time: {1}. Closing the job driver.",
+                new Object[]{maxRuns, totalTime / (double) maxRuns});
+            runningJob.close();
+            stopAndNotify();
+          }
+        }
+      }
+    }
+  }
+
+  /**
+   * Receive notification from the job driver that the job had failed.
+   */
+  final class FailedJobHandler implements EventHandler<FailedJob> {
+    @Override
+    public void onNext(final FailedJob job) {
+      LOG.log(Level.SEVERE, "Failed job: " + job.getId(), job.getReason().orElse(null));
+      stopAndNotify();
+    }
+  }
+
+  /**
+   * Receive notification from the job driver that the job had completed successfully.
+   */
+  final class CompletedJobHandler implements EventHandler<CompletedJob> {
+    @Override
+    public void onNext(final CompletedJob job) {
+      LOG.log(Level.INFO, "Completed job: {0}", job.getId());
+      stopAndNotify();
+    }
+  }
+
+  /**
+   * Receive notification that there was an exception thrown from the job driver.
+   */
+  final class RuntimeErrorHandler implements EventHandler<FailedRuntime> {
+    @Override
+    public void onNext(final FailedRuntime error) {
+      LOG.log(Level.SEVERE, "Error in job driver: " + error, error.getReason().orElse(null));
+      stopAndNotify();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/JobDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/JobDriver.java b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/JobDriver.java
new file mode 100644
index 0000000..8b798cd
--- /dev/null
+++ b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/JobDriver.java
@@ -0,0 +1,489 @@
+/**
+ * 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.reef.examples.retained_evalCLR;
+
+import org.apache.reef.driver.catalog.ResourceCatalog;
+import org.apache.reef.driver.client.JobMessageObserver;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ClosedContext;
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.driver.evaluator.*;
+import org.apache.reef.driver.task.CompletedTask;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.examples.library.Command;
+import org.apache.reef.examples.library.ShellTask;
+import org.apache.reef.tang.*;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.implementation.protobuf.ProtocolBufferClassHierarchy;
+import org.apache.reef.tang.proto.ClassHierarchyProto;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.event.Alarm;
+import org.apache.reef.wake.time.event.StartTime;
+import org.apache.reef.wake.time.event.StopTime;
+
+import javax.inject.Inject;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Retained Evaluator example job driver. Execute shell command on all evaluators,
+ * capture stdout, and return concatenated results back to the client.
+ */
+@Unit
+public final class JobDriver {
+  public static final String SHELL_TASK_CLASS_HIERARCHY_FILENAME = "ShellTask.bin";
+  /**
+   * Standard Java logger.
+   */
+  private static final Logger LOG = Logger.getLogger(JobDriver.class.getName());
+  /**
+   * Duration of one clock interval.
+   */
+  private static final int CHECK_UP_INTERVAL = 1000; // 1 sec.
+  private static final String JVM_CONTEXT_SUFFIX = "_JVMContext";
+  private static final String CLR_CONTEXT_SUFFIX = "_CLRContext";
+  /**
+   * String codec is used to encode the results
+   * before passing them back to the client.
+   */
+  private static final ObjectSerializableCodec<String> JVM_CODEC = new ObjectSerializableCodec<>();
+  public static int totalEvaluators = 2;
+  /**
+   * Wake clock is used to schedule periodical job check-ups.
+   */
+  private final Clock clock;
+  /**
+   * Job observer on the client.
+   * We use it to send results from the driver back to the client.
+   */
+  private final JobMessageObserver jobMessageObserver;
+  /**
+   * Job driver uses EvaluatorRequestor
+   * to request Evaluators that will run the Tasks.
+   */
+  private final EvaluatorRequestor evaluatorRequestor;
+  /**
+   * Static catalog of REEF resources.
+   * We use it to schedule Task on every available node.
+   */
+  private final ResourceCatalog catalog;
+  /**
+   * Shell execution results from each Evaluator.
+   */
+  private final List<String> results = new ArrayList<>();
+  /**
+   * Map from context ID to running evaluator context.
+   */
+  private final Map<String, ActiveContext> contexts = new HashMap<>();
+  private int nCLREvaluator = 1;                  // guarded by this
+  private int nJVMEvaluator = totalEvaluators - nCLREvaluator;  // guarded by this
+  /**
+   * Job driver state.
+   */
+  private State state = State.INIT;
+  /**
+   * First command to execute. Sometimes client can send us the first command
+   * before Evaluators are available; we need to store this command here.
+   */
+  private String cmd;
+  /**
+   * Number of evaluators/tasks to complete.
+   */
+  private int expectCount = 0;
+
+  /**
+   * Job driver constructor.
+   * All parameters are injected from TANG automatically.
+   *
+   * @param clock              Wake clock to schedule and check up running jobs.
+   * @param jobMessageObserver is used to send messages back to the client.
+   * @param evaluatorRequestor is used to request Evaluators.
+   */
+  @Inject
+  JobDriver(final Clock clock,
+            final JobMessageObserver jobMessageObserver,
+            final EvaluatorRequestor evaluatorRequestor,
+            final ResourceCatalog catalog) {
+    this.clock = clock;
+    this.jobMessageObserver = jobMessageObserver;
+    this.evaluatorRequestor = evaluatorRequestor;
+    this.catalog = catalog;
+  }
+
+  /**
+   * Makes a task configuration for the CLR ShellTask.
+   *
+   * @param taskId
+   * @return task configuration for the CLR Task.
+   * @throws BindException
+   */
+  private static final Configuration getCLRTaskConfiguration(
+      final String taskId, final String command) throws BindException {
+
+    final ConfigurationBuilder cb = Tang.Factory.getTang()
+        .newConfigurationBuilder(loadShellTaskClassHierarchy(SHELL_TASK_CLASS_HIERARCHY_FILENAME));
+
+    cb.bind("Microsoft.Reef.Tasks.ITask, Microsoft.Reef.Tasks.ITask, Version=1.0.0.0, Culture=neutral, PublicKeyToken=69c3241e6f0468ca", "Microsoft.Reef.Tasks.ShellTask, Microsoft.Reef.Tasks.ShellTask, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
+    cb.bind("Microsoft.Reef.Tasks.TaskConfigurationOptions+Identifier, Microsoft.Reef.Tasks.ITask, Version=1.0.0.0, Culture=neutral, PublicKeyToken=69c3241e6f0468ca", taskId);
+    cb.bind("Microsoft.Reef.Tasks.ShellTask+Command, Microsoft.Reef.Tasks.ShellTask, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", command);
+
+    return cb.build();
+  }
+
+  /**
+   * Makes a task configuration for the JVM ShellTask..
+   *
+   * @param taskId
+   * @return task configuration for the JVM Task.
+   * @throws BindException
+   */
+  private static final Configuration getJVMTaskConfiguration(
+      final String taskId, final String command) throws BindException {
+
+    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.addConfiguration(
+        TaskConfiguration.CONF
+            .set(TaskConfiguration.IDENTIFIER, taskId)
+            .set(TaskConfiguration.TASK, ShellTask.class)
+            .build()
+    );
+    cb.bindNamedParameter(Command.class, command);
+    return cb.build();
+  }
+
+  /**
+   * Loads the class hierarchy.
+   *
+   * @return
+   */
+  private static ClassHierarchy loadShellTaskClassHierarchy(String binFile) {
+    try (final InputStream chin = new FileInputStream(binFile)) {
+      final ClassHierarchyProto.Node root = ClassHierarchyProto.Node.parseFrom(chin);
+      final ClassHierarchy ch = new ProtocolBufferClassHierarchy(root);
+      return ch;
+    } catch (final IOException e) {
+      final String message = "Unable to load class hierarchy " + binFile;
+      LOG.log(Level.SEVERE, message, e);
+      throw new RuntimeException(message, e);
+    }
+  }
+
+  private void submitEvaluator(final AllocatedEvaluator eval, EvaluatorType type) {
+    synchronized (JobDriver.this) {
+
+      String contextIdSuffix = type.equals(EvaluatorType.JVM) ? JVM_CONTEXT_SUFFIX : CLR_CONTEXT_SUFFIX;
+      String contextId = eval.getId() + contextIdSuffix;
+
+      eval.setType(type);
+
+      LOG.log(Level.INFO, "Allocated Evaluator: {0} expect {1} running {2}",
+          new Object[]{eval.getId(), JobDriver.this.expectCount, JobDriver.this.contexts.size()});
+      assert (JobDriver.this.state == State.WAIT_EVALUATORS);
+      try {
+        eval.submitContext(ContextConfiguration.CONF.set(ContextConfiguration.IDENTIFIER, contextId).build());
+      } catch (final BindException ex) {
+        LOG.log(Level.SEVERE, "Failed to submit context " + contextId, ex);
+        throw new RuntimeException(ex);
+      }
+    }
+  }
+
+  /**
+   * Submit command to all available evaluators.
+   *
+   * @param command shell command to execute.
+   */
+  private void submit(final String command) {
+    LOG.log(Level.INFO, "Submit command {0} to {1} evaluators. state: {2}",
+        new Object[]{command, this.contexts.size(), this.state});
+    assert (this.state == State.READY);
+    this.expectCount = this.contexts.size();
+    this.state = State.WAIT_TASKS;
+    this.cmd = null;
+    for (final ActiveContext context : this.contexts.values()) {
+      this.submit(context, command);
+    }
+  }
+
+  /**
+   * Submit a Task that execute the command to a single Evaluator.
+   * This method is called from <code>submitTask(cmd)</code>.
+   */
+  private void submit(final ActiveContext context, final String command) {
+    try {
+      LOG.log(Level.INFO, "Sending command {0} to context: {1}", new Object[]{command, context});
+      String taskId = context.getId() + "_task";
+      final Configuration taskConfiguration;
+      if (context.getId().endsWith(JVM_CONTEXT_SUFFIX)) {
+        taskConfiguration = getJVMTaskConfiguration(taskId, command);
+      } else {
+        taskConfiguration = getCLRTaskConfiguration(taskId, command);
+      }
+      context.submitTask(taskConfiguration);
+    } catch (final BindException ex) {
+      LOG.log(Level.SEVERE, "Bad Task configuration for context: " + context.getId(), ex);
+      throw new RuntimeException(ex);
+    }
+  }
+
+  /**
+   * Construct the final result and forward it to the Client.
+   */
+  private void returnResults() {
+    final StringBuilder sb = new StringBuilder();
+    for (final String result : this.results) {
+      sb.append(result);
+    }
+    this.results.clear();
+    LOG.log(Level.INFO, "Return results to the client:\n{0}", sb);
+    this.jobMessageObserver.sendMessageToClient(JVM_CODEC.encode(sb.toString()));
+  }
+
+  /**
+   * Request evaluators on each node.
+   * If nodes are not available yet, schedule another request in CHECK_UP_INTERVAL.
+   * TODO: Ask for specific nodes. (This is not working in YARN... need to check again at some point.)
+   *
+   * @throws RuntimeException if any of the requests fails.
+   */
+  private synchronized void requestEvaluators() {
+    assert (this.state == State.INIT);
+    final int numNodes = totalEvaluators;
+    if (numNodes > 0) {
+      LOG.log(Level.INFO, "Schedule on {0} nodes.", numNodes);
+      this.evaluatorRequestor.submit(
+          EvaluatorRequest.newBuilder()
+              .setMemory(128)
+              .setNumberOfCores(1)
+              .setNumber(numNodes).build()
+      );
+      this.state = State.WAIT_EVALUATORS;
+      this.expectCount = numNodes;
+    } else {
+      // No nodes available yet - wait and ask again.
+      this.clock.scheduleAlarm(CHECK_UP_INTERVAL, new EventHandler<Alarm>() {
+        @Override
+        public void onNext(final Alarm time) {
+          synchronized (JobDriver.this) {
+            LOG.log(Level.INFO, "{0} Alarm: {1}", new Object[]{JobDriver.this.state, time});
+            if (JobDriver.this.state == State.INIT) {
+              JobDriver.this.requestEvaluators();
+            }
+          }
+        }
+      });
+    }
+  }
+
+  /**
+   * Possible states of the job driver. Can be one of:
+   * <dl>
+   * <du><code>INIT</code></du><dd>initial state, ready to request the evaluators.</dd>
+   * <du><code>WAIT_EVALUATORS</code></du><dd>Wait for requested evaluators to initialize.</dd>
+   * <du><code>READY</code></du><dd>Ready to submitTask a new task.</dd>
+   * <du><code>WAIT_TASKS</code></du><dd>Wait for tasks to complete.</dd>
+   * </dl>
+   */
+  private enum State {
+    INIT, WAIT_EVALUATORS, READY, WAIT_TASKS
+  }
+
+  /**
+   * Handles AllocatedEvaluator: Submit an empty context
+   */
+  final class AllocatedEvaluatorHandler implements EventHandler<AllocatedEvaluator> {
+    @Override
+    public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+      synchronized (JobDriver.this) {
+        if (JobDriver.this.nJVMEvaluator > 0) {
+          LOG.log(Level.INFO, "===== adding JVM evaluator =====");
+          JobDriver.this.submitEvaluator(allocatedEvaluator, EvaluatorType.JVM);
+          JobDriver.this.nJVMEvaluator -= 1;
+        } else if (JobDriver.this.nCLREvaluator > 0) {
+          LOG.log(Level.INFO, "===== adding CLR evaluator =====");
+          JobDriver.this.submitEvaluator(allocatedEvaluator, EvaluatorType.CLR);
+          JobDriver.this.nCLREvaluator -= 1;
+        }
+      }
+    }
+  }
+
+  /**
+   * Receive notification that a new Context is available.
+   * Submit a new Distributed Shell Task to that Context.
+   */
+  final class ActiveContextHandler implements EventHandler<ActiveContext> {
+    @Override
+    public void onNext(final ActiveContext context) {
+      synchronized (JobDriver.this) {
+        LOG.log(Level.INFO, "Context available: {0} expect {1} state {2}",
+            new Object[]{context.getId(), JobDriver.this.expectCount, JobDriver.this.state});
+        assert (JobDriver.this.state == State.WAIT_EVALUATORS);
+        JobDriver.this.contexts.put(context.getId(), context);
+        if (--JobDriver.this.expectCount <= 0) {
+          JobDriver.this.state = State.READY;
+          if (JobDriver.this.cmd == null) {
+            LOG.log(Level.INFO, "All evaluators ready; waiting for command. State: {0}",
+                JobDriver.this.state);
+          } else {
+            JobDriver.this.submit(JobDriver.this.cmd);
+          }
+        }
+      }
+    }
+  }
+
+  /**
+   * Receive notification that the Context had completed.
+   * Remove context from the list of active context.
+   */
+  final class ClosedContextHandler implements EventHandler<ClosedContext> {
+    @Override
+    public void onNext(final ClosedContext context) {
+      LOG.log(Level.INFO, "Completed Context: {0}", context.getId());
+      synchronized (JobDriver.this) {
+        JobDriver.this.contexts.remove(context.getId());
+      }
+    }
+  }
+
+  /**
+   * Receive notification that the Context had failed.
+   * Remove context from the list of active context and notify the client.
+   */
+  final class FailedContextHandler implements EventHandler<FailedContext> {
+    @Override
+    public void onNext(final FailedContext context) {
+      LOG.log(Level.SEVERE, "FailedContext", context);
+      synchronized (JobDriver.this) {
+        JobDriver.this.contexts.remove(context.getId());
+      }
+      throw new RuntimeException("Failed context: ", context.asError());
+    }
+  }
+
+  /**
+   * Receive notification that the entire Evaluator had failed.
+   * Stop other jobs and pass this error to the job observer on the client.
+   */
+  final class FailedEvaluatorHandler implements EventHandler<FailedEvaluator> {
+    @Override
+    public void onNext(final FailedEvaluator eval) {
+      synchronized (JobDriver.this) {
+        LOG.log(Level.SEVERE, "FailedEvaluator", eval);
+        for (final FailedContext failedContext : eval.getFailedContextList()) {
+          JobDriver.this.contexts.remove(failedContext.getId());
+        }
+        throw new RuntimeException("Failed Evaluator: ", eval.getEvaluatorException());
+      }
+    }
+  }
+
+  /**
+   * Receive notification that the Task has completed successfully.
+   */
+  final class CompletedTaskHandler implements EventHandler<CompletedTask> {
+    @Override
+    public void onNext(final CompletedTask task) {
+      LOG.log(Level.INFO, "Completed task: {0}", task.getId());
+      // Take the message returned by the task and add it to the running result.
+      String result = "default result";
+      try {
+        if (task.getId().contains(CLR_CONTEXT_SUFFIX)) {
+          result = new String(task.get());
+        } else {
+          result = JVM_CODEC.decode(task.get());
+        }
+      } catch (final Exception e) {
+        LOG.log(Level.WARNING, "failed to decode task outcome");
+      }
+      synchronized (JobDriver.this) {
+        JobDriver.this.results.add(task.getId() + " :: " + result);
+        LOG.log(Level.INFO, "Task {0} result {1}: {2} state: {3}", new Object[]{
+            task.getId(), JobDriver.this.results.size(), result, JobDriver.this.state});
+        if (--JobDriver.this.expectCount <= 0) {
+          JobDriver.this.returnResults();
+          JobDriver.this.state = State.READY;
+          if (JobDriver.this.cmd != null) {
+            JobDriver.this.submit(JobDriver.this.cmd);
+          }
+        }
+      }
+    }
+  }
+
+  /**
+   * Receive notification from the client.
+   */
+  final class ClientMessageHandler implements EventHandler<byte[]> {
+    @Override
+    public void onNext(final byte[] message) {
+      synchronized (JobDriver.this) {
+        final String command = JVM_CODEC.decode(message);
+        LOG.log(Level.INFO, "Client message: {0} state: {1}",
+            new Object[]{command, JobDriver.this.state});
+        assert (JobDriver.this.cmd == null);
+        if (JobDriver.this.state == State.READY) {
+          JobDriver.this.submit(command);
+        } else {
+          // not ready yet - save the command for better times.
+          assert (JobDriver.this.state == State.WAIT_EVALUATORS);
+          JobDriver.this.cmd = command;
+        }
+      }
+    }
+  }
+
+  /**
+   * Job Driver is ready and the clock is set up: request the evaluators.
+   */
+  final class StartHandler implements EventHandler<StartTime> {
+    @Override
+    public void onNext(final StartTime startTime) {
+      LOG.log(Level.INFO, "{0} StartTime: {1}", new Object[]{state, startTime});
+      assert (state == State.INIT);
+      requestEvaluators();
+    }
+  }
+
+  /**
+   * Shutting down the job driver: close the evaluators.
+   */
+  final class StopHandler implements EventHandler<StopTime> {
+    @Override
+    public void onNext(final StopTime time) {
+      LOG.log(Level.INFO, "{0} StopTime: {1}", new Object[]{state, time});
+      for (final ActiveContext context : contexts.values()) {
+        context.close();
+      }
+    }
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/Launch.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/Launch.java b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/Launch.java
new file mode 100644
index 0000000..97c39c3
--- /dev/null
+++ b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/Launch.java
@@ -0,0 +1,189 @@
+/**
+ * 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.reef.examples.retained_evalCLR;
+
+import org.apache.reef.client.ClientConfiguration;
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.runtime.yarn.client.YarnClientConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.AvroConfigurationSerializer;
+import org.apache.reef.tang.formats.CommandLine;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.OptionalParameter;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Retained Evaluators example - main class.
+ */
+public final class Launch {
+
+  /**
+   * Number of REEF worker threads in local mode.
+   */
+  private static final int NUM_LOCAL_THREADS = JobDriver.totalEvaluators;
+  /**
+   * Standard Java logger
+   */
+  private static final Logger LOG = Logger.getLogger(Launch.class.getName());
+
+  /**
+   * This class should not be instantiated.
+   */
+  private Launch() {
+    throw new RuntimeException("Do not instantiate this class!");
+  }
+
+  /**
+   * Parse the command line arguments.
+   *
+   * @param args command line arguments, as passed to main()
+   * @return Configuration object.
+   * @throws BindException configuration error.
+   * @throws IOException   error reading the configuration.
+   */
+  private static Configuration parseCommandLine(final String[] args)
+      throws BindException, IOException {
+    final JavaConfigurationBuilder confBuilder = Tang.Factory.getTang().newConfigurationBuilder();
+    final CommandLine cl = new CommandLine(confBuilder);
+    cl.registerShortNameOfClass(Local.class);
+    cl.registerShortNameOfClass(Command.class);
+    cl.registerShortNameOfClass(NumRuns.class);
+    cl.processCommandLine(args);
+    return confBuilder.build();
+  }
+
+  private static Configuration cloneCommandLineConfiguration(final Configuration commandLineConf)
+      throws InjectionException, BindException {
+    final Injector injector = Tang.Factory.getTang().newInjector(commandLineConf);
+    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+    cb.bindNamedParameter(Command.class, injector.getNamedInstance(Command.class));
+    cb.bindNamedParameter(NumRuns.class, String.valueOf(injector.getNamedInstance(NumRuns.class)));
+    return cb.build();
+  }
+
+  /**
+   * Parse command line arguments and create TANG configuration ready to be submitted to REEF.
+   *
+   * @param args Command line arguments, as passed into main().
+   * @return (immutable) TANG Configuration object.
+   * @throws BindException      if configuration commandLineInjector fails.
+   * @throws InjectionException if configuration commandLineInjector fails.
+   * @throws IOException        error reading the configuration.
+   */
+  private static Configuration getClientConfiguration(final String[] args)
+      throws BindException, InjectionException, IOException {
+
+    final Configuration commandLineConf = parseCommandLine(args);
+
+    final Configuration clientConfiguration = ClientConfiguration.CONF
+        .set(ClientConfiguration.ON_JOB_RUNNING, JobClient.RunningJobHandler.class)
+        .set(ClientConfiguration.ON_JOB_MESSAGE, JobClient.JobMessageHandler.class)
+        .set(ClientConfiguration.ON_JOB_COMPLETED, JobClient.CompletedJobHandler.class)
+        .set(ClientConfiguration.ON_JOB_FAILED, JobClient.FailedJobHandler.class)
+        .set(ClientConfiguration.ON_RUNTIME_ERROR, JobClient.RuntimeErrorHandler.class)
+        .build();
+
+    // TODO: Remove the injector, have stuff injected.
+    final Injector commandLineInjector = Tang.Factory.getTang().newInjector(commandLineConf);
+    final boolean isLocal = commandLineInjector.getNamedInstance(Local.class);
+    final Configuration runtimeConfiguration;
+    if (isLocal) {
+      LOG.log(Level.INFO, "Running on the local runtime");
+      runtimeConfiguration = LocalRuntimeConfiguration.CONF
+          .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, NUM_LOCAL_THREADS)
+          .build();
+    } else {
+      LOG.log(Level.INFO, "Running on YARN");
+      runtimeConfiguration = YarnClientConfiguration.CONF.build();
+    }
+
+    return Tang.Factory.getTang()
+        .newConfigurationBuilder(runtimeConfiguration, clientConfiguration,
+            cloneCommandLineConfiguration(commandLineConf))
+        .build();
+  }
+
+  private static ConfigurationModule addAll(final ConfigurationModule conf, final OptionalParameter<String> param, final File folder) {
+    ConfigurationModule result = conf;
+    for (final File f : folder.listFiles()) {
+      if (f.canRead() && f.exists() && f.isFile()) {
+        result = result.set(param, f.getAbsolutePath());
+      }
+    }
+    return result;
+  }
+
+  /**
+   * Main method that starts the Retained Evaluators job.
+   *
+   * @param args command line parameters.
+   */
+  public static void main(final String[] args) {
+    try {
+      final File dotNetFolder = new File(args[0]).getAbsoluteFile();
+      String[] removedArgs = Arrays.copyOfRange(args, 1, args.length);
+
+      final Configuration config = getClientConfiguration(removedArgs);
+      LOG.log(Level.INFO, "Configuration:\n--\n{0}--",
+          new AvroConfigurationSerializer().toString(config));
+      final Injector injector = Tang.Factory.getTang().newInjector(config);
+      final JobClient client = injector.getInstance(JobClient.class);
+      client.submit(dotNetFolder);
+      client.waitForCompletion();
+      LOG.info("Done!");
+    } catch (final BindException | InjectionException | IOException ex) {
+      LOG.log(Level.SEVERE, "Job configuration error", ex);
+    }
+  }
+
+  /**
+   * Command line parameter: a command to run. e.g. "echo Hello REEF"
+   */
+  @NamedParameter(doc = "The shell command", short_name = "cmd", default_value = "*INTERACTIVE*")
+  public static final class Command implements Name<String> {
+  }
+
+  /**
+   * Command line parameter: number of experiments to run.
+   */
+  @NamedParameter(doc = "Number of times to run the command",
+      short_name = "num_runs", default_value = "1")
+  public static final class NumRuns implements Name<Integer> {
+  }
+
+  /**
+   * Command line parameter = true to run locally, or false to run on YARN.
+   */
+  @NamedParameter(doc = "Whether or not to run on the local runtime",
+      short_name = "local", default_value = "true")
+  public static final class Local implements Name<Boolean> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/package-info.java b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/package-info.java
new file mode 100644
index 0000000..45455bb
--- /dev/null
+++ b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * The Retained Evaluators CLR example.
+ */
+package org.apache.reef.examples.retained_evalCLR;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-hdinsight/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-hdinsight/pom.xml b/lang/java/reef-examples-hdinsight/pom.xml
new file mode 100644
index 0000000..ce52f92
--- /dev/null
+++ b/lang/java/reef-examples-hdinsight/pom.xml
@@ -0,0 +1,128 @@
+<?xml version="1.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.
+-->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+         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>
+    <artifactId>reef-examples-hdinsight</artifactId>
+    <name>REEF Examples on HDInsight</name>
+
+    <parent>
+        <groupId>org.apache.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <dependencies>
+        <!-- REEF -->
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-hdinsight</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-examples</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <!-- End of REEF -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <!-- Hadoop -->
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-common</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-yarn-common</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-yarn-client</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-yarn-api</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <!-- End of Hadoop -->
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-jdk14</artifactId>
+            <optional>true</optional>
+        </dependency>
+    </dependencies>
+
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-shade-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>shade</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <outputFile>
+                        ${project.build.directory}/${project.artifactId}-${project.version}-shaded.jar
+                    </outputFile>
+                    <transformers>
+                        <transformer
+                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+                            <manifestEntries>
+                                <Main-Class>
+                                    org.apache.reef.runtime.hdinsight.cli.HDICLI
+                                </Main-Class>
+                            </manifestEntries>
+                        </transformer>
+                    </transformers>
+                    <filters>
+                        <filter>
+                            <artifact>*:*</artifact>
+                            <excludes>
+                                <exclude>yarn-default.xml</exclude>
+                                <exclude>yarn-version-info.properties</exclude>
+                                <exclude>core-default.xml</exclude>
+                                <exclude>LICENSE</exclude>
+                                <exclude>META-INF/*</exclude>
+                            </excludes>
+                        </filter>
+                    </filters>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-hdinsight/src/main/java/org/apache/reef/examples/hello/HelloHDInsight.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-hdinsight/src/main/java/org/apache/reef/examples/hello/HelloHDInsight.java b/lang/java/reef-examples-hdinsight/src/main/java/org/apache/reef/examples/hello/HelloHDInsight.java
new file mode 100644
index 0000000..2eacd7b
--- /dev/null
+++ b/lang/java/reef-examples-hdinsight/src/main/java/org/apache/reef/examples/hello/HelloHDInsight.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.examples.hello;
+
+import org.apache.reef.runtime.hdinsight.client.UnsafeHDInsightRuntimeConfiguration;
+import org.apache.reef.tang.exceptions.InjectionException;
+
+import java.io.IOException;
+
+/**
+ * HelloREEF running on HDInsight
+ */
+public class HelloHDInsight {
+  public static void main(final String[] args) throws InjectionException, IOException {
+    HelloREEFNoClient.runHelloReefWithoutClient(UnsafeHDInsightRuntimeConfiguration.fromEnvironment());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/.gitignore
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/.gitignore b/lang/java/reef-examples/.gitignore
new file mode 100644
index 0000000..8ce3786
--- /dev/null
+++ b/lang/java/reef-examples/.gitignore
@@ -0,0 +1 @@
+dotnet*
\ No newline at end of file


[34/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/JavaLaunchCommandBuilder.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/JavaLaunchCommandBuilder.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/JavaLaunchCommandBuilder.java
new file mode 100644
index 0000000..8084068
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/JavaLaunchCommandBuilder.java
@@ -0,0 +1,163 @@
+/**
+ * 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.reef.runtime.common.launch;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.reef.runtime.common.Launcher;
+import org.apache.reef.runtime.common.launch.parameters.ClockConfigurationPath;
+import org.apache.reef.runtime.common.launch.parameters.ErrorHandlerRID;
+import org.apache.reef.runtime.common.launch.parameters.LaunchID;
+import org.apache.reef.util.EnvironmentUtils;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+public final class JavaLaunchCommandBuilder implements LaunchCommandBuilder {
+  private static final String DEFAULT_JAVA_PATH = System.getenv("JAVA_HOME") + "/bin/" + "java";
+  private String stderrPath = null;
+  private String stdoutPath = null;
+  private String errorHandlerRID = null;
+  private String launchID = null;
+  private int megaBytes = 0;
+  private String evaluatorConfigurationPath = null;
+  private String javaPath = null;
+  private String classPath = null;
+  private Boolean assertionsEnabled = null;
+
+  @Override
+  public List<String> build() {
+    return new ArrayList<String>() {{
+
+      if (javaPath == null || javaPath.isEmpty()) {
+        add(DEFAULT_JAVA_PATH);
+      } else {
+        add(javaPath);
+      }
+
+      add("-XX:PermSize=128m");
+      add("-XX:MaxPermSize=128m");
+      // Set Xmx based on am memory size
+      add("-Xmx" + megaBytes + "m");
+
+      if ((assertionsEnabled != null && assertionsEnabled)
+          || EnvironmentUtils.areAssertionsEnabled()) {
+        add("-ea");
+      }
+
+      if (classPath != null && !classPath.isEmpty()) {
+        add("-classpath");
+        add(classPath);
+      }
+
+      Launcher.propagateProperties(this, true, "proc_reef");
+      Launcher.propagateProperties(this, false,
+          "java.util.logging.config.file", "java.util.logging.config.class");
+
+      add(Launcher.class.getName());
+
+      add("-" + ErrorHandlerRID.SHORT_NAME);
+      add(errorHandlerRID);
+      add("-" + LaunchID.SHORT_NAME);
+      add(launchID);
+      add("-" + ClockConfigurationPath.SHORT_NAME);
+      add(evaluatorConfigurationPath);
+
+      if (stdoutPath != null && !stdoutPath.isEmpty()) {
+        add("1>");
+        add(stdoutPath);
+      }
+
+      if (stderrPath != null && !stderrPath.isEmpty()) {
+        add("2>");
+        add(stderrPath);
+      }
+    }};
+  }
+
+  @Override
+  public JavaLaunchCommandBuilder setErrorHandlerRID(final String errorHandlerRID) {
+    this.errorHandlerRID = errorHandlerRID;
+    return this;
+  }
+
+  @Override
+  public JavaLaunchCommandBuilder setLaunchID(final String launchID) {
+    this.launchID = launchID;
+    return this;
+  }
+
+  @Override
+  public JavaLaunchCommandBuilder setMemory(final int megaBytes) {
+    this.megaBytes = megaBytes;
+    return this;
+  }
+
+  @Override
+  public JavaLaunchCommandBuilder setConfigurationFileName(final String configurationFileName) {
+    this.evaluatorConfigurationPath = configurationFileName;
+    return this;
+  }
+
+  @Override
+  public JavaLaunchCommandBuilder setStandardOut(final String standardOut) {
+    this.stdoutPath = standardOut;
+    return this;
+  }
+
+  @Override
+  public JavaLaunchCommandBuilder setStandardErr(final String standardErr) {
+    this.stderrPath = standardErr;
+    return this;
+  }
+
+  /**
+   * Set the path to the java executable. Will default to a heuristic search if not set.
+   *
+   * @param path
+   * @return this
+   */
+  public JavaLaunchCommandBuilder setJavaPath(final String path) {
+    this.javaPath = path;
+    return this;
+  }
+
+  public JavaLaunchCommandBuilder setClassPath(final String classPath) {
+    this.classPath = classPath;
+    return this;
+  }
+
+  public JavaLaunchCommandBuilder setClassPath(final Collection<String> classPathElements) {
+    this.classPath = StringUtils.join(classPathElements, File.pathSeparatorChar);
+    return this;
+  }
+
+  /**
+   * Enable or disable assertions on the child process.
+   * If not set, the setting is taken from the JVM that executes the code.
+   *
+   * @param assertionsEnabled
+   * @return this
+   */
+  public JavaLaunchCommandBuilder enableAssertions(final boolean assertionsEnabled) {
+    this.assertionsEnabled = assertionsEnabled;
+    return this;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/LaunchClass.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/LaunchClass.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/LaunchClass.java
new file mode 100644
index 0000000..8c40439
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/LaunchClass.java
@@ -0,0 +1,191 @@
+/**
+ * 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.reef.runtime.common.launch;
+
+import org.apache.reef.runtime.common.evaluator.PIDStoreStartHandler;
+import org.apache.reef.runtime.common.launch.parameters.ClockConfigurationPath;
+import org.apache.reef.runtime.common.launch.parameters.ErrorHandlerRID;
+import org.apache.reef.runtime.common.launch.parameters.LaunchID;
+import org.apache.reef.runtime.common.utils.RemoteManager;
+import org.apache.reef.tang.*;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.formats.ConfigurationSerializer;
+import org.apache.reef.util.REEFVersion;
+import org.apache.reef.wake.profiler.WakeProfiler;
+import org.apache.reef.wake.remote.RemoteConfiguration;
+import org.apache.reef.wake.time.Clock;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This encapsulates processes started by REEF.
+ */
+public final class LaunchClass implements AutoCloseable, Runnable {
+
+  private static final Logger LOG = Logger.getLogger(LaunchClass.class.getName());
+  private final RemoteManager remoteManager;
+  private final String launchID;
+  private final String errorHandlerID;
+  private final String evaluatorConfigurationPath;
+  private final boolean isProfilingEnabled;
+  private final REEFErrorHandler errorHandler;
+  private final ConfigurationSerializer configurationSerializer;
+  private WakeProfiler profiler;
+
+  @Inject
+  LaunchClass(final RemoteManager remoteManager,
+              final REEFUncaughtExceptionHandler uncaughtExceptionHandler,
+              final REEFErrorHandler errorHandler,
+              final @Parameter(LaunchID.class) String launchID,
+              final @Parameter(ErrorHandlerRID.class) String errorHandlerID,
+              final @Parameter(ClockConfigurationPath.class) String evaluatorConfigurationPath,
+              final @Parameter(ProfilingEnabled.class) boolean enableProfiling,
+              final ConfigurationSerializer configurationSerializer,
+              final REEFVersion reefVersion) {
+    reefVersion.logVersion();
+    this.remoteManager = remoteManager;
+    this.launchID = launchID;
+    this.errorHandlerID = errorHandlerID;
+    this.evaluatorConfigurationPath = evaluatorConfigurationPath;
+    this.isProfilingEnabled = enableProfiling;
+    this.errorHandler = errorHandler;
+    this.configurationSerializer = configurationSerializer;
+
+
+    // Registering a default exception handler. It sends every exception to the upstream RemoteManager
+    Thread.setDefaultUncaughtExceptionHandler(uncaughtExceptionHandler);
+
+
+    if (isProfilingEnabled) {
+      this.profiler = new WakeProfiler();
+      ProfilingStopHandler.setProfiler(profiler); // TODO: This probably should be bound via Tang.
+    }
+  }
+
+  /**
+   * Loads the client and resource manager configuration files from disk.
+   */
+  private Configuration getClockConfiguration() {
+    return Configurations.merge(readConfigurationFromDisk(), getStaticClockConfiguration());
+  }
+
+
+  private Configuration readConfigurationFromDisk() {
+    LOG.log(Level.FINEST, "Loading configuration file: {0}", this.evaluatorConfigurationPath);
+
+    final File evaluatorConfigFile = new File(this.evaluatorConfigurationPath);
+
+    if (!evaluatorConfigFile.exists()) {
+      final String message = "The configuration file " + this.evaluatorConfigurationPath +
+          "doesn't exist. This points to an issue in the job submission.";
+      fail(message, new FileNotFoundException());
+      throw new RuntimeException(message);
+    } else if (!evaluatorConfigFile.canRead()) {
+      final String message = "The configuration file " + this.evaluatorConfigurationPath + " exists, but can't be read";
+      fail(message, new IOException());
+      throw new RuntimeException(message);
+    } else {
+      try {
+        return this.configurationSerializer.fromFile(evaluatorConfigFile);
+      } catch (final IOException e) {
+        final String message = "Unable to parse the configuration file " + this.evaluatorConfigurationPath;
+        fail(message, e);
+        throw new RuntimeException(message, e);
+      }
+    }
+  }
+
+  /**
+   * @return the part of the clock configuration *not* read from disk.
+   */
+  private Configuration getStaticClockConfiguration() {
+    final JavaConfigurationBuilder builder = Tang.Factory.getTang().newConfigurationBuilder()
+        .bindNamedParameter(LaunchID.class, this.launchID)
+        .bindNamedParameter(ErrorHandlerRID.class, this.errorHandlerID)
+        .bindSetEntry(Clock.StartHandler.class, PIDStoreStartHandler.class)
+        .bindNamedParameter(RemoteConfiguration.ErrorHandler.class, REEFErrorHandler.class)
+        .bindNamedParameter(RemoteConfiguration.ManagerName.class, "REEF_LAUNCHER")
+        .bindNamedParameter(RemoteConfiguration.MessageCodec.class, REEFMessageCodec.class);
+    if (this.isProfilingEnabled) {
+      builder.bindSetEntry(Clock.StopHandler.class, ProfilingStopHandler.class);
+    }
+    return builder.build();
+  }
+
+  /**
+   * Instantiates the clock.
+   *
+   * @return a clock object.
+   */
+  private Clock getClock() {
+    try {
+      final Injector clockInjector = Tang.Factory.getTang().newInjector(this.getClockConfiguration());
+      if (isProfilingEnabled) {
+        clockInjector.bindAspect(profiler);
+      }
+      clockInjector.bindVolatileInstance(RemoteManager.class, this.remoteManager);
+      return clockInjector.getInstance(Clock.class);
+    } catch (final Throwable ex) {
+      fail("Unable to instantiate the clock", ex);
+      throw new RuntimeException("Unable to instantiate the clock", ex);
+    }
+  }
+
+  /**
+   * Starts the Clock.
+   * This blocks until the clock returns.
+   */
+  @Override
+  public void run() {
+    LOG.entering(this.getClass().getName(), "run", "Starting the clock");
+    try {
+      this.getClock().run();
+    } catch (final Throwable t) {
+      fail("Fatal exception while executing the clock", t);
+    }
+    LOG.exiting(this.getClass().getName(), "run", "Clock terminated");
+  }
+
+  /**
+   * Closes the remote manager managed by this class.
+   *
+   * @throws Exception
+   */
+  @Override
+  public void close() throws Exception {
+    LOG.entering(this.getClass().getName(), "close");
+    this.errorHandler.close(); // Also closes the remoteManager
+    LOG.exiting(this.getClass().getName(), "close");
+  }
+
+  private void fail(final String message, final Throwable throwable) {
+    this.errorHandler.onNext(new Exception(message, throwable));
+  }
+
+  @NamedParameter(doc = "If true, profiling will be enabled", short_name = "profiling", default_value = "false")
+  public final static class ProfilingEnabled implements Name<Boolean> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/LaunchCommandBuilder.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/LaunchCommandBuilder.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/LaunchCommandBuilder.java
new file mode 100644
index 0000000..6874b83
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/LaunchCommandBuilder.java
@@ -0,0 +1,66 @@
+/**
+ * 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.reef.runtime.common.launch;
+
+import java.util.List;
+
+/**
+ * Used to build the launch command for REEF processes.
+ */
+public interface LaunchCommandBuilder {
+
+
+  /**
+   * @return the launch command line
+   */
+  public List<String> build();
+
+  public LaunchCommandBuilder setErrorHandlerRID(final String errorHandlerRID);
+
+  public LaunchCommandBuilder setLaunchID(final String launchID);
+
+  public LaunchCommandBuilder setMemory(final int megaBytes);
+
+  /**
+   * Set the name of the configuration file for the Launcher. This file is assumed to exist in the working directory of
+   * the process launched with this command line.
+   *
+   * @param configurationFileName
+   * @return this
+   */
+  public LaunchCommandBuilder setConfigurationFileName(final String configurationFileName);
+
+  /**
+   * Names a file to which stdout will be redirected.
+   *
+   * @param standardOut
+   * @return this
+   */
+  public LaunchCommandBuilder setStandardOut(final String standardOut);
+
+  /**
+   * Names a file to which stderr will be redirected.
+   *
+   * @param standardErr
+   * @return this
+   */
+  public LaunchCommandBuilder setStandardErr(final String standardErr);
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/LauncherSingletons.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/LauncherSingletons.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/LauncherSingletons.java
new file mode 100644
index 0000000..51da6c0
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/LauncherSingletons.java
@@ -0,0 +1,18 @@
+/**
+ * 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.
+ */

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/ProfilingStopHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/ProfilingStopHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/ProfilingStopHandler.java
new file mode 100644
index 0000000..3ddabb0
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/ProfilingStopHandler.java
@@ -0,0 +1,58 @@
+/**
+ * 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.reef.runtime.common.launch;
+
+import org.apache.reef.runtime.common.launch.parameters.LaunchID;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.profiler.WakeProfiler;
+import org.apache.reef.wake.time.event.StopTime;
+
+import javax.inject.Inject;
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * An EventHandler that writes out the profiler results.
+ */
+final class ProfilingStopHandler implements EventHandler<StopTime> {
+  private static final Logger LOG = Logger.getLogger(ProfilingStopHandler.class.getName());
+  private static WakeProfiler profiler;
+  private final String launchID;
+
+  @Inject
+  public ProfilingStopHandler(final @Parameter(LaunchID.class) String launchID) {
+    this.launchID = launchID;
+  }
+
+  static void setProfiler(final WakeProfiler profiler) {
+    ProfilingStopHandler.profiler = profiler;
+  }
+
+  @Override
+  public void onNext(final StopTime stopTime) {
+    try (final PrintWriter out = new PrintWriter("profile-" + launchID + ".json")) {
+      out.print(profiler.objectGraphToString());
+    } catch (final FileNotFoundException e) {
+      LOG.log(Level.WARNING, "Unable to write the profile", e);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/REEFErrorHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/REEFErrorHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/REEFErrorHandler.java
new file mode 100644
index 0000000..544fcc6
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/REEFErrorHandler.java
@@ -0,0 +1,101 @@
+/**
+ * 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.reef.runtime.common.launch;
+
+import com.google.protobuf.ByteString;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.launch.parameters.ErrorHandlerRID;
+import org.apache.reef.runtime.common.launch.parameters.LaunchID;
+import org.apache.reef.runtime.common.utils.ExceptionCodec;
+import org.apache.reef.runtime.common.utils.RemoteManager;
+import org.apache.reef.tang.InjectionFuture;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+
+/**
+ * The error handler REEF registers with Wake.
+ */
+public final class REEFErrorHandler implements EventHandler<Throwable> {
+
+  private static final Logger LOG = Logger.getLogger(REEFErrorHandler.class.getName());
+
+  // This class is used as the ErrorHandler in the RemoteManager. Hence, we need an InjectionFuture here.
+  private final InjectionFuture<RemoteManager> remoteManager;
+  private final String launchID;
+  private final String errorHandlerRID;
+  private final ExceptionCodec exceptionCodec;
+
+  @Inject
+  REEFErrorHandler(final InjectionFuture<RemoteManager> remoteManager,
+                   final @Parameter(ErrorHandlerRID.class) String errorHandlerRID,
+                   final @Parameter(LaunchID.class) String launchID,
+                   final ExceptionCodec exceptionCodec) {
+    this.errorHandlerRID = errorHandlerRID;
+    this.remoteManager = remoteManager;
+    this.launchID = launchID;
+    this.exceptionCodec = exceptionCodec;
+  }
+
+  @Override
+  public void onNext(final Throwable e) {
+    LOG.log(Level.SEVERE, "Uncaught exception.", e);
+    // TODO: This gets a new EventHandler each time an exception is caught. It would be better to cache the handler. But
+    // that introduces threading issues and isn't really worth it, as the JVM typically will be killed once we catch an
+    // Exception in here.
+    if (!this.errorHandlerRID.equals(ErrorHandlerRID.NONE)) {
+      final EventHandler<ReefServiceProtos.RuntimeErrorProto> runtimeErrorHandler = this.remoteManager.get()
+          .getHandler(errorHandlerRID, ReefServiceProtos.RuntimeErrorProto.class);
+      final ReefServiceProtos.RuntimeErrorProto message = ReefServiceProtos.RuntimeErrorProto.newBuilder()
+          .setName("reef")
+          .setIdentifier(launchID)
+          .setMessage(e.getMessage())
+          .setException(ByteString.copyFrom(this.exceptionCodec.toBytes(e)))
+          .build();
+      try {
+        runtimeErrorHandler.onNext(message);
+      } catch (final Throwable t) {
+        LOG.log(Level.SEVERE, "Unable to send the error upstream", t);
+      }
+    } else {
+      LOG.log(Level.SEVERE, "Caught an exception from Wake we cannot send upstream because there is no upstream");
+    }
+  }
+
+  public void close() {
+    try {
+      this.remoteManager.get().close();
+    } catch (final Throwable ex) {
+      LOG.log(Level.SEVERE, "Unable to close the remote manager", ex);
+    }
+  }
+
+  @Override
+  public String toString() {
+    return "REEFErrorHandler{" +
+        "remoteManager=" + remoteManager +
+        ", launchID='" + launchID + '\'' +
+        ", errorHandlerRID='" + errorHandlerRID + '\'' +
+        '}';
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/REEFMessageCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/REEFMessageCodec.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/REEFMessageCodec.java
new file mode 100644
index 0000000..8a81184
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/REEFMessageCodec.java
@@ -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.
+ */
+package org.apache.reef.runtime.common.launch;
+
+import com.google.protobuf.GeneratedMessage;
+import com.google.protobuf.InvalidProtocolBufferException;
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.ClientRuntimeProtocol;
+import org.apache.reef.proto.EvaluatorRuntimeProtocol;
+import org.apache.reef.proto.REEFProtocol;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.wake.remote.Codec;
+
+import javax.inject.Inject;
+
+/**
+ * Codec for REEF's control flow messages.
+ */
+@Private
+@Provided
+@ClientSide
+@DriverSide
+@EvaluatorSide
+public final class REEFMessageCodec implements Codec<GeneratedMessage> {
+
+
+  @Inject
+  private REEFMessageCodec() {
+  }
+
+  @Override
+  public GeneratedMessage decode(final byte[] bytes) {
+    try {
+      final REEFProtocol.REEFMessage message = REEFProtocol.REEFMessage.parseFrom(bytes);
+      if (message.hasJobSubmission()) {
+        return message.getJobSubmission();
+      } else if (message.hasJobControl()) {
+        return message.getJobControl();
+      } else if (message.hasRuntimeError()) {
+        return message.getRuntimeError();
+      } else if (message.hasJobStatus()) {
+        return message.getJobStatus();
+      } else if (message.hasEvaluatorControl()) {
+        return message.getEvaluatorControl();
+      } else if (message.hasEvaluatorHeartBeat()) {
+        return message.getEvaluatorHeartBeat();
+      }
+      throw new RuntimeException("Unable to decode a message: " + message.toString());
+    } catch (final InvalidProtocolBufferException e) {
+      throw new RuntimeException("Unable to decode a message", e);
+    }
+  }
+
+  @Override
+  public byte[] encode(final GeneratedMessage msg) {
+    final REEFProtocol.REEFMessage.Builder message = REEFProtocol.REEFMessage.newBuilder();
+
+    if (msg instanceof ClientRuntimeProtocol.JobSubmissionProto) {
+      message.setJobSubmission((ClientRuntimeProtocol.JobSubmissionProto) msg);
+    } else if (msg instanceof ClientRuntimeProtocol.JobControlProto) {
+      message.setJobControl((ClientRuntimeProtocol.JobControlProto) msg);
+    } else if (msg instanceof ReefServiceProtos.RuntimeErrorProto) {
+      message.setRuntimeError((ReefServiceProtos.RuntimeErrorProto) msg);
+    } else if (msg instanceof ReefServiceProtos.JobStatusProto) {
+      message.setJobStatus((ReefServiceProtos.JobStatusProto) msg);
+    } else if (msg instanceof EvaluatorRuntimeProtocol.EvaluatorControlProto) {
+      message.setEvaluatorControl((EvaluatorRuntimeProtocol.EvaluatorControlProto) msg);
+    } else if (msg instanceof EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto) {
+      message.setEvaluatorHeartBeat((EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto) msg);
+    } else {
+      throw new RuntimeException("Unable to serialize: " + msg);
+    }
+
+    return message.build().toByteArray();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/REEFUncaughtExceptionHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/REEFUncaughtExceptionHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/REEFUncaughtExceptionHandler.java
new file mode 100644
index 0000000..5190f86
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/REEFUncaughtExceptionHandler.java
@@ -0,0 +1,67 @@
+/**
+ * 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.reef.runtime.common.launch;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This is used as the Exception handler for REEF client processes (Driver, Evaluator).
+ * <p/>
+ * It catches all exceptions and sends them to the controlling process.
+ * For Evaluators, that is the Driver. For the Driver, that is the Client.
+ * <p/>
+ * After sending the exception, this shuts down the JVM, as this JVM is then officially dead.
+ */
+final class REEFUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
+  private static final Logger LOG = Logger.getLogger(REEFUncaughtExceptionHandler.class.getName());
+  private final REEFErrorHandler errorHandler;
+
+
+  /**
+   * @param errorHandler
+   */
+  @Inject
+  REEFUncaughtExceptionHandler(final REEFErrorHandler errorHandler) {
+    this.errorHandler = errorHandler;
+  }
+
+  @Override
+  public final synchronized void uncaughtException(final Thread thread, final Throwable throwable) {
+    final String msg = "Thread " + thread.getName() + " threw an uncaught exception.";
+    LOG.log(Level.SEVERE, msg, throwable);
+    this.errorHandler.onNext(new Exception(msg, throwable));
+    try {
+      this.wait(100); // TODO: Remove
+    } catch (final InterruptedException e) {
+
+    }
+    this.errorHandler.close();
+    LOG.log(Level.SEVERE, "System.exit(1)");
+    System.exit(1);
+  }
+
+  @Override
+  public String toString() {
+    return "REEFUncaughtExceptionHandler{" +
+        "errorHandler=" + errorHandler +
+        '}';
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/package-info.java
new file mode 100644
index 0000000..fef18f4
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Common launch code between Driver and Evaluator.
+ */
+package org.apache.reef.runtime.common.launch;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/ClockConfigurationPath.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/ClockConfigurationPath.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/ClockConfigurationPath.java
new file mode 100644
index 0000000..3715774
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/ClockConfigurationPath.java
@@ -0,0 +1,30 @@
+/**
+ * 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.reef.runtime.common.launch.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The path to the clock configuration
+ */
+@NamedParameter(doc = "The path to process configuration.", short_name = ClockConfigurationPath.SHORT_NAME)
+public final class ClockConfigurationPath implements Name<String> {
+  public static final String SHORT_NAME = "runtime_configuration";
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/ErrorHandlerRID.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/ErrorHandlerRID.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/ErrorHandlerRID.java
new file mode 100644
index 0000000..0285ad0
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/ErrorHandlerRID.java
@@ -0,0 +1,37 @@
+/**
+ * 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.reef.runtime.common.launch.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+@NamedParameter(doc = "The error handler remote identifier.", short_name = ErrorHandlerRID.SHORT_NAME, default_value = ErrorHandlerRID.NONE)
+public final class ErrorHandlerRID implements Name<String> {
+  /**
+   * Indicates that no ErrorHandler is bound.
+   */
+  // TODO: Find all comparisons with this and see whether we can do something about them
+  public static final String NONE = "NO_ERROR_HANDLER_REMOTE_ID";
+
+  /**
+   * Short name for the command line and such.
+   */
+  public static final String SHORT_NAME = "error_handler_rid";
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/LaunchID.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/LaunchID.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/LaunchID.java
new file mode 100644
index 0000000..7dc8546
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/LaunchID.java
@@ -0,0 +1,27 @@
+/**
+ * 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.reef.runtime.common.launch.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+@NamedParameter(doc = "The launch identifier.", short_name = LaunchID.SHORT_NAME)
+public final class LaunchID implements Name<String> {
+  public static final String SHORT_NAME = "launch_id";
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/package-info.java
new file mode 100644
index 0000000..155c399
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/launch/parameters/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Parameters of the Launcher.
+ */
+package org.apache.reef.runtime.common.launch.parameters;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/package-info.java
new file mode 100644
index 0000000..57a7e54
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/package-info.java
@@ -0,0 +1,26 @@
+/**
+ * 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.
+ */
+/**
+ * REEF implementation.
+ * This is referred to as the `common resourcemanager` that contains code
+ * common to implementations of REEF on all resource managers.
+ * The individual resource managers are implemented by providing implementations
+ * of the various interfaces presribed in sub-packages called `API`.
+ */
+package org.apache.reef.runtime.common;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/parameters/DeleteTempFiles.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/parameters/DeleteTempFiles.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/parameters/DeleteTempFiles.java
new file mode 100644
index 0000000..891d890
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/parameters/DeleteTempFiles.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.runtime.common.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * Whether or not to delete the temporary files created during Driver and Evaluator submission.
+ */
+@NamedParameter(doc = "Whether or not to delete the temporary files created during Driver and Evaluator submission.", default_value = "true")
+public final class DeleteTempFiles implements Name<Boolean> {
+  private DeleteTempFiles() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/parameters/JVMHeapSlack.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/parameters/JVMHeapSlack.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/parameters/JVMHeapSlack.java
new file mode 100644
index 0000000..3caa66b
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/parameters/JVMHeapSlack.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.runtime.common.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The fraction of the container memory NOT to use for the Java Heap.
+ */
+@NamedParameter(doc = "The fraction of the container memory NOT to use for the Java Heap.", default_value = "0.0")
+public final class JVMHeapSlack implements Name<Double> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/BroadCastEventHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/BroadCastEventHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/BroadCastEventHandler.java
new file mode 100644
index 0000000..49fe345
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/BroadCastEventHandler.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.runtime.common.utils;
+
+import org.apache.reef.wake.EventHandler;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+public class BroadCastEventHandler<E> implements EventHandler<E> {
+  private final List<EventHandler<E>> handlers;
+
+  public BroadCastEventHandler(final Collection<EventHandler<E>> handlers) {
+    this.handlers = new ArrayList<>(handlers);
+  }
+
+  @Override
+  public void onNext(final E event) {
+    for (final EventHandler<E> handler : handlers)
+      handler.onNext(event);
+  }
+
+  public void addEventHandler(final EventHandler<E> eventHandler) {
+    this.handlers.add(eventHandler);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/DefaultExceptionCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/DefaultExceptionCodec.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/DefaultExceptionCodec.java
new file mode 100644
index 0000000..1a80f96
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/DefaultExceptionCodec.java
@@ -0,0 +1,64 @@
+/**
+ * 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.reef.runtime.common.utils;
+
+import org.apache.commons.lang.SerializationException;
+import org.apache.commons.lang.SerializationUtils;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.util.Optional;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default implementation of ExceptionCodec that uses Java serialization as its implementation.
+ */
+@Private
+final class DefaultExceptionCodec implements ExceptionCodec {
+  private static final Logger LOG = Logger.getLogger(DefaultExceptionCodec.class.getName());
+
+  @Inject
+  DefaultExceptionCodec() {
+  }
+
+  @Override
+  public Optional<Throwable> fromBytes(final byte[] bytes) {
+    try {
+      return Optional.<Throwable>of((Throwable) SerializationUtils.deserialize(bytes));
+    } catch (SerializationException | IllegalArgumentException e) {
+      LOG.log(Level.FINE, "Unable to deserialize a Throwable.", e);
+      return Optional.empty();
+    }
+  }
+
+  @Override
+  public Optional<Throwable> fromBytes(final Optional<byte[]> bytes) {
+    if (bytes.isPresent()) {
+      return this.fromBytes(bytes.get());
+    } else {
+      return Optional.empty();
+    }
+  }
+
+  @Override
+  public byte[] toBytes(final Throwable throwable) {
+    return SerializationUtils.serialize(throwable);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/DispatchingEStage.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/DispatchingEStage.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/DispatchingEStage.java
new file mode 100644
index 0000000..64c32e8
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/DispatchingEStage.java
@@ -0,0 +1,143 @@
+/**
+ * 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.reef.runtime.common.utils;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.tang.util.MonotonicHashMap;
+import org.apache.reef.util.ExceptionHandlingEventHandler;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.impl.ThreadPoolStage;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Delayed event router that dispatches messages to the proper event handler by type.
+ * This class is used in EvaluatorManager to isolate user threads from REEF.
+ */
+@Private
+@DriverSide
+public final class DispatchingEStage implements AutoCloseable {
+
+  /**
+   * A map of event handlers, populated in the register() method.
+   */
+  private final Map<Class<?>, EventHandler<?>> handlers =
+      Collections.synchronizedMap(new MonotonicHashMap<Class<?>, EventHandler<?>>());
+  /**
+   * Exception handler, one for all event handlers.
+   */
+  private final EventHandler<Throwable> errorHandler;
+  /**
+   * Thread pool to process delayed event handler invocations.
+   */
+  private final ThreadPoolStage<DelayedOnNext> stage;
+
+  /**
+   * @param errorHandler used for exceptions thrown from the event handlers registered.
+   * @param numThreads   number of threads to allocate to dispatch events.
+   * @param stageName    the name to use for the underlying stage. It will be carried over to name the Thread(s) spawned.
+   */
+  public DispatchingEStage(final EventHandler<Throwable> errorHandler,
+                           final int numThreads,
+                           final String stageName) {
+    this.errorHandler = errorHandler;
+    this.stage = new ThreadPoolStage<>(stageName,
+        new EventHandler<DelayedOnNext>() {
+          @Override
+          public void onNext(final DelayedOnNext promise) {
+            promise.handler.onNext(promise.message);
+          }
+        }, numThreads
+    );
+
+  }
+
+  /**
+   * Constructs a DispatchingEStage that uses the Thread pool and ErrorHandler of another one.
+   *
+   * @param other
+   */
+  public DispatchingEStage(final DispatchingEStage other) {
+    this.errorHandler = other.errorHandler;
+    this.stage = other.stage;
+  }
+
+  /**
+   * Register a new event handler.
+   *
+   * @param type     Message type to process with this handler.
+   * @param handlers A set of handlers that process that type of message.
+   * @param <T>      Message type.
+   * @param <U>      Type of message that event handler supports. Must be a subclass of T.
+   */
+  public <T, U extends T> void register(final Class<T> type, final Set<EventHandler<U>> handlers) {
+    this.handlers.put(type, new ExceptionHandlingEventHandler<>(
+        new BroadCastEventHandler<>(handlers), this.errorHandler));
+  }
+
+  /**
+   * Dispatch a new message by type.
+   *
+   * @param type    Type of event handler - must match the register() call.
+   * @param message A message to process. Must be a subclass of T.
+   * @param <T>     Message type that event handler supports.
+   * @param <U>     input message type. Must be a subclass of T.
+   */
+  @SuppressWarnings("unchecked")
+  public <T, U extends T> void onNext(final Class<T> type, final U message) {
+    final EventHandler<T> handler = (EventHandler<T>) this.handlers.get(type);
+    this.stage.onNext(new DelayedOnNext(handler, message));
+  }
+
+  /**
+   * Return true if there are no messages queued or in processing, false otherwise.
+   */
+  public boolean isEmpty() {
+    return this.stage.getQueueLength() == 0;
+  }
+
+  /**
+   * Close the internal thread pool.
+   *
+   * @throws Exception forwarded from EStage.close() call.
+   */
+  @Override
+  public void close() throws Exception {
+    this.stage.close();
+  }
+
+  /**
+   * Delayed EventHandler.onNext() call.
+   * Contains a message object and EventHandler to process it.
+   */
+  private static final class DelayedOnNext {
+
+    public final EventHandler<Object> handler;
+    public final Object message;
+
+    @SuppressWarnings("unchecked")
+    public <T, U extends T> DelayedOnNext(final EventHandler<T> handler, final U message) {
+      this.handler = (EventHandler<Object>) handler;
+      this.message = message;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/ExceptionCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/ExceptionCodec.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/ExceptionCodec.java
new file mode 100644
index 0000000..37fa264
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/ExceptionCodec.java
@@ -0,0 +1,50 @@
+/**
+ * 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.reef.runtime.common.utils;
+
+import org.apache.reef.tang.annotations.DefaultImplementation;
+import org.apache.reef.util.Optional;
+
+/**
+ * (De-)serializes exceptions.
+ */
+@DefaultImplementation(DefaultExceptionCodec.class)
+public interface ExceptionCodec {
+
+  /**
+   * Deserializes a Throwable that has been serialized using toBytes().
+   *
+   * @param bytes
+   * @return the Throable or Optional.empty() if the deserialization fails.
+   */
+  public Optional<Throwable> fromBytes(final byte[] bytes);
+
+  /**
+   * @param bytes
+   * @return fromBytes(bytes.get()) or Optional.empty()
+   */
+  public Optional<Throwable> fromBytes(final Optional<byte[]> bytes);
+
+  /**
+   * @param throwable
+   * @return the serialized form of the given Throwable.
+   */
+  public byte[] toBytes(final Throwable throwable);
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/RemoteManager.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/RemoteManager.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/RemoteManager.java
new file mode 100644
index 0000000..e17108e
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/utils/RemoteManager.java
@@ -0,0 +1,76 @@
+/**
+ * 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.reef.runtime.common.utils;
+
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.RemoteIdentifierFactory;
+import org.apache.reef.wake.remote.RemoteMessage;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class RemoteManager {
+
+  private static final Logger LOG = Logger.getLogger(RemoteManager.class.getName());
+
+  private final org.apache.reef.wake.remote.RemoteManager raw;
+  private final RemoteIdentifierFactory factory;
+
+  @Inject
+  public RemoteManager(final org.apache.reef.wake.remote.RemoteManager raw,
+                       final RemoteIdentifierFactory factory) {
+    this.raw = raw;
+    this.factory = factory;
+    LOG.log(Level.FINE, "Instantiated 'RemoteManager' with remoteId: {0}", this.getMyIdentifier());
+  }
+
+  public final org.apache.reef.wake.remote.RemoteManager raw() {
+    return this.raw;
+  }
+
+  public void close() throws Exception {
+    this.raw.close();
+  }
+
+  public <T> EventHandler<T> getHandler(
+      final String destinationIdentifier, final Class<? extends T> messageType) {
+    return this.raw.getHandler(factory.getNewInstance(destinationIdentifier), messageType);
+  }
+
+  public <T, U extends T> AutoCloseable registerHandler(
+      final String sourceIdentifier, final Class<U> messageType,
+      final EventHandler<T> theHandler) {
+    return this.raw.registerHandler(factory.getNewInstance(sourceIdentifier), messageType, theHandler);
+  }
+
+  public <T, U extends T> AutoCloseable registerHandler(
+      final Class<U> messageType, final EventHandler<RemoteMessage<T>> theHandler) {
+    return this.raw.registerHandler(messageType, theHandler);
+  }
+
+  public AutoCloseable registerErrorHandler(final EventHandler<Exception> theHandler) {
+    return this.raw.registerErrorHandler(theHandler);
+  }
+
+  public String getMyIdentifier() {
+    return this.raw.getMyIdentifier().toString();
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/task/HeartBeatTriggerManager.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/task/HeartBeatTriggerManager.java b/lang/java/reef-common/src/main/java/org/apache/reef/task/HeartBeatTriggerManager.java
new file mode 100644
index 0000000..7137420
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/task/HeartBeatTriggerManager.java
@@ -0,0 +1,53 @@
+/**
+ * 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.reef.task;
+
+import org.apache.reef.annotations.Unstable;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.annotations.audience.TaskSide;
+import org.apache.reef.runtime.common.evaluator.HeartBeatManager;
+
+import javax.inject.Inject;
+
+/**
+ * Helper class for immediately sending heartbeat messages.
+ * This can be used together with TaskMessageSource to push urgent messages to the Driver.
+ * <p/>
+ * CAUTION: Do not overuse as the Driver can be saturated with heartbeats.
+ *
+ * @see https://issues.apache.org/jira/browse/REEF-33 for the ongoing discussion of alternatives to this design.
+ */
+@TaskSide
+@Public
+@Unstable
+public class HeartBeatTriggerManager {
+  private final HeartBeatManager heartBeatManager;
+
+  @Inject
+  HeartBeatTriggerManager(final HeartBeatManager heartBeatManager) {
+    this.heartBeatManager = heartBeatManager;
+  }
+
+  /**
+   * Immediately send a heartbeat message to the Driver.
+   */
+  public void triggerHeartBeat() {
+    this.heartBeatManager.sendHeartbeat();
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/task/Task.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/task/Task.java b/lang/java/reef-common/src/main/java/org/apache/reef/task/Task.java
new file mode 100644
index 0000000..b042558
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/task/Task.java
@@ -0,0 +1,48 @@
+/**
+ * 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.reef.task;
+
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.annotations.audience.TaskSide;
+
+import java.util.concurrent.Callable;
+
+/**
+ * The interface for Tasks.
+ * <p/>
+ * This interface is to be implemented for Tasks.
+ * <p/>
+ * The main entry point for a Task is the call() method inherited from
+ * {@link Callable}. The REEF Evaluator will call this method in order to run
+ * the Task. The byte[] returned by it will be pushed to the Job Driver.
+ */
+@TaskSide
+@Public
+public interface Task {
+
+  /**
+   * Called by the resourcemanager harness to execute the task.
+   *
+   * @param memento the memento objected passed down by the driver.
+   * @return the user defined return value
+   * @throws Exception whenever the Task encounters an unsolved issue.
+   *                   This Exception will be thrown at the Driver's event handler.
+   */
+  public byte[] call(final byte[] memento) throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/task/TaskMessage.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/task/TaskMessage.java b/lang/java/reef-common/src/main/java/org/apache/reef/task/TaskMessage.java
new file mode 100644
index 0000000..60c8c33
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/task/TaskMessage.java
@@ -0,0 +1,67 @@
+/**
+ * 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.reef.task;
+
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.io.Message;
+
+/**
+ * A message sent from a Task to a Driver.
+ */
+@EvaluatorSide
+@Public
+@Provided
+public final class TaskMessage implements Message {
+
+  private final String messageSourceID;
+  private final byte[] theBytes;
+
+  private TaskMessage(final String messageSourceID, final byte[] theBytes) {
+    this.messageSourceID = messageSourceID;
+    this.theBytes = theBytes;
+  }
+
+  /**
+   * @param messageSourceID The message's sourceID. This will be accessible in the Driver for routing.
+   * @param theBytes        The actual content of the message, serialized into a byte[]
+   * @return a new TaskMessage with the given content.
+   */
+  public static TaskMessage from(final String messageSourceID, final byte[] theBytes) {
+    assert (theBytes != null && messageSourceID != null);
+    return new TaskMessage(messageSourceID, theBytes);
+  }
+
+  /**
+   * @return the message source identifier.
+   */
+  public String getMessageSourceID() {
+    return this.messageSourceID;
+  }
+
+  /**
+   * @return the message
+   */
+  @Override
+  public byte[] get() {
+    return this.theBytes;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/task/TaskMessageSource.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/task/TaskMessageSource.java b/lang/java/reef-common/src/main/java/org/apache/reef/task/TaskMessageSource.java
new file mode 100644
index 0000000..38077e0
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/task/TaskMessageSource.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.task;
+
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.util.Optional;
+
+/**
+ * Message source for control flow messages from a task to the Driver.
+ * <p/>
+ * The getMessage() method in an Implementation of this interface will be called by the Evaluator resourcemanager whenever it is
+ * about to communicate with the Driver anyway. Hence, this can be used for occasional status updates etc.
+ */
+@Public
+@EvaluatorSide
+public interface TaskMessageSource {
+
+  /**
+   * @return a message to be sent back to the Driver, or Optional.empty() if no message shall be sent at this time.
+   */
+  public Optional<TaskMessage> getMessage();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/task/events/CloseEvent.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/task/events/CloseEvent.java b/lang/java/reef-common/src/main/java/org/apache/reef/task/events/CloseEvent.java
new file mode 100644
index 0000000..106bc5f
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/task/events/CloseEvent.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.task.events;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.annotations.audience.TaskSide;
+import org.apache.reef.util.Optional;
+
+/**
+ * Indicates that the driver called .close() on this Task.
+ */
+@TaskSide
+@Provided
+@Public
+public interface CloseEvent {
+
+  /**
+   * @return the message sent with the close call, if any.
+   */
+  public Optional<byte[]> get();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/task/events/DriverMessage.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/task/events/DriverMessage.java b/lang/java/reef-common/src/main/java/org/apache/reef/task/events/DriverMessage.java
new file mode 100644
index 0000000..dbfe025
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/task/events/DriverMessage.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.task.events;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.annotations.audience.TaskSide;
+import org.apache.reef.util.Optional;
+
+/**
+ * Represents a message sent by the driver.
+ */
+@TaskSide
+@Public
+@Provided
+public interface DriverMessage {
+
+  /**
+   * @return the message sent by the driver.
+   */
+  public Optional<byte[]> get();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/task/events/SuspendEvent.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/task/events/SuspendEvent.java b/lang/java/reef-common/src/main/java/org/apache/reef/task/events/SuspendEvent.java
new file mode 100644
index 0000000..f23f3bf
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/task/events/SuspendEvent.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.task.events;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.annotations.audience.TaskSide;
+import org.apache.reef.util.Optional;
+
+/**
+ * Event fired when the driver called suspend() on this task.
+ */
+@TaskSide
+@Provided
+@Public
+public interface SuspendEvent {
+
+  /**
+   * @return the message sent with the suspend call, if any.
+   */
+  public Optional<byte[]> get();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/task/events/TaskStart.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/task/events/TaskStart.java b/lang/java/reef-common/src/main/java/org/apache/reef/task/events/TaskStart.java
new file mode 100644
index 0000000..1a7a38b
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/task/events/TaskStart.java
@@ -0,0 +1,37 @@
+/**
+ * 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.reef.task.events;
+
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.io.naming.Identifiable;
+
+/**
+ * Represents a TaskStart. Fired right before Task.call() is invoked.
+ */
+@EvaluatorSide
+@Public
+public interface TaskStart extends Identifiable {
+
+  /**
+   * @return task identifier.
+   */
+  @Override
+  String getId();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/task/events/TaskStop.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/task/events/TaskStop.java b/lang/java/reef-common/src/main/java/org/apache/reef/task/events/TaskStop.java
new file mode 100644
index 0000000..3a77dbb
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/task/events/TaskStop.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.task.events;
+
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.io.naming.Identifiable;
+
+/**
+ * Represents a Task stop. Fired right after Task.call() returned.
+ */
+@EvaluatorSide
+@Public
+public interface TaskStop extends Identifiable {
+
+  /**
+   * @return the task identifier
+   */
+  public String getId();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/Builder.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/Builder.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/Builder.java
new file mode 100644
index 0000000..3cd0db1
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/Builder.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.util;
+
+/**
+ * A basic Builder pattern interface.
+ *
+ * @param <T> The type of object to be built.
+ */
+public interface Builder<T> {
+
+  /**
+   * Builds a fresh instance of the object. This can be invoked several times,
+   * each of which return a new instance.
+   *
+   * @return a fresh instance of the object.
+   */
+  public T build();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/CommandUtils.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/CommandUtils.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/CommandUtils.java
new file mode 100644
index 0000000..146a161
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/CommandUtils.java
@@ -0,0 +1,55 @@
+/**
+ * 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.reef.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * run given command and return the result as string
+ */
+final public class CommandUtils {
+  /**
+   * Standard java logger.
+   */
+  private static final Logger LOG = Logger.getLogger(CommandUtils.class.getName());
+
+  public final static String runCommand(final String command) {
+    final StringBuilder sb = new StringBuilder();
+    try {
+      final String cmd = OSUtils.isWindows() ? "cmd.exe /c " + command : command;
+      final Process proc = Runtime.getRuntime().exec(cmd);
+
+      try (final BufferedReader input =
+               new BufferedReader(new InputStreamReader(proc.getInputStream()))) {
+        String line;
+        while ((line = input.readLine()) != null) {
+          sb.append(line).append('\n');
+        }
+      }
+    } catch (final IOException ex) {
+      LOG.log(Level.SEVERE, "Error in call: " + command, ex);
+      sb.append(ex);
+    }
+    return sb.toString();
+  }
+}


[40/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverExceptionHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverExceptionHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverExceptionHandler.java
new file mode 100644
index 0000000..d145246
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverExceptionHandler.java
@@ -0,0 +1,53 @@
+/**
+ * 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.reef.runtime.common.driver;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Exception handler for exceptions thrown by client code in the Driver.
+ * It uses the JobMessageObserverImpl to send an update to the client and die.
+ */
+@Private
+@DriverSide
+public final class DriverExceptionHandler implements EventHandler<Throwable> {
+  private static final Logger LOG = Logger.getLogger(DriverExceptionHandler.class.getName());
+  /**
+   * We delegate the failures to this object.
+   */
+  private final DriverStatusManager driverStatusManager;
+
+  @Inject
+  public DriverExceptionHandler(final DriverStatusManager driverStatusManager) {
+    this.driverStatusManager = driverStatusManager;
+    LOG.log(Level.FINE, "Instantiated 'DriverExceptionHandler'");
+  }
+
+
+  @Override
+  public void onNext(final Throwable throwable) {
+    this.driverStatusManager.onError(throwable);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverRuntimeConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverRuntimeConfiguration.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverRuntimeConfiguration.java
new file mode 100644
index 0000000..a2e4078
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverRuntimeConfiguration.java
@@ -0,0 +1,73 @@
+/**
+ * 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.reef.runtime.common.driver;
+
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.catalog.ResourceCatalog;
+import org.apache.reef.driver.client.JobMessageObserver;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.driver.parameters.DriverIdleSources;
+import org.apache.reef.runtime.common.driver.api.RuntimeParameters;
+import org.apache.reef.runtime.common.driver.catalog.ResourceCatalogImpl;
+import org.apache.reef.runtime.common.driver.client.ClientManager;
+import org.apache.reef.runtime.common.driver.client.JobMessageObserverImpl;
+import org.apache.reef.runtime.common.driver.idle.ClockIdlenessSource;
+import org.apache.reef.runtime.common.driver.idle.EventHandlerIdlenessSource;
+import org.apache.reef.runtime.common.driver.resourcemanager.NodeDescriptorHandler;
+import org.apache.reef.runtime.common.driver.resourcemanager.ResourceAllocationHandler;
+import org.apache.reef.runtime.common.driver.resourcemanager.ResourceManagerStatus;
+import org.apache.reef.runtime.common.driver.resourcemanager.ResourceStatusHandler;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.wake.time.Clock;
+
+@Private
+@ClientSide
+public final class DriverRuntimeConfiguration extends ConfigurationModuleBuilder {
+
+  public static final ConfigurationModule CONF = new DriverRuntimeConfiguration()
+      // Resource Catalog
+      .bindImplementation(ResourceCatalog.class, ResourceCatalogImpl.class)
+
+          // JobMessageObserver
+      .bindImplementation(EvaluatorRequestor.class, EvaluatorRequestorImpl.class) // requesting evaluators
+      .bindImplementation(JobMessageObserver.class, JobMessageObserverImpl.class) // sending message to job client
+
+          // Client manager
+      .bindNamedParameter(DriverRuntimeConfigurationOptions.JobControlHandler.class, ClientManager.class)
+
+          // Bind the resourcemanager parameters
+      .bindNamedParameter(RuntimeParameters.NodeDescriptorHandler.class, NodeDescriptorHandler.class)
+      .bindNamedParameter(RuntimeParameters.ResourceAllocationHandler.class, ResourceAllocationHandler.class)
+      .bindNamedParameter(RuntimeParameters.ResourceStatusHandler.class, ResourceStatusHandler.class)
+      .bindNamedParameter(RuntimeParameters.RuntimeStatusHandler.class, ResourceManagerStatus.class)
+
+          // Bind to the Clock
+      .bindSetEntry(Clock.RuntimeStartHandler.class, DriverRuntimeStartHandler.class)
+      .bindSetEntry(Clock.RuntimeStopHandler.class, DriverRuntimeStopHandler.class)
+
+          // Bind the idle handlers
+      .bindSetEntry(DriverIdleSources.class, ClockIdlenessSource.class)
+      .bindSetEntry(DriverIdleSources.class, EventHandlerIdlenessSource.class)
+      .bindSetEntry(DriverIdleSources.class, ResourceManagerStatus.class)
+      .bindSetEntry(Clock.IdleHandler.class, ClockIdlenessSource.class)
+
+      .build();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverRuntimeConfigurationOptions.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverRuntimeConfigurationOptions.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverRuntimeConfigurationOptions.java
new file mode 100644
index 0000000..ae26f8e
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverRuntimeConfigurationOptions.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.runtime.common.driver;
+
+import org.apache.reef.proto.ClientRuntimeProtocol;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ * Houses the Driver resourcemanager configuration's NamedParameters
+ */
+public class DriverRuntimeConfigurationOptions {
+  @NamedParameter(doc = "Called when a job control message is received by the client.")
+  public final static class JobControlHandler implements Name<EventHandler<ClientRuntimeProtocol.JobControlProto>> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverRuntimeStartHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverRuntimeStartHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverRuntimeStartHandler.java
new file mode 100644
index 0000000..114981b
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverRuntimeStartHandler.java
@@ -0,0 +1,80 @@
+/**
+ * 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.reef.runtime.common.driver;
+
+import org.apache.reef.proto.EvaluatorRuntimeProtocol;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.driver.evaluator.EvaluatorHeartbeatHandler;
+import org.apache.reef.runtime.common.driver.evaluator.EvaluatorResourceManagerErrorHandler;
+import org.apache.reef.runtime.common.driver.resourcemanager.ResourceManagerStatus;
+import org.apache.reef.runtime.common.utils.RemoteManager;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.runtime.event.RuntimeStart;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The RuntimeStart handler of the Driver.
+ * <p/>
+ * This instantiates the DriverSingletons upon construction. Upon onNext(), it sets the resource manager status and
+ * wires up the remote event handler connections to the client and the evaluators.
+ */
+final class DriverRuntimeStartHandler implements EventHandler<RuntimeStart> {
+  private static final Logger LOG = Logger.getLogger(DriverRuntimeStartHandler.class.getName());
+  private final RemoteManager remoteManager;
+  private final EvaluatorResourceManagerErrorHandler evaluatorResourceManagerErrorHandler;
+  private final EvaluatorHeartbeatHandler evaluatorHeartbeatHandler;
+  private final ResourceManagerStatus resourceManagerStatus;
+  private final DriverStatusManager driverStatusManager;
+
+  /**
+   * @param singletons                           the objects we want to be Singletons in the Driver
+   * @param remoteManager                        the remoteManager in the Driver.
+   * @param evaluatorResourceManagerErrorHandler This will be wired up to the remoteManager on onNext()
+   * @param evaluatorHeartbeatHandler            This will be wired up to the remoteManager on onNext()
+   * @param resourceManagerStatus                will be set to RUNNING in onNext()
+   * @param driverStatusManager                  will be set to RUNNING in onNext()
+   */
+  @Inject
+  DriverRuntimeStartHandler(final DriverSingletons singletons,
+                            final RemoteManager remoteManager,
+                            final EvaluatorResourceManagerErrorHandler evaluatorResourceManagerErrorHandler,
+                            final EvaluatorHeartbeatHandler evaluatorHeartbeatHandler,
+                            final ResourceManagerStatus resourceManagerStatus,
+                            final DriverStatusManager driverStatusManager) {
+    this.remoteManager = remoteManager;
+    this.evaluatorResourceManagerErrorHandler = evaluatorResourceManagerErrorHandler;
+    this.evaluatorHeartbeatHandler = evaluatorHeartbeatHandler;
+    this.resourceManagerStatus = resourceManagerStatus;
+    this.driverStatusManager = driverStatusManager;
+  }
+
+  @Override
+  public synchronized void onNext(final RuntimeStart runtimeStart) {
+    LOG.log(Level.FINEST, "RuntimeStart: {0}", runtimeStart);
+
+    this.remoteManager.registerHandler(EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto.class, evaluatorHeartbeatHandler);
+    this.remoteManager.registerHandler(ReefServiceProtos.RuntimeErrorProto.class, evaluatorResourceManagerErrorHandler);
+    this.resourceManagerStatus.setRunning();
+    this.driverStatusManager.onRunning();
+    LOG.log(Level.FINEST, "DriverRuntimeStartHandler complete.");
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverRuntimeStopHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverRuntimeStopHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverRuntimeStopHandler.java
new file mode 100644
index 0000000..70b1f97
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverRuntimeStopHandler.java
@@ -0,0 +1,71 @@
+/**
+ * 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.reef.runtime.common.driver;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.runtime.common.driver.evaluator.Evaluators;
+import org.apache.reef.runtime.common.utils.RemoteManager;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.runtime.event.RuntimeStop;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Handler for the RuntimeStop event in the Driver. It shuts down the  evaluators and the RemoteManager and
+ * informs the Client.
+ */
+@Private
+@DriverSide
+final class DriverRuntimeStopHandler implements EventHandler<RuntimeStop> {
+  private static final Logger LOG = Logger.getLogger(DriverRuntimeStopHandler.class.getName());
+
+  private final DriverStatusManager driverStatusManager;
+  private final RemoteManager remoteManager;
+  private final Evaluators evaluators;
+
+  @Inject
+  DriverRuntimeStopHandler(final DriverStatusManager driverStatusManager,
+                           final RemoteManager remoteManager,
+                           final Evaluators evaluators) {
+    this.driverStatusManager = driverStatusManager;
+    this.remoteManager = remoteManager;
+    this.evaluators = evaluators;
+  }
+
+  @Override
+  public synchronized void onNext(final RuntimeStop runtimeStop) {
+    LOG.log(Level.FINEST, "RuntimeStop: {0}", runtimeStop);
+    // Shutdown the Evaluators.
+    this.evaluators.close();
+    // Inform the client of the shutdown.
+    final Optional<Throwable> exception = Optional.<Throwable>ofNullable(runtimeStop.getException());
+    this.driverStatusManager.sendJobEndingMessageToClient(exception);
+    // Close the remoteManager.
+    try {
+      this.remoteManager.close();
+      LOG.log(Level.INFO, "Driver shutdown complete");
+    } catch (final Exception e) {
+      throw new RuntimeException("Unable to close the RemoteManager.", e);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverSingleton.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverSingleton.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverSingleton.java
new file mode 100644
index 0000000..51da6c0
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverSingleton.java
@@ -0,0 +1,18 @@
+/**
+ * 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.
+ */

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverSingletons.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverSingletons.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverSingletons.java
new file mode 100644
index 0000000..6ab42e9
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverSingletons.java
@@ -0,0 +1,90 @@
+/**
+ * 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.reef.runtime.common.driver;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ClosedContext;
+import org.apache.reef.driver.context.ContextMessage;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.CompletedEvaluator;
+import org.apache.reef.driver.evaluator.FailedEvaluator;
+import org.apache.reef.driver.parameters.*;
+import org.apache.reef.driver.task.*;
+import org.apache.reef.proto.ClientRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.api.ResourceLaunchHandler;
+import org.apache.reef.runtime.common.driver.api.ResourceReleaseHandler;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.Set;
+
+/**
+ * A class that depends on all objects we want to enforce to be singletons in the Driver.
+ * The DriverRuntimeStartHandler depends on an instance of this class, which instantiates its dependencies.
+ */
+@DriverSide
+@Private
+final class DriverSingletons {
+  @Inject
+  DriverSingletons(
+      // Application event handlers
+      final @Parameter(ContextActiveHandlers.class) Set<EventHandler<ActiveContext>> contextActiveEventHandlers,
+      final @Parameter(ContextClosedHandlers.class) Set<EventHandler<ClosedContext>> contextClosedEventHandlers,
+      final @Parameter(ContextFailedHandlers.class) Set<EventHandler<FailedContext>> contextFailedEventHandlers,
+      final @Parameter(ContextMessageHandlers.class) Set<EventHandler<ContextMessage>> contextMessageHandlers,
+      final @Parameter(TaskRunningHandlers.class) Set<EventHandler<RunningTask>> taskRunningEventHandlers,
+      final @Parameter(TaskCompletedHandlers.class) Set<EventHandler<CompletedTask>> taskCompletedEventHandlers,
+      final @Parameter(TaskSuspendedHandlers.class) Set<EventHandler<SuspendedTask>> taskSuspendedEventHandlers,
+      final @Parameter(TaskMessageHandlers.class) Set<EventHandler<TaskMessage>> taskMessageEventHandlers,
+      final @Parameter(TaskFailedHandlers.class) Set<EventHandler<FailedTask>> taskExceptionEventHandlers,
+      final @Parameter(EvaluatorAllocatedHandlers.class) Set<EventHandler<AllocatedEvaluator>> evaluatorAllocatedEventHandlers,
+      final @Parameter(EvaluatorFailedHandlers.class) Set<EventHandler<FailedEvaluator>> evaluatorFailedHandlers,
+      final @Parameter(EvaluatorCompletedHandlers.class) Set<EventHandler<CompletedEvaluator>> evaluatorCompletedHandlers,
+
+      // Service event handlers
+      final @Parameter(ServiceContextActiveHandlers.class) Set<EventHandler<ActiveContext>> serviceContextActiveEventHandlers,
+      final @Parameter(ServiceContextClosedHandlers.class) Set<EventHandler<ClosedContext>> serviceContextClosedEventHandlers,
+      final @Parameter(ServiceContextFailedHandlers.class) Set<EventHandler<FailedContext>> serviceContextFailedEventHandlers,
+      final @Parameter(ServiceContextMessageHandlers.class) Set<EventHandler<ContextMessage>> serviceContextMessageHandlers,
+      final @Parameter(ServiceTaskRunningHandlers.class) Set<EventHandler<RunningTask>> serviceTaskRunningEventHandlers,
+      final @Parameter(ServiceTaskCompletedHandlers.class) Set<EventHandler<CompletedTask>> serviceTaskCompletedEventHandlers,
+      final @Parameter(ServiceTaskSuspendedHandlers.class) Set<EventHandler<SuspendedTask>> serviceTaskSuspendedEventHandlers,
+      final @Parameter(ServiceTaskMessageHandlers.class) Set<EventHandler<TaskMessage>> serviceTaskMessageEventHandlers,
+      final @Parameter(ServiceTaskFailedHandlers.class) Set<EventHandler<FailedTask>> serviceTaskExceptionEventHandlers,
+      final @Parameter(ServiceEvaluatorAllocatedHandlers.class) Set<EventHandler<AllocatedEvaluator>> serviceEvaluatorAllocatedEventHandlers,
+      final @Parameter(ServiceEvaluatorFailedHandlers.class) Set<EventHandler<FailedEvaluator>> serviceEvaluatorFailedHandlers,
+      final @Parameter(ServiceEvaluatorCompletedHandlers.class) Set<EventHandler<CompletedEvaluator>> serviceEvaluatorCompletedHandlers,
+
+      // Client event handler
+      final @Parameter(DriverRuntimeConfigurationOptions.JobControlHandler.class) EventHandler<ClientRuntimeProtocol.JobControlProto> jobControlHandler,
+
+      // Resource*Handlers - Should be invoked once
+      // The YarnResourceLaunchHandler creates and uploads
+      // the global jar file. If these handlers are
+      // instantiated for each container allocation
+      // we get container failures dure to modifications
+      // to already submitted global jar file
+      final ResourceLaunchHandler resourceLaunchHandler,
+      final ResourceReleaseHandler resourceReleaseHandler) {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverStartHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverStartHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverStartHandler.java
new file mode 100644
index 0000000..a2f8f6f
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverStartHandler.java
@@ -0,0 +1,93 @@
+/**
+ * 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.reef.runtime.common.driver;
+
+import org.apache.reef.driver.parameters.DriverRestartHandler;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This is bound to the start event of the clock and dispatches it to the approriate application code.
+ */
+public final class DriverStartHandler implements EventHandler<StartTime> {
+  private static final Logger LOG = Logger.getLogger(DriverStartHandler.class.getName());
+
+  private final Set<EventHandler<StartTime>> startHandlers;
+  private final Optional<EventHandler<StartTime>> restartHandler;
+  private final DriverStatusManager driverStatusManager;
+
+  @Inject
+  DriverStartHandler(final @Parameter(org.apache.reef.driver.parameters.DriverStartHandler.class) Set<EventHandler<StartTime>> startHandler,
+                     final @Parameter(DriverRestartHandler.class) EventHandler<StartTime> restartHandler,
+                     final DriverStatusManager driverStatusManager) {
+    this.startHandlers = startHandler;
+    this.restartHandler = Optional.of(restartHandler);
+    this.driverStatusManager = driverStatusManager;
+    LOG.log(Level.FINE, "Instantiated `DriverStartHandler with StartHandler [{0}] and RestartHandler [{1}]",
+        new String[]{this.startHandlers.toString(), this.restartHandler.toString()});
+  }
+
+  @Inject
+  DriverStartHandler(final @Parameter(org.apache.reef.driver.parameters.DriverStartHandler.class) Set<EventHandler<StartTime>> startHandler,
+                     final DriverStatusManager driverStatusManager) {
+    this.startHandlers = startHandler;
+    this.restartHandler = Optional.empty();
+    this.driverStatusManager = driverStatusManager;
+    LOG.log(Level.FINE, "Instantiated `DriverStartHandler with StartHandler [{0}] and no RestartHandler",
+        this.startHandlers.toString());
+  }
+
+  @Override
+  public void onNext(final StartTime startTime) {
+    if (isRestart()) {
+      this.onRestart(startTime);
+    } else {
+      this.onStart(startTime);
+    }
+  }
+
+  private void onRestart(final StartTime startTime) {
+    if (restartHandler.isPresent()) {
+      this.restartHandler.get().onNext(startTime);
+    } else {
+      // TODO: We might have to indicate this to YARN somehow such that it doesn't try another time.
+      throw new RuntimeException("Driver restart happened, but no ON_DRIVER_RESTART handler is bound.");
+    }
+  }
+
+  private void onStart(final StartTime startTime) {
+    for (final EventHandler<StartTime> startHandler : this.startHandlers) {
+      startHandler.onNext(startTime);
+    }
+  }
+
+  /**
+   * @return true, if the Driver is in fact being restarted.
+   */
+  private boolean isRestart() {
+    return this.driverStatusManager.getNumPreviousContainers() > 0;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverStatus.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverStatus.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverStatus.java
new file mode 100644
index 0000000..600092d
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverStatus.java
@@ -0,0 +1,30 @@
+/**
+ * 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.reef.runtime.common.driver;
+
+/**
+ * The status of the Driver.
+ */
+public enum DriverStatus {
+  PRE_INIT,
+  INIT,
+  RUNNING,
+  SHUTTING_DOWN,
+  FAILING
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverStatusManager.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverStatusManager.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverStatusManager.java
new file mode 100644
index 0000000..e5e544c
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/DriverStatusManager.java
@@ -0,0 +1,330 @@
+/**
+ * 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.reef.runtime.common.driver;
+
+import com.google.protobuf.ByteString;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.driver.api.AbstractDriverRuntimeConfiguration;
+import org.apache.reef.runtime.common.driver.client.ClientConnection;
+import org.apache.reef.runtime.common.utils.ExceptionCodec;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.time.Clock;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Manages the Driver's status.
+ */
+public final class DriverStatusManager {
+  private static final Logger LOG = Logger.getLogger(DriverStatusManager.class.getName());
+  private final Clock clock;
+  private final ClientConnection clientConnection;
+  private final String jobIdentifier;
+  private final ExceptionCodec exceptionCodec;
+  private DriverStatus driverStatus = DriverStatus.PRE_INIT;
+  private Optional<Throwable> shutdownCause = Optional.empty();
+  private boolean driverTerminationHasBeenCommunicatedToClient = false;
+  private boolean restartCompleted = false;
+  private int numPreviousContainers = -1;
+  private int numRecoveredContainers = 0;
+
+
+  /**
+   * @param clock
+   * @param clientConnection
+   * @param jobIdentifier
+   * @param exceptionCodec
+   */
+  @Inject
+  DriverStatusManager(final Clock clock,
+                      final ClientConnection clientConnection,
+                      final @Parameter(AbstractDriverRuntimeConfiguration.JobIdentifier.class) String jobIdentifier,
+                      final ExceptionCodec exceptionCodec) {
+    LOG.entering(DriverStatusManager.class.getCanonicalName(), "<init>");
+    this.clock = clock;
+    this.clientConnection = clientConnection;
+    this.jobIdentifier = jobIdentifier;
+    this.exceptionCodec = exceptionCodec;
+    LOG.log(Level.FINE, "Instantiated 'DriverStatusManager'");
+    LOG.exiting(DriverStatusManager.class.getCanonicalName(), "<init>");
+  }
+
+  /**
+   * Check whether a state transition 'from->to' is legal.
+   *
+   * @param from
+   * @param to
+   * @return
+   */
+  private static boolean isLegalTransition(final DriverStatus from, final DriverStatus to) {
+    switch (from) {
+      case PRE_INIT:
+        switch (to) {
+          case INIT:
+            return true;
+          default:
+            return false;
+        }
+      case INIT:
+        switch (to) {
+          case RUNNING:
+            return true;
+          default:
+            return false;
+        }
+      case RUNNING:
+        switch (to) {
+          case SHUTTING_DOWN:
+          case FAILING:
+            return true;
+          default:
+            return false;
+        }
+      case FAILING:
+      case SHUTTING_DOWN:
+        return false;
+      default:
+        throw new IllegalStateException("Unknown input state: " + from);
+    }
+  }
+
+  /**
+   * Changes the driver status to INIT and sends message to the client about the transition.
+   */
+  public synchronized void onInit() {
+    LOG.entering(DriverStatusManager.class.getCanonicalName(), "onInit");
+    this.clientConnection.send(this.getInitMessage());
+    this.setStatus(DriverStatus.INIT);
+    LOG.exiting(DriverStatusManager.class.getCanonicalName(), "onInit");
+  }
+
+  /**
+   * Changes the driver status to RUNNING and sends message to the client about the transition.
+   * If the driver is in status 'PRE_INIT', this first calls onInit();
+   */
+  public synchronized void onRunning() {
+    LOG.entering(DriverStatusManager.class.getCanonicalName(), "onRunning");
+    if (this.driverStatus.equals(DriverStatus.PRE_INIT)) {
+      this.onInit();
+    }
+    this.clientConnection.send(this.getRunningMessage());
+    this.setStatus(DriverStatus.RUNNING);
+    LOG.exiting(DriverStatusManager.class.getCanonicalName(), "onRunning");
+  }
+
+  /**
+   * End the Driver with an exception.
+   *
+   * @param exception
+   */
+  public synchronized void onError(final Throwable exception) {
+    LOG.entering(DriverStatusManager.class.getCanonicalName(), "onError", new Object[]{exception});
+    if (this.isShuttingDownOrFailing()) {
+      LOG.log(Level.WARNING, "Received an exception while already in shutdown.", exception);
+    } else {
+      LOG.log(Level.WARNING, "Shutting down the Driver with an exception: ", exception);
+      this.shutdownCause = Optional.of(exception);
+      this.clock.stop();
+      this.setStatus(DriverStatus.FAILING);
+    }
+    LOG.exiting(DriverStatusManager.class.getCanonicalName(), "onError", new Object[]{exception});
+  }
+
+  /**
+   * Perform a clean shutdown of the Driver.
+   */
+  public synchronized void onComplete() {
+    LOG.entering(DriverStatusManager.class.getCanonicalName(), "onComplete");
+    if (this.isShuttingDownOrFailing()) {
+      LOG.log(Level.WARNING, "Ignoring second call to onComplete()");
+    } else {
+      LOG.log(Level.INFO, "Clean shutdown of the Driver.");
+      if (LOG.isLoggable(Level.FINEST)) {
+        LOG.log(Level.FINEST, "Callstack: ", new Exception());
+      }
+      this.clock.close();
+      this.setStatus(DriverStatus.SHUTTING_DOWN);
+    }
+    LOG.exiting(DriverStatusManager.class.getCanonicalName(), "onComplete");
+
+  }
+
+  /**
+   * Sends the final message to the Driver. This is used by DriverRuntimeStopHandler.onNext().
+   *
+   * @param exception
+   */
+  public synchronized void sendJobEndingMessageToClient(final Optional<Throwable> exception) {
+    if (this.isNotShuttingDownOrFailing()) {
+      LOG.log(Level.SEVERE, "Sending message in a state different that SHUTTING_DOWN or FAILING. This is likely a illegal call to clock.close() at play. Current state: " + this.driverStatus);
+    }
+    if (this.driverTerminationHasBeenCommunicatedToClient) {
+      LOG.log(Level.SEVERE, ".sendJobEndingMessageToClient() called twice. Ignoring the second call");
+    } else {
+      { // Log the shutdown situation
+        if (this.shutdownCause.isPresent()) {
+          LOG.log(Level.WARNING, "Sending message about an unclean driver shutdown.", this.shutdownCause.get());
+        }
+        if (exception.isPresent()) {
+          LOG.log(Level.WARNING, "There was an exception during clock.close().", exception.get());
+        }
+        if (this.shutdownCause.isPresent() && exception.isPresent()) {
+          LOG.log(Level.WARNING, "The driver is shutdown because of an exception (see above) and there was an exception during clock.close(). Only the first exception will be sent to the client");
+        }
+      }
+      if (this.shutdownCause.isPresent()) {
+        // Send the earlier exception, if there was one
+        this.clientConnection.send(getJobEndingMessage(this.shutdownCause));
+      } else {
+        // Send the exception passed, if there was one.
+        this.clientConnection.send(getJobEndingMessage(exception));
+      }
+      this.driverTerminationHasBeenCommunicatedToClient = true;
+    }
+  }
+
+  /**
+   * Indicate that the Driver restart is complete. It is meant to be called exactly once during a restart and never
+   * during the ininital launch of a Driver.
+   */
+  public synchronized void setRestartCompleted() {
+    if (!this.isDriverRestart()) {
+      throw new IllegalStateException("setRestartCompleted() called in a Driver that is not, in fact, restarted.");
+    } else if (this.restartCompleted) {
+      LOG.log(Level.WARNING, "Calling setRestartCompleted more than once.");
+    } else {
+      this.restartCompleted = true;
+    }
+  }
+
+  /**
+   * @return the number of Evaluators expected to check in from a previous run.
+   */
+  public synchronized int getNumPreviousContainers() {
+    return this.numPreviousContainers;
+  }
+
+  /**
+   * Set the number of containers to expect still active from a previous execution of the Driver in a restart situation.
+   * To be called exactly once during a driver restart.
+   *
+   * @param num
+   */
+  public synchronized void setNumPreviousContainers(final int num) {
+    if (this.numPreviousContainers >= 0) {
+      throw new IllegalStateException("Attempting to set the number of expected containers left from a previous container more than once.");
+    } else {
+      this.numPreviousContainers = num;
+    }
+  }
+
+  /**
+   * @return the number of Evaluators from a previous Driver that have checked in with the Driver in a restart situation.
+   */
+  public synchronized int getNumRecoveredContainers() {
+    return this.numRecoveredContainers;
+  }
+
+  /**
+   * Indicate that this Driver has re-established the connection with one more Evaluator of a previous run.
+   */
+  public synchronized void oneContainerRecovered() {
+    this.numRecoveredContainers += 1;
+    if (this.numRecoveredContainers > this.numPreviousContainers) {
+      throw new IllegalStateException("Reconnected to" +
+          this.numRecoveredContainers +
+          "Evaluators while only expecting " +
+          this.numPreviousContainers);
+    }
+  }
+
+  /**
+   * @return true if the Driver is a restarted driver of an earlier attempt.
+   */
+  private synchronized boolean isDriverRestart() {
+    return this.getNumPreviousContainers() > 0;
+  }
+
+  public synchronized boolean isShuttingDownOrFailing() {
+    return DriverStatus.SHUTTING_DOWN.equals(this.driverStatus)
+        || DriverStatus.FAILING.equals(this.driverStatus);
+  }
+
+  private synchronized boolean isNotShuttingDownOrFailing() {
+    return !isShuttingDownOrFailing();
+  }
+
+  /**
+   * Helper method to set the status. This also checks whether the transition from the current status to the new one is
+   * legal.
+   *
+   * @param newStatus
+   */
+  private synchronized void setStatus(final DriverStatus newStatus) {
+    if (isLegalTransition(this.driverStatus, newStatus)) {
+      this.driverStatus = newStatus;
+    } else {
+      LOG.log(Level.WARNING, "Illegal state transiton: '" + this.driverStatus + "'->'" + newStatus + "'");
+    }
+  }
+
+  /**
+   * @param exception the exception that ended the Driver, if any.
+   * @return message to be sent to the client at the end of the job.
+   */
+  private synchronized ReefServiceProtos.JobStatusProto getJobEndingMessage(final Optional<Throwable> exception) {
+    final ReefServiceProtos.JobStatusProto message;
+    if (exception.isPresent()) {
+      message = ReefServiceProtos.JobStatusProto.newBuilder()
+          .setIdentifier(this.jobIdentifier)
+          .setState(ReefServiceProtos.State.FAILED)
+          .setException(ByteString.copyFrom(this.exceptionCodec.toBytes(exception.get())))
+          .build();
+    } else {
+      message = ReefServiceProtos.JobStatusProto.newBuilder()
+          .setIdentifier(this.jobIdentifier)
+          .setState(ReefServiceProtos.State.DONE)
+          .build();
+    }
+    return message;
+  }
+
+  /**
+   * @return The message to be sent through the ClientConnection when in state INIT.
+   */
+  private synchronized ReefServiceProtos.JobStatusProto getInitMessage() {
+    return ReefServiceProtos.JobStatusProto.newBuilder()
+        .setIdentifier(this.jobIdentifier)
+        .setState(ReefServiceProtos.State.INIT)
+        .build();
+  }
+
+  /**
+   * @return The message to be sent through the ClientConnection when in state RUNNING.
+   */
+  private synchronized ReefServiceProtos.JobStatusProto getRunningMessage() {
+    return ReefServiceProtos.JobStatusProto.newBuilder()
+        .setIdentifier(this.jobIdentifier)
+        .setState(ReefServiceProtos.State.RUNNING)
+        .build();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/EvaluatorRequestorImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/EvaluatorRequestorImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/EvaluatorRequestorImpl.java
new file mode 100644
index 0000000..940de3c
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/EvaluatorRequestorImpl.java
@@ -0,0 +1,95 @@
+/**
+ * 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.reef.runtime.common.driver;
+
+import org.apache.reef.driver.catalog.NodeDescriptor;
+import org.apache.reef.driver.catalog.RackDescriptor;
+import org.apache.reef.driver.catalog.ResourceCatalog;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.api.ResourceRequestHandler;
+import org.apache.reef.util.logging.LoggingScope;
+import org.apache.reef.util.logging.LoggingScopeFactory;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+
+/**
+ * Implementation of the EvaluatorRequestor that translates the request and hands it down to the underlying RM.
+ */
+public final class EvaluatorRequestorImpl implements EvaluatorRequestor {
+
+  private static final Logger LOG = Logger.getLogger(EvaluatorRequestorImpl.class.getName());
+
+  private final ResourceCatalog resourceCatalog;
+  private final ResourceRequestHandler resourceRequestHandler;
+  private final LoggingScopeFactory loggingScopeFactory;
+
+  /**
+   * @param resourceCatalog
+   * @param resourceRequestHandler
+   */
+  @Inject
+  public EvaluatorRequestorImpl(final ResourceCatalog resourceCatalog,
+                                final ResourceRequestHandler resourceRequestHandler,
+                                final LoggingScopeFactory loggingScopeFactory) {
+    this.resourceCatalog = resourceCatalog;
+    this.resourceRequestHandler = resourceRequestHandler;
+    this.loggingScopeFactory = loggingScopeFactory;
+  }
+
+  @Override
+  public synchronized void submit(final EvaluatorRequest req) {
+    LOG.log(Level.FINEST, "Got an EvaluatorRequest: number: {0}, memory = {1}, cores = {2}.", new Object[]{req.getNumber(), req.getMegaBytes(), req.getNumberOfCores()});
+
+    if (req.getMegaBytes() <= 0) {
+      throw new IllegalArgumentException("Given an unsupported memory size: " + req.getMegaBytes());
+    }
+    if (req.getNumberOfCores() <= 0) {
+      throw new IllegalArgumentException("Given an unsupported core number: " + req.getNumberOfCores());
+    }
+    if (req.getNumber() <= 0) {
+      throw new IllegalArgumentException("Given an unsupported number of evaluators: " + req.getNumber());
+    }
+
+    try (LoggingScope ls = loggingScopeFactory.evaluatorSubmit(req.getNumber())) {
+      final DriverRuntimeProtocol.ResourceRequestProto.Builder request = DriverRuntimeProtocol.ResourceRequestProto
+          .newBuilder()
+          .setResourceCount(req.getNumber())
+          .setVirtualCores(req.getNumberOfCores())
+          .setMemorySize(req.getMegaBytes());
+
+      final ResourceCatalog.Descriptor descriptor = req.getDescriptor();
+      if (descriptor != null) {
+        if (descriptor instanceof RackDescriptor) {
+          request.addRackName(descriptor.getName());
+        } else if (descriptor instanceof NodeDescriptor) {
+          request.addNodeName(descriptor.getName());
+        } else {
+          throw new IllegalArgumentException("Unable to operate on descriptors of type " + descriptor.getClass().getName());
+        }
+      }
+
+      this.resourceRequestHandler.onNext(request.build());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/AbstractDriverRuntimeConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/AbstractDriverRuntimeConfiguration.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/AbstractDriverRuntimeConfiguration.java
new file mode 100644
index 0000000..b832d22
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/AbstractDriverRuntimeConfiguration.java
@@ -0,0 +1,124 @@
+/**
+ * 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.reef.runtime.common.driver.api;
+
+import org.apache.reef.runtime.common.launch.parameters.ErrorHandlerRID;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.util.Builder;
+
+/**
+ * @deprecated Runtimes are advised to create their own ConfigurationModules instead of subclassing this class.
+ */
+@Deprecated
+public abstract class AbstractDriverRuntimeConfiguration implements Builder<Configuration> {
+
+  protected JavaConfigurationBuilder builder = Tang.Factory.getTang().newConfigurationBuilder();
+
+  protected AbstractDriverRuntimeConfiguration(
+      final Class<? extends ResourceLaunchHandler> resourceLaunchHandlerClass,
+      final Class<? extends ResourceReleaseHandler> resourceReleaseHandlerClass,
+      final Class<? extends ResourceRequestHandler> resourceRequestHandlerClass) {
+    try {
+      this.builder.bind(ResourceLaunchHandler.class, resourceLaunchHandlerClass);
+      this.builder.bind(ResourceReleaseHandler.class, resourceReleaseHandlerClass);
+      this.builder.bind(ResourceRequestHandler.class, resourceRequestHandlerClass);
+
+    } catch (final BindException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  public final Configuration build() {
+    return this.builder.build();
+  }
+
+  public final AbstractDriverRuntimeConfiguration addClientConfiguration(final Configuration conf) {
+    try {
+      this.builder.addConfiguration(conf);
+      return this;
+    } catch (final BindException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  public final AbstractDriverRuntimeConfiguration setJobIdentifier(final String id) {
+    try {
+      this.builder.bindNamedParameter(JobIdentifier.class, id.toString());
+      return this;
+    } catch (final BindException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  public final AbstractDriverRuntimeConfiguration setClientRemoteIdentifier(final String rid) {
+    try {
+      this.builder.bindNamedParameter(ClientRemoteIdentifier.class, rid.toString());
+      return this;
+    } catch (final BindException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  public final AbstractDriverRuntimeConfiguration setDriverProcessMemory(final int memory) {
+    try {
+      this.builder.bindNamedParameter(DriverProcessMemory.class, Integer.toString(memory));
+      return this;
+    } catch (final BindException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  public final AbstractDriverRuntimeConfiguration setEvaluatorTimeout(final long value) {
+    try {
+      this.builder.bindNamedParameter(EvaluatorTimeout.class, Long.toString(value));
+      return this;
+    } catch (final BindException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  @NamedParameter(doc = "The job identifier.")
+  public final static class JobIdentifier implements Name<String> {
+  }
+
+  @NamedParameter(doc = "The client remote identifier.", default_value = ClientRemoteIdentifier.NONE)
+  public final static class ClientRemoteIdentifier implements Name<String> {
+    /**
+     * Indicates that there is no Client.
+     */
+    public static final String NONE = ErrorHandlerRID.NONE;
+  }
+
+  @NamedParameter(doc = "The evaluator timeout (how long to wait before deciding an evaluator is dead.", default_value = "60000")
+  public final static class EvaluatorTimeout implements Name<Long> {
+  }
+
+  /**
+   * This parameter denotes that the driver process should actually be
+   * started in a separate process with the given amount of JVM memory.
+   */
+  @NamedParameter(doc = "The driver process memory.", default_value = "512")
+  public final static class DriverProcessMemory implements Name<Integer> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/DefaultResourceManagerLifeCycle.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/DefaultResourceManagerLifeCycle.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/DefaultResourceManagerLifeCycle.java
new file mode 100644
index 0000000..51da6c0
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/DefaultResourceManagerLifeCycle.java
@@ -0,0 +1,18 @@
+/**
+ * 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.
+ */

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/ResourceLaunchHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/ResourceLaunchHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/ResourceLaunchHandler.java
new file mode 100644
index 0000000..65c3830
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/ResourceLaunchHandler.java
@@ -0,0 +1,30 @@
+/**
+ * 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.reef.runtime.common.driver.api;
+
+import org.apache.reef.annotations.audience.RuntimeAuthor;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ *
+ */
+@RuntimeAuthor
+public interface ResourceLaunchHandler extends EventHandler<DriverRuntimeProtocol.ResourceLaunchProto> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/ResourceManagerLifeCycle.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/ResourceManagerLifeCycle.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/ResourceManagerLifeCycle.java
new file mode 100644
index 0000000..51da6c0
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/ResourceManagerLifeCycle.java
@@ -0,0 +1,18 @@
+/**
+ * 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.
+ */

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/ResourceReleaseHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/ResourceReleaseHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/ResourceReleaseHandler.java
new file mode 100644
index 0000000..581eb63
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/ResourceReleaseHandler.java
@@ -0,0 +1,30 @@
+/**
+ * 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.reef.runtime.common.driver.api;
+
+import org.apache.reef.annotations.audience.RuntimeAuthor;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ *
+ */
+@RuntimeAuthor
+public interface ResourceReleaseHandler extends EventHandler<DriverRuntimeProtocol.ResourceReleaseProto> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/ResourceRequestHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/ResourceRequestHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/ResourceRequestHandler.java
new file mode 100644
index 0000000..3d30ec8
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/ResourceRequestHandler.java
@@ -0,0 +1,30 @@
+/**
+ * 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.reef.runtime.common.driver.api;
+
+import org.apache.reef.annotations.audience.RuntimeAuthor;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ * The evaluator request handler.
+ */
+@RuntimeAuthor
+public interface ResourceRequestHandler extends EventHandler<DriverRuntimeProtocol.ResourceRequestProto> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/RuntimeParameters.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/RuntimeParameters.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/RuntimeParameters.java
new file mode 100644
index 0000000..e847249
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/RuntimeParameters.java
@@ -0,0 +1,50 @@
+/**
+ * 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.reef.runtime.common.driver.api;
+
+import org.apache.reef.annotations.audience.RuntimeAuthor;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ * Driver resourcemanager parameters that resourcemanager implementations use to communicate with
+ * the Driver.
+ */
+@RuntimeAuthor
+public final class RuntimeParameters {
+
+  @NamedParameter(doc = "The resource allocation handler that stub runtimes send along allocated resources e.g., containers.")
+  public final static class ResourceAllocationHandler implements Name<EventHandler<DriverRuntimeProtocol.ResourceAllocationProto>> {
+  }
+
+  @NamedParameter(doc = "The node descriptor handler that stub runtimes send along node information.")
+  public final static class NodeDescriptorHandler implements Name<EventHandler<DriverRuntimeProtocol.NodeDescriptorProto>> {
+  }
+
+  @NamedParameter(doc = "The resource status handler.")
+  public final static class ResourceStatusHandler implements Name<EventHandler<DriverRuntimeProtocol.ResourceStatusProto>> {
+  }
+
+  @NamedParameter(doc = "The resourcemanager status handler.")
+  public final static class RuntimeStatusHandler implements Name<EventHandler<DriverRuntimeProtocol.RuntimeStatusProto>> {
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/package-info.java
new file mode 100644
index 0000000..50f52f6
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/api/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Driver-Side Event Handlers to be implemented by a specific resource manager.
+ */
+package org.apache.reef.runtime.common.driver.api;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/catalog/NodeDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/catalog/NodeDescriptorImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/catalog/NodeDescriptorImpl.java
new file mode 100644
index 0000000..3cdf0d3
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/catalog/NodeDescriptorImpl.java
@@ -0,0 +1,78 @@
+/**
+ * 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.reef.runtime.common.driver.catalog;
+
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.catalog.NodeDescriptor;
+import org.apache.reef.driver.catalog.RackDescriptor;
+
+import java.net.InetSocketAddress;
+
+@Private
+public class NodeDescriptorImpl implements NodeDescriptor {
+
+  private final RackDescriptorImpl rack;
+
+  private final String id;
+
+  private final InetSocketAddress address;
+
+  private final int ram;
+
+  /**
+   * @param id
+   * @param address
+   * @param rack
+   * @param ram     the RAM available to the machine, in MegaBytes.
+   */
+  NodeDescriptorImpl(final String id, final InetSocketAddress address, final RackDescriptorImpl rack, final int ram) {
+    this.id = id;
+    this.address = address;
+    this.rack = rack;
+    this.ram = ram;
+    this.rack.addNodeDescriptor(this);
+  }
+
+  @Override
+  public String toString() {
+    return "Node [" + this.address + "]: RACK " + this.rack.getName() + ", RAM " + ram;
+  }
+
+  @Override
+  public final String getId() {
+    return this.id;
+  }
+
+
+  @Override
+  public InetSocketAddress getInetSocketAddress() {
+    return this.address;
+  }
+
+  @Override
+  public RackDescriptor getRackDescriptor() {
+    return this.rack;
+  }
+
+  @Override
+  public String getName() {
+    return this.address.getHostName();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/catalog/RackDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/catalog/RackDescriptorImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/catalog/RackDescriptorImpl.java
new file mode 100644
index 0000000..4256ee5
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/catalog/RackDescriptorImpl.java
@@ -0,0 +1,78 @@
+/**
+ * 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.reef.runtime.common.driver.catalog;
+
+import org.apache.reef.driver.catalog.NodeDescriptor;
+import org.apache.reef.driver.catalog.RackDescriptor;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public final class RackDescriptorImpl implements RackDescriptor {
+
+  private final String name;
+
+
+  private final List<NodeDescriptorImpl> nodes;
+
+  RackDescriptorImpl(final String name) {
+    this.name = name;
+    this.nodes = new ArrayList<>();
+  }
+
+  public final String toString() {
+    final StringBuilder sb = new StringBuilder();
+    sb.append("Rack " + this.name);
+    for (final NodeDescriptorImpl node : nodes) {
+      sb.append("\n\t" + node);
+    }
+    return sb.toString();
+  }
+
+  public final int hashCode() {
+    return this.name.hashCode();
+  }
+
+  public final boolean equals(final Object obj) {
+    if (obj instanceof RackDescriptorImpl) {
+      return obj.toString().equals(this.name);
+    } else {
+      return false;
+    }
+  }
+
+  public String getName() {
+    return this.name;
+  }
+
+  @Override
+  public List<NodeDescriptor> getNodes() {
+    return Collections.unmodifiableList(new ArrayList<NodeDescriptor>(this.nodes));
+  }
+
+  /**
+   * Should only be used from YarnNodeDescriptor constructor.
+   *
+   * @param node to add.
+   */
+  void addNodeDescriptor(final NodeDescriptorImpl node) {
+    this.nodes.add(node);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/catalog/ResourceCatalogImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/catalog/ResourceCatalogImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/catalog/ResourceCatalogImpl.java
new file mode 100644
index 0000000..6193af4
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/catalog/ResourceCatalogImpl.java
@@ -0,0 +1,88 @@
+/**
+ * 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.reef.runtime.common.driver.catalog;
+
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.catalog.NodeDescriptor;
+import org.apache.reef.driver.catalog.RackDescriptor;
+import org.apache.reef.driver.catalog.ResourceCatalog;
+import org.apache.reef.proto.DriverRuntimeProtocol.NodeDescriptorProto;
+
+import javax.inject.Inject;
+import java.net.InetSocketAddress;
+import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Private
+public final class ResourceCatalogImpl implements ResourceCatalog {
+
+  public final static String DEFAULT_RACK = "/default-rack";
+  private static final Logger LOG = Logger.getLogger(ResourceCatalog.class.getName());
+  private final Map<String, RackDescriptorImpl> racks = new HashMap<>();
+
+  private final Map<String, NodeDescriptorImpl> nodes = new HashMap<>();
+
+  @Inject
+  ResourceCatalogImpl() {
+    LOG.log(Level.FINE, "Instantiated 'ResourceCatalogImpl'");
+  }
+
+  @Override
+  public synchronized String toString() {
+    final StringBuilder sb = new StringBuilder();
+    sb.append("=== Resource Catalog ===");
+    for (final RackDescriptor rack : racks.values()) {
+      sb.append("\n" + rack);
+    }
+    return sb.toString();
+  }
+
+  @Override
+  public synchronized Collection<NodeDescriptor> getNodes() {
+    return Collections.unmodifiableCollection(new ArrayList<NodeDescriptor>(this.nodes.values()));
+  }
+
+  @Override
+  public synchronized Collection<RackDescriptor> getRacks() {
+    return Collections.unmodifiableCollection(new ArrayList<RackDescriptor>(this.racks.values()));
+  }
+
+  public synchronized final NodeDescriptor getNode(final String id) {
+    return this.nodes.get(id);
+  }
+
+  public synchronized final void handle(final NodeDescriptorProto node) {
+    final String rack_name = (node.hasRackName() ? node.getRackName() : DEFAULT_RACK);
+
+    LOG.log(Level.FINEST, "Catalog new node: id[{0}], rack[{1}], host[{2}], port[{3}], memory[{4}]",
+        new Object[]{node.getIdentifier(), rack_name, node.getHostName(), node.getPort(),
+            node.getMemorySize()}
+    );
+
+    if (!this.racks.containsKey(rack_name)) {
+      final RackDescriptorImpl rack = new RackDescriptorImpl(rack_name);
+      this.racks.put(rack_name, rack);
+    }
+    final RackDescriptorImpl rack = this.racks.get(rack_name);
+    final InetSocketAddress address = new InetSocketAddress(node.getHostName(), node.getPort());
+    final NodeDescriptorImpl nodeDescriptor = new NodeDescriptorImpl(node.getIdentifier(), address, rack, node.getMemorySize());
+    this.nodes.put(nodeDescriptor.getId(), nodeDescriptor);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/ClientConnection.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/ClientConnection.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/ClientConnection.java
new file mode 100644
index 0000000..f7640b9
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/ClientConnection.java
@@ -0,0 +1,82 @@
+/**
+ * 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.reef.runtime.common.driver.client;
+
+import com.google.protobuf.ByteString;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.driver.api.AbstractDriverRuntimeConfiguration;
+import org.apache.reef.runtime.common.utils.RemoteManager;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Represents the communication channel to the client.
+ */
+@DriverSide
+public final class ClientConnection {
+
+  private static final Logger LOG = Logger.getLogger(ClientConnection.class.getName());
+
+  private final EventHandler<ReefServiceProtos.JobStatusProto> jobStatusHandler;
+  private final String jobIdentifier;
+
+  @Inject
+  public ClientConnection(
+      final RemoteManager remoteManager,
+      final @Parameter(AbstractDriverRuntimeConfiguration.ClientRemoteIdentifier.class) String clientRID,
+      final @Parameter(AbstractDriverRuntimeConfiguration.JobIdentifier.class) String jobIdentifier) {
+    this.jobIdentifier = jobIdentifier;
+    if (clientRID.equals(AbstractDriverRuntimeConfiguration.ClientRemoteIdentifier.NONE)) {
+      LOG.log(Level.FINE, "Instantiated 'ClientConnection' without an actual connection to the client.");
+      this.jobStatusHandler = new LoggingJobStatusHandler();
+    } else {
+      this.jobStatusHandler = remoteManager.getHandler(clientRID, ReefServiceProtos.JobStatusProto.class);
+      LOG.log(Level.FINE, "Instantiated 'ClientConnection'");
+    }
+  }
+
+  /**
+   * Send the given JobStatus to the client.
+   *
+   * @param status
+   */
+  public synchronized void send(final ReefServiceProtos.JobStatusProto status) {
+    LOG.log(Level.FINEST, "Sending:\n" + status);
+    this.jobStatusHandler.onNext(status);
+  }
+
+  /**
+   * Send the given byte[] as a message to the client.
+   *
+   * @param message
+   */
+  public synchronized void sendMessage(final byte[] message) {
+    this.send(ReefServiceProtos.JobStatusProto.newBuilder()
+        .setIdentifier(this.jobIdentifier)
+        .setState(ReefServiceProtos.State.RUNNING)
+        .setMessage(ByteString.copyFrom(message))
+        .build());
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/ClientManager.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/ClientManager.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/ClientManager.java
new file mode 100644
index 0000000..2a686af
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/client/ClientManager.java
@@ -0,0 +1,148 @@
+/**
+ * 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.reef.runtime.common.driver.client;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.parameters.ClientCloseHandlers;
+import org.apache.reef.driver.parameters.ClientCloseWithMessageHandlers;
+import org.apache.reef.driver.parameters.ClientMessageHandlers;
+import org.apache.reef.proto.ClientRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.DriverStatusManager;
+import org.apache.reef.runtime.common.driver.api.AbstractDriverRuntimeConfiguration;
+import org.apache.reef.runtime.common.utils.BroadCastEventHandler;
+import org.apache.reef.runtime.common.utils.RemoteManager;
+import org.apache.reef.tang.InjectionFuture;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Represents the Client in the Driver.
+ */
+@Private
+@DriverSide
+public final class ClientManager implements EventHandler<ClientRuntimeProtocol.JobControlProto> {
+
+  private final static Logger LOG = Logger.getLogger(ClientManager.class.getName());
+
+
+  private final InjectionFuture<Set<EventHandler<Void>>> clientCloseHandlers;
+
+  private final InjectionFuture<Set<EventHandler<byte[]>>> clientCloseWithMessageHandlers;
+
+  private final InjectionFuture<Set<EventHandler<byte[]>>> clientMessageHandlers;
+
+  private final DriverStatusManager driverStatusManager;
+
+  private volatile EventHandler<Void> clientCloseDispatcher;
+
+  private volatile EventHandler<byte[]> clientCloseWithMessageDispatcher;
+
+  private volatile EventHandler<byte[]> clientMessageDispatcher;
+
+
+  @Inject
+  ClientManager(final @Parameter(ClientCloseHandlers.class) InjectionFuture<Set<EventHandler<Void>>> clientCloseHandlers,
+                final @Parameter(ClientCloseWithMessageHandlers.class) InjectionFuture<Set<EventHandler<byte[]>>> clientCloseWithMessageHandlers,
+                final @Parameter(ClientMessageHandlers.class) InjectionFuture<Set<EventHandler<byte[]>>> clientMessageHandlers,
+                final @Parameter(AbstractDriverRuntimeConfiguration.ClientRemoteIdentifier.class) String clientRID,
+                final RemoteManager remoteManager,
+                final DriverStatusManager driverStatusManager) {
+    this.driverStatusManager = driverStatusManager;
+    this.clientCloseHandlers = clientCloseHandlers;
+    this.clientCloseWithMessageHandlers = clientCloseWithMessageHandlers;
+    this.clientMessageHandlers = clientMessageHandlers;
+
+    if (!clientRID.equals(AbstractDriverRuntimeConfiguration.ClientRemoteIdentifier.NONE)) {
+      remoteManager.registerHandler(clientRID, ClientRuntimeProtocol.JobControlProto.class, this);
+    } else {
+      LOG.log(Level.FINE, "Not registering a handler for JobControlProto, as there is no client.");
+    }
+  }
+
+  /**
+   * This method reacts to control messages passed by the client to the driver. It will forward
+   * messages related to the ClientObserver interface to the Driver. It will also initiate a shutdown
+   * if the client indicates a close message.
+   *
+   * @param jobControlProto contains the client initiated control message
+   */
+  @Override
+  public synchronized void onNext(final ClientRuntimeProtocol.JobControlProto jobControlProto) {
+    if (jobControlProto.hasSignal()) {
+      if (jobControlProto.getSignal() == ClientRuntimeProtocol.Signal.SIG_TERMINATE) {
+        try {
+          if (jobControlProto.hasMessage()) {
+            getClientCloseWithMessageDispatcher().onNext(jobControlProto.getMessage().toByteArray());
+          } else {
+            getClientCloseDispatcher().onNext(null);
+          }
+        } finally {
+          this.driverStatusManager.onComplete();
+        }
+      } else {
+        LOG.log(Level.FINEST, "Unsupported signal: " + jobControlProto.getSignal());
+      }
+    } else if (jobControlProto.hasMessage()) {
+      getClientMessageDispatcher().onNext(jobControlProto.getMessage().toByteArray());
+    }
+  }
+
+  private synchronized EventHandler<Void> getClientCloseDispatcher() {
+    if (clientCloseDispatcher != null) {
+      return clientCloseDispatcher;
+    } else {
+      synchronized (this) {
+        if (clientCloseDispatcher == null)
+          clientCloseDispatcher = new BroadCastEventHandler<>(clientCloseHandlers.get());
+      }
+      return clientCloseDispatcher;
+    }
+  }
+
+  private EventHandler<byte[]> getClientCloseWithMessageDispatcher() {
+    if (clientCloseWithMessageDispatcher != null) {
+      return clientCloseWithMessageDispatcher;
+    } else {
+      synchronized (this) {
+        if (clientCloseWithMessageDispatcher == null)
+          clientCloseWithMessageDispatcher = new BroadCastEventHandler<>(clientCloseWithMessageHandlers.get());
+      }
+      return clientCloseWithMessageDispatcher;
+    }
+  }
+
+  private EventHandler<byte[]> getClientMessageDispatcher() {
+    if (clientMessageDispatcher != null) {
+      return clientMessageDispatcher;
+    } else {
+      synchronized (this) {
+        if (clientMessageDispatcher == null)
+          clientMessageDispatcher = new BroadCastEventHandler<>(clientMessageHandlers.get());
+      }
+      return clientMessageDispatcher;
+    }
+  }
+
+}


[16/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Configuration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Configuration.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Configuration.java
new file mode 100644
index 0000000..af210d3
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Configuration.java
@@ -0,0 +1,167 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.types.ClassNode;
+import org.apache.reef.tang.types.ConstructorDef;
+import org.apache.reef.tang.types.NamedParameterNode;
+
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Set;
+
+/**
+ * Immutable, type-checked configuration data.
+ * <p/>
+ * Tang Configuration objects are constructed via
+ * ConfigurationBuilders, and most applications interact with the
+ * Configuration API much more than the one described here.  See
+ * the ConfigurationBuilder documentation for a discussion of the
+ * semantics of configuration options.  The documentation provided
+ * here is primarily for people that wish to extend Tang or implement
+ * formats that export data from Configuration objects to other systems.
+ * <p/>
+ * Conceptually, a configuration contains a set of key
+ * value pairs.  Each pair either maps from an interface to an
+ * implementation (a class) or from a configuration option to a
+ * value (e.g., an integer or string).
+ * <p/>
+ * Under the hood, Configuration objects carry much richer type
+ * information than this, and also refer to the ClassHierarchy
+ * object they were checked against.  Configurations can be
+ * merged into each other by creating a new ConfigurationBuilder
+ * object, and passing in multiple configurations.  In such situations,
+ * Tang automatically merges the reflection data from the underlying
+ * ClassHierarchy objects, and re-validates the merged configuration
+ * data against the merged classpath.
+ * <p/>
+ * Note that the left hand side of each configuration object (the
+ * "key" in the key value pair) is unique.  Although there are many
+ * APIs that take NamedParameterNode objects in this API, a given
+ * NamedParameterNode represents a unique type of binding, and is only
+ * applicable to one of the getters below.  These APIs use Java generic
+ * types to make it easier to map from NamedParameterNode to the appropriate
+ * getter.
+ */
+public interface Configuration {
+
+  /**
+   * Create a new ConfigurationBuilder object based on the same classpath
+   * as this Configuration, and populate it with the configuration options
+   * of this object.
+   * <p/>
+   * This API is unstable and should be considered private.  Use the methods
+   * in org.apache.reef.Tang instead.
+   */
+  public ConfigurationBuilder newBuilder();
+
+  /**
+   * Return the value of the given named parameter as an unparsed string.
+   * <p/>
+   * If nothing was explicitly bound, this method returns null (it does not
+   * return default values).
+   *
+   * @param np A NamedParameter object from this Configuration's class hierarchy.
+   * @return The validated string that this parameter is bound to, or null.
+   * @see getClassHierarchy()
+   */
+  public String getNamedParameter(NamedParameterNode<?> np);
+
+  /**
+   * Obtain the set of class hierarchy nodes or strings that were bound to a given NamedParameterNode.
+   * If nothing was explicitly bound, the set will be empty (it will not reflect any default values).
+   *
+   * @param np A NamedParameterNode from this Configuration's class hierarchy.
+   * @return A set of ClassHierarchy Node objects or a set of strings, depending on whether the NamedParameterNode refers to an interface or configuration options, respectively.
+   * @see getClassHierarchy()
+   */
+  public Set<Object> getBoundSet(NamedParameterNode<Set<?>> np);
+
+  /**
+   * Get the list bound to a given NamedParameterNode. The list will be empty if nothing was bound.
+   *
+   * @param np Target NamedParameter
+   * @return A list bound to np
+   */
+  public List<Object> getBoundList(NamedParameterNode<List<?>> np);
+
+  /**
+   * @return the external constructor that cn has been explicitly bound to, or null.  Defaults are not returned.
+   */
+  public <T> ClassNode<ExternalConstructor<T>> getBoundConstructor(ClassNode<T> cn);
+
+  /**
+   * @return the implementation that cn has been explicitly bound to, or null.  Defaults are not returned.
+   */
+  public <T> ClassNode<T> getBoundImplementation(ClassNode<T> cn);
+
+  /**
+   * Return the LegacyConstructor that has been bound to this Class.  Such constructors are defined in the class, but missing their @Inject annotation.
+   * <p/>
+   * For now, only one legacy constructor can be bound per class.
+   * <p/>
+   * TODO: Should this return Set<ConstructorDef<T>> instead?
+   */
+  public <T> ConstructorDef<T> getLegacyConstructor(ClassNode<T> cn);
+
+  /**
+   * @return the set of all interfaces (or super-classes) that have been explicitly
+   * bound to an implementation sub-class.
+   */
+  Set<ClassNode<?>> getBoundImplementations();
+
+  /**
+   * @return the set of all the interfaces that have had an external constructor bound to them.
+   */
+  Set<ClassNode<?>> getBoundConstructors();
+
+  /**
+   * @return the set of all the named parameters that have been explicitly bound to something.
+   */
+  Set<NamedParameterNode<?>> getNamedParameters();
+
+  /**
+   * @return the set of all interfaces that have a legacy constructor binding.
+   */
+  Set<ClassNode<?>> getLegacyConstructors();
+
+  /**
+   * Configuration objects are associated with the ClassHierarchy objects that were used during validation.
+   *
+   * @return the ClassHierarchy that backs this Configuration.
+   */
+  public ClassHierarchy getClassHierarchy();
+
+  /**
+   * Get the set bindings from set-valued NamedParameters to the values they were bound to.
+   * <p/>
+   * TODO: This API seems wonky.  Why not return a Set<NamedParameterNode<Set<?>>> instead, and let the caller invoke getBoundSet() above?
+   *
+   * @return a flattened set with one entry for each binding (the same NamedParameterNode may be a key for multiple bindings.
+   * @deprecated
+   */
+  @Deprecated
+  Iterable<Entry<NamedParameterNode<Set<?>>, Object>> getBoundSets();
+
+  /**
+   * @return the set of all NamedParameterNodes explicitly bound to lists.
+   */
+  Set<NamedParameterNode<List<?>>> getBoundLists();
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/ConfigurationBuilder.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/ConfigurationBuilder.java
new file mode 100644
index 0000000..b4152dd
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/ConfigurationBuilder.java
@@ -0,0 +1,251 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.types.ClassNode;
+import org.apache.reef.tang.types.ConstructorArg;
+import org.apache.reef.tang.types.NamedParameterNode;
+import org.apache.reef.tang.types.Node;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * This class allows applications to register bindings with Tang.  Tang
+ * configurations are simply sets of bindings of various types.  The most
+ * common bindings are of interfaces (or superclasses) to implementation
+ * classes, and of configuration options ("NamedParameters") to values.
+ * <p/>
+ * Implementations of this class type check the bindings against an underlying
+ * ClassHierarchy implementation.  Typically, the backing ClassHierarchy will
+ * be delegate to the default classloader (the one that loaded the code that is
+ * invoking Tang), though other scenarios are possible.  For instance, the
+ * ClassHierarchy could incorporate additional Jars, or it might not delegate
+ * to the default classloader at all.  In fact, Tang supports ClassHierarchy
+ * objects that are derived from reflection data from other languages, such as
+ * C#.  This enables cross-language injection sessions, where Java code
+ * configures C# code, or vice versa.
+ * <p/>
+ * <p/>
+ * When possible, the methods in this interface eagerly check for these
+ * errors.  Methods that check for configuration and other runtime or
+ * application-level errors are declared to throw BindException.
+ * <p/>
+ * Furthermore, all methods in Tang, may throw RuntimeException if they
+ * encounter inconsistencies in the underlying ClassHierarchy.  Such errors
+ * reflect problems that existed when the application was compiled or
+ * packaged, and cannot be corrected at runtime.  Examples include
+ * inconsistent type hierarchies (such as version mismatches between jars),
+ * and unparsable default values (such as an int that defaults to "false"
+ * or "five").  These exceptions are analogous to the runtime exceptions
+ * thrown by the Java classloader; other than logging them or reporting them
+ * to an end user, applications have little recourse when such problems are
+ * encountered.
+ *
+ * @see JavaConfigurationBuilder for convenience methods that assume the
+ * underlying ClassHierarchy object delegates to the default
+ * classloader, and enable many compile time static checks.
+ * @see ConfigurationModule which pushes additional type checks to class load
+ * time.  This allows Tint, Tang's static analysis tool, to detect a wide
+ * range of runtime configuration errors at build time.
+ */
+public interface ConfigurationBuilder {
+
+  /**
+   * Add all configuration parameters from the given Configuration object.
+   *
+   * @param c
+   */
+  public void addConfiguration(final Configuration c) throws BindException;
+
+  /**
+   * Each ConfigurationBuilder instance is associated with a ClassHierarchy.
+   * It uses this ClassHierarchy to validate the configuration options that it
+   * processes.
+   *
+   * @return a reference to the ClassHierarchy instance backing this
+   * ConfigurationBuilder. No copy is made, since ClassHierarchy objects
+   * are effectively immutable.
+   */
+  public ClassHierarchy getClassHierarchy();
+
+  /**
+   * Force Tang to treat the specified constructor as though it had an @Inject
+   * annotation.
+   * <p/>
+   * This method takes ClassNode objects.  Like all of the methods in this
+   * API, the ClassNode objects must come from the ClassHierarchy instance
+   * returned by getClassHierarchy().
+   *
+   * @param cn   The class the constructor instantiates.
+   * @param args The types of the arguments taken by the constructor, in declaration order.
+   * @throws BindException if the constructor does not exist, or if it has already been bound as a legacy constructor.
+   */
+  void registerLegacyConstructor(ClassNode<?> cn, ClassNode<?>... args)
+      throws BindException;
+
+  /**
+   * Force Tang to treat the specified constructor as though it had an @Inject
+   * annotation.
+   *
+   * @param cn   The full name of the class the constructor instantiates.
+   * @param args The full names of the types of the arguments taken by the constructor, in declaration order.
+   * @throws BindException if the constructor does not exist, or if it has already been bound as a legacy constructor.
+   */
+  void registerLegacyConstructor(String cn, String... args)
+      throws BindException;
+
+  /**
+   * Force Tang to treat the specified constructor as though it had an @Inject
+   * annotation.
+   * <p/>
+   * This method takes ClassNode and ConstructorArg objects.  Like all of the
+   * methods in this API, these objects must come from the ClassHierarchy
+   * instance returned by getClassHierarchy().
+   *
+   * @param cn   The class the constructor instantiates.
+   * @param args The parsed ConstructorArg objects correspdonding to the types of the arguments taken by the constructor, in declaration order.
+   * @throws BindException if the constructor does not exist, or if it has already been bound as a legacy constructor.
+   */
+  void registerLegacyConstructor(ClassNode<?> c, ConstructorArg... args)
+      throws BindException;
+
+  /**
+   * Bind classes to each other, based on their full class names; alternatively,
+   * bound a NamedParameter configuration option to a configuration value.
+   *
+   * @param iface The full name of the interface that should resolve to impl,
+   *              or the NamedParameter to be set.
+   * @param impl  The full name of the implementation that will be used in
+   *              place of impl, or the value the NamedParameter should be set to.
+   * @throws BindException If (In the case of interfaces and implementations)
+   *                       the underlying ClassHierarchy does not recognice iface and
+   *                       impl as known, valid classes, or if impl is not a in
+   *                       implementation of iface, or (in the case of NamedParameters
+   *                       and values) if iface is not a NamedParameter, or if impl
+   *                       fails to parse as the type the iface expects.
+   */
+  public <T> void bind(String iface, String impl)
+      throws BindException;
+
+  /**
+   * Bind classes to each other, based on their full class names; alternatively,
+   * bound a NamedParameter configuration option to a configuration value.
+   * <p/>
+   * This method takes Node objects.  Like all of the methods in this API,
+   * these objects must come from the ClassHierarchy instance returned by
+   * getClassHierarchy().
+   *
+   * @param key   The interface / NamedParmaeter to be bound.
+   * @param value The implementation / value iface should be set to.
+   * @throws BindException if there is a type checking error
+   * @see bind(String, String) for a more complete description.
+   */
+  void bind(Node iface, Node impl) throws BindException;
+
+  /**
+   * Register an ExternalConstructor implementation with Tang.
+   * ExternalConstructors are proxy classes that instantiate some
+   * other class.  They have two primary use cases: (1) adding new
+   * constructors to classes that you cannot modify and (2) implementing
+   * constructors that exmanine their arguments and return an instance of a
+   * subclass of the requested object.
+   * <p/>
+   * To see how the second use case could be useful, consider a implementing a
+   * URI interface with a distinct subclass for each valid URI prefix (e.g.,
+   * http://, ssh://, etc...).  An ExternalConstructor could examine the prefix
+   * and delegate to a constructor of the correct implementation (e.g, HttpURL,
+   * SshURL, etc...) which would validate the remainder of the provided string.
+   * URI's external constructor would return the validated subclass of URI that
+   * corresponds to the provided string, allowing instanceof and downcasts to
+   * behave as expected in the code that invoked Tang.
+   * <p/>
+   * Both use cases should be avoided when possible, since they can
+   * unnecessarily complicate object injections and undermine Tang's ability
+   * to statically check a given configuration.
+   * <p/>
+   * This method takes ClassNode objects.  Like all of the methods in this API,
+   * these objects must come from the ClassHierarchy instance returned by
+   * getClassHierarchy().
+   *
+   * @param iface The class or interface to be instantiated.
+   * @param impl  The ExternalConstructor class that will be used to instantiate iface.
+   * @throws BindException If impl does not instantiate a subclass of iface.
+   */
+  public <T> void bindConstructor(ClassNode<T> iface,
+                                  ClassNode<? extends ExternalConstructor<? extends T>> impl)
+      throws BindException;
+
+  /**
+   * Pretty print the default implementation / value of the provided class / NamedParamter.
+   * This is used by Tang to produce human readable error messages.
+   */
+  public String classPrettyDefaultString(String longName) throws BindException;
+
+  /**
+   * Pretty print the human readable documentation of the provided class / NamedParamter.
+   * This is used by Tang to produce human readable error messages.
+   */
+  public String classPrettyDescriptionString(String longName)
+      throws BindException;
+
+  /**
+   * Produce an immutable Configuration object that contains the current
+   * bindings and ClassHierarchy of this ConfigurationBuilder.  Future
+   * changes to this ConfigurationBuilder will not be reflected in the
+   * returned Configuration.
+   * <p/>
+   * Since Tang eagerly checks for configuration errors, this method does not
+   * perform any additional validation, and does not throw any checkable
+   * exceptions.
+   *
+   * @return
+   */
+  public Configuration build();
+
+  public <T> void bindSetEntry(NamedParameterNode<Set<T>> iface, Node impl)
+      throws BindException;
+
+  public <T> void bindSetEntry(NamedParameterNode<Set<T>> iface, String impl)
+      throws BindException;
+
+  public void bindSetEntry(String iface, String impl) throws BindException;
+
+  public void bindSetEntry(String iface, Node impl) throws BindException;
+
+  /**
+   * Bind an list of implementations(Class or String) to an given NamedParameter.
+   * Unlike bindSetEntry, bindListEntry will bind a whole list to the parameter,
+   * not an element of the list.
+   * <p/>
+   * Since ordering of the list is important, list binding cannot be repeated or
+   * merged unlike set binding. If the elements of the list are Classes, the objects
+   * created by the Classes will be injected. If the elements are Strings, the values
+   * will be injected directly to a given list parameter.
+   *
+   * @param iface    The list named parameter to be instantiated
+   * @param implList The list of class or value will be used to instantiated the named parameter
+   * @throws BindException
+   */
+  public <T> void bindList(NamedParameterNode<List<T>> iface, List implList) throws BindException;
+
+  public void bindList(String iface, List implList) throws BindException;
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Configurations.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Configurations.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Configurations.java
new file mode 100644
index 0000000..a7450bc
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Configurations.java
@@ -0,0 +1,59 @@
+/**
+ * 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.reef.tang;
+
+/**
+ * Helper class for Configurations
+ */
+public final class Configurations {
+
+  /**
+   * This is a utility class that isn't meant to be instantiated.
+   */
+  private Configurations() {
+  }
+
+
+  /**
+   * Merge a set of Configurations.
+   *
+   * @param configurations
+   * @return the merged configuration.
+   * @throws org.apache.reef.tang.exceptions.BindException if the merge fails.
+   */
+  public static Configuration merge(final Configuration... configurations) {
+    return Tang.Factory.getTang().newConfigurationBuilder(configurations).build();
+  }
+
+  /**
+   * Merge a set of Configurations.
+   *
+   * @param configurations
+   * @return the merged configuration.
+   * @throws org.apache.reef.tang.exceptions.BindException if the merge fails.
+   */
+  public static Configuration merge(final Iterable<Configuration> configurations) {
+    final ConfigurationBuilder configurationBuilder = Tang.Factory.getTang().newConfigurationBuilder();
+    for (final Configuration configuration : configurations) {
+      configurationBuilder.addConfiguration(configuration);
+    }
+    return configurationBuilder.build();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/ExternalConstructor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/ExternalConstructor.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/ExternalConstructor.java
new file mode 100644
index 0000000..7fb9fcc
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/ExternalConstructor.java
@@ -0,0 +1,40 @@
+/**
+ * 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.reef.tang;
+
+/**
+ * This interface allows legacy classes to be injected by
+ * ConfigurationBuilderImpl. To be of any use, implementations of this class
+ * must have at least one constructor with an @Inject annotation. From
+ * ConfigurationBuilderImpl's perspective, an ExternalConstructor class is just
+ * a special instance of the class T, except that, after injection an
+ * ExternalConstructor, ConfigurationBuilderImpl will call newInstance, and
+ * store the resulting object. It will then discard the ExternalConstructor.
+ *
+ * @param <T> The type this ExternalConstructor will create.
+ * @author sears
+ */
+public interface ExternalConstructor<T> {
+  /**
+   * This method will only be called once.
+   *
+   * @return a new, distinct instance of T.
+   */
+  public T newInstance();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/InjectionFuture.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/InjectionFuture.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/InjectionFuture.java
new file mode 100644
index 0000000..0cdc522
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/InjectionFuture.java
@@ -0,0 +1,136 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.implementation.java.InjectorImpl;
+
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A future-based mechanism for cyclic object injections. Since Tang is a
+ * constructor-based dependency injector, there is no way to directly create
+ * cycles of objects.
+ * <p/>
+ * In situations where you need to have two objects that point at each other, you
+ * can use an InjectionFuture to break the cycle. Simply ask Tang to inject an
+ * InjectionFuture<T> into your constructor.  Later (after your constructor
+ * returns) invoke the get() method of the injection future to get a reference
+ * to an injected object of type T.
+ * <p/>
+ * Note that InjectorFutures and singletons interact in subtle ways.
+ * <p/>
+ * Normally, Tang never reuses a reference to an injected object unless the
+ * object is a singleton or a volatile instance. If InjectionFutures followed
+ * this convention, then a cyclic injection of two non-singleton classes would
+ * result in an an infinite chain of objects of the two types. Tang addresses
+ * this issue as follows:
+ * <p/>
+ * 1) In the first pass, it injects a complete object tree, making note of
+ * InjectionFuture objects that will need to be populated later. The injection
+ * of this tree respects standard Tang singleton and volatile semantics.
+ * <p/>
+ * 2) In a second pass, Tang populates each of the InjectionFutures with the
+ * reference to the requested class that was instantiated in the first pass. If
+ * this reference does not exist (or is non-unique) then an InjectionException
+ * is thrown.
+ * <p/>
+ * Note: The semantics of complex cyclic injections may change over time.
+ * <p/>
+ * We haven't seen many complicated injections that involve cycles in practice.
+ * A second approach would be to establish some scoping rules, so that each
+ * InjectionFuture binds to the innermost matching parent in the InjectionPlan.
+ * This would allow plans to inject multiple cycles involving distinct objects
+ * of the same type.
+ *
+ * @param <T>
+ */
+
+public final class InjectionFuture<T> implements Future<T> {
+
+  protected final InjectorImpl injector;
+
+  private final Class<? extends T> iface;
+
+  private final T instance;
+
+  public InjectionFuture() {
+    injector = null;
+    iface = null;
+    instance = null;
+  }
+
+  public InjectionFuture(final Injector injector, Class<? extends T> iface) {
+    this.injector = (InjectorImpl) injector;
+    this.iface = iface;
+    this.instance = null;
+  }
+
+  public InjectionFuture(T instance) {
+    this.injector = null;
+    this.iface = null;
+    this.instance = instance;
+  }
+
+  @Override
+  public final boolean cancel(boolean mayInterruptIfRunning) {
+    return false;
+  }
+
+  @Override
+  public final boolean isCancelled() {
+    return false;
+  }
+
+  @Override
+  public final boolean isDone() {
+    return true;
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public T get() {
+    if (instance != null) return instance;
+    try {
+      synchronized (injector) {
+        final T t;
+        if (Name.class.isAssignableFrom(iface)) {
+          t = injector.getNamedInstance((Class<Name<T>>) iface);
+        } else {
+          t = injector.getInstance(iface);
+        }
+        Aspect a = injector.getAspect();
+        if (a != null) {
+          a.injectionFutureInstantiated(this, t);
+        }
+        return t;
+      }
+    } catch (InjectionException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  @Override
+  public T get(long timeout, TimeUnit unit) {
+    throw new UnsupportedOperationException();
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Injector.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Injector.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Injector.java
new file mode 100644
index 0000000..198f2f3
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Injector.java
@@ -0,0 +1,133 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.exceptions.NameResolutionException;
+import org.apache.reef.tang.implementation.InjectionPlan;
+
+public interface Injector {
+
+  /**
+   * Gets an instance of iface, or the implementation that has been bound to it.
+   * If an instance has alread been created in this (or a parent) scope, then
+   * the existing instance will be returned. Otherwise, a new instance will be
+   * returned, and registered in the current scope.
+   *
+   * @param iface
+   * @return
+   * @throws NameResolutionException
+   * @throws ReflectiveOperationException
+   */
+  public <U> U getInstance(Class<U> iface) throws InjectionException;
+
+  public <U> U getInstance(String iface) throws InjectionException,
+      NameResolutionException;
+
+  /**
+   * Gets the value stored for the given named parameter.
+   *
+   * @param <U>
+   * @param name
+   * @return an Instance of the class configured as the implementation for the
+   * given interface class.
+   * @throws InjectionException
+   */
+  public <U> U getNamedInstance(Class<? extends Name<U>> iface)
+      throws InjectionException;
+
+  /**
+   * Binds the given object to the class. Note that this only affects objects
+   * created by the returned Injector and its children. Also, like all
+   * Injectors, none of those objects can be serialized back to a configuration
+   * file).
+   *
+   * @param iface
+   * @param inst
+   * @return A copy of this injector that reflects the new binding.
+   * @throws BindException
+   */
+  public <T> void bindVolatileInstance(Class<T> iface, T inst)
+      throws BindException;
+
+  public <T> void bindVolatileParameter(Class<? extends Name<T>> iface, T inst)
+      throws BindException;
+
+  /**
+   * Binds a TANG Aspect to this injector.  Tang Aspects interpose on each
+   * injection performed by an injector, and return an instance of their choosing.
+   * <p/>
+   * A given aspect will be invoked once for each object that Tang injects, and aspects
+   * will be copied in a way that mirrors the scoping that Tang creates at runtime.
+   *
+   * @param a
+   * @throws BindException
+   */
+  public <T> void bindAspect(Aspect a) throws BindException;
+
+  /**
+   * Allows InjectionFuture to tell the aspect when get() is invoked.  Package private.
+   *
+   * @return
+   */
+  Aspect getAspect();
+
+  /**
+   * Create a copy of this Injector that inherits the instances that were already
+   * created by this Injector, but reflects additional Configuration objects.
+   * This can be used to create trees of Injectors that obey hierarchical
+   * scoping rules.
+   * <p/>
+   * <p/>
+   * Except for the fact that the child Injector will have references to this
+   * injector's instances, the returned Injector is equivalent to the one you
+   * would get by using ConfigurationBuilder to build a merged Configuration,
+   * and then using the merged Configuration to create an Injector. Injectors
+   * returned by ConfigurationBuilders are always independent, and never
+   * share references to the same instances of injected objects.
+   *
+   * @throws BindException If any of the configurations conflict with each other, or the
+   *                       existing Injector's Configuration.
+   */
+  public Injector forkInjector(Configuration... configurations) throws BindException;
+
+  /**
+   * Returns true if this Injector is able to instantiate the object named by
+   * name.
+   *
+   * @param name
+   * @return
+   * @throws BindException
+   */
+  boolean isInjectable(String name) throws BindException;
+
+  boolean isParameterSet(String name) throws BindException;
+
+  boolean isInjectable(Class<?> clazz) throws BindException;
+
+  boolean isParameterSet(Class<? extends Name<?>> name) throws BindException;
+
+  InjectionPlan<?> getInjectionPlan(String name) throws NameResolutionException;
+
+  <T> InjectionPlan<T> getInjectionPlan(Class<T> name);
+
+  Injector forkInjector();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/JavaClassHierarchy.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/JavaClassHierarchy.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/JavaClassHierarchy.java
new file mode 100644
index 0000000..27aa6cb
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/JavaClassHierarchy.java
@@ -0,0 +1,67 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.exceptions.ClassHierarchyException;
+import org.apache.reef.tang.exceptions.ParseException;
+import org.apache.reef.tang.types.NamedParameterNode;
+import org.apache.reef.tang.types.Node;
+
+public interface JavaClassHierarchy extends ClassHierarchy {
+  /**
+   * Look up a class object in this ClassHierarchy. Unlike the version that
+   * takes a string in ClassHierarchy, this version does not throw
+   * NameResolutionException.
+   * <p/>
+   * The behavior of this method is undefined if the provided Class object is
+   * not from the ClassLoader (or an ancestor of the ClassLoader) associated
+   * with this JavaClassHierarchy. By default, Tang uses the default runtime
+   * ClassLoader as its root ClassLoader, so static references (expressions like
+   * getNode(Foo.class)) are safe.
+   *
+   * @param c The class to be looked up in the class hierarchy.
+   * @return The associated NamedParameterNode or ClassNode.
+   */
+  public Node getNode(Class<?> c);
+
+  public Class<?> classForName(String name) throws ClassNotFoundException;
+
+  /**
+   * Parse a string value that has been passed into a named parameter.
+   *
+   * @param name  The named parameter that will receive the value.
+   * @param value A string value to be validated and parsed.
+   * @return An instance of T, or a ClassNode<? extends T>.
+   * @throws ParseException if the value failed to parse, or parsed to the
+   *                        wrong type (such as when it specifies a class that does not implement
+   *                        or extend T).
+   */
+  public <T> T parse(NamedParameterNode<T> name, String value) throws ParseException;
+
+  /**
+   * Obtain a parsed instance of the default value of a named parameter
+   *
+   * @param name The named parameter that should be checked for a default instance.
+   * @return The default instance or null, unless T is a set type.  If T is a set,
+   * then this method returns a (potentially empty) set of default instances.
+   * @throws ClassHierarchyException if an instance failed to parse.
+   */
+  public <T> T parseDefaultValue(NamedParameterNode<T> name) throws ClassHierarchyException;
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/JavaConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/JavaConfigurationBuilder.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/JavaConfigurationBuilder.java
new file mode 100644
index 0000000..ace0080
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/JavaConfigurationBuilder.java
@@ -0,0 +1,98 @@
+/**
+ * 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.reef.tang;
+
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.NameResolutionException;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Convenience methods that extend the ConfigurationBuilder but assume that
+ * the underlying ClassHierarchy delegates to the default Java classloader.
+ * <p/>
+ * In addition to being less verbose, this interface expresses many of Tang's
+ * type checks in Java's generic type system.  This improves IDE
+ * auto-completion.  It also allows the errors to be caught at compile time
+ * instead of later on in the build process, or at runtime.
+ *
+ * @see ConfigurationModule which pushes additional type checks to class load
+ * time.  This allows Tint, Tang's static analysis tool, to detect a wide
+ * range of runtime configuration errors at build time.
+ */
+public interface JavaConfigurationBuilder extends ConfigurationBuilder {
+
+  /**
+   * Bind named parameters, implementations or external constructors, depending
+   * on the types of the classes passed in.
+   *
+   * @param iface
+   * @param impl
+   */
+  public <T> JavaConfigurationBuilder bind(Class<T> iface, Class<?> impl) throws BindException;
+
+  /**
+   * Binds the Class impl as the implementation of the interface iface
+   *
+   * @param <T>
+   * @param iface
+   * @param impl
+   */
+  public <T> JavaConfigurationBuilder bindImplementation(Class<T> iface, Class<? extends T> impl)
+      throws BindException;
+
+
+  /**
+   * Set the value of a named parameter.
+   *
+   * @param name  The dummy class that serves as the name of this parameter.
+   * @param value A string representing the value of the parameter. Reef must know
+   *              how to parse the parameter's type.
+   * @throws NameResolutionException
+   */
+  public JavaConfigurationBuilder bindNamedParameter(Class<? extends Name<?>> name, String value)
+      throws BindException;
+
+  public <T> JavaConfigurationBuilder bindNamedParameter(Class<? extends Name<T>> iface,
+                                                         Class<? extends T> impl) throws BindException;
+
+  public <T> JavaConfigurationBuilder bindConstructor(Class<T> c,
+                                                      Class<? extends ExternalConstructor<? extends T>> v) throws BindException;
+
+  public <T> JavaConfigurationBuilder bindSetEntry(Class<? extends Name<Set<T>>> iface, String value) throws BindException;
+
+  public <T> JavaConfigurationBuilder bindSetEntry(Class<? extends Name<Set<T>>> iface, Class<? extends T> impl) throws BindException;
+
+  /**
+   * Binds a specfic list to a named parameter. List's elements can be string values or class implementations.
+   * Their type would be checked in this method. If their types are not applicable to the named parameter,
+   * it will make an exception.
+   *
+   * @param iface The target named parameter to be injected into
+   * @param impl  A concrete list
+   * @param <T>
+   * @return
+   * @throws BindException
+   */
+  public <T> JavaConfigurationBuilder bindList(Class<? extends Name<List<T>>> iface, List impl)
+      throws BindException;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Tang.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Tang.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Tang.java
new file mode 100644
index 0000000..3bba253
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/Tang.java
@@ -0,0 +1,149 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.implementation.TangImpl;
+
+import java.net.URL;
+
+/**
+ * The root factory interface for Tang.  This interface allows callers to
+ * instantiate Tang's core API, and is responsible for memoization and other
+ * runtime optimizations.
+ */
+public interface Tang {
+
+  /**
+   * Returns an Injector for the given Configurations.
+   *
+   * @throws BindException If the confs conflict, a BindException will be thrown.
+   */
+  public Injector newInjector(final Configuration... confs)
+      throws BindException;
+
+  /**
+   * Returns an Injector for the given Configuration.
+   */
+  public Injector newInjector(final Configuration confs);
+
+  /**
+   * Returns an Injector based on an empty Configuration.
+   */
+  public Injector newInjector();
+
+  /**
+   * Return a new ConfigurationBuilder that is backed by the provided
+   * ClassHierarchy object.
+   *
+   * @param ch Any valid Tang ClassHierarchy, including ones derived from non-Java application binaries.
+   * @return an instance of ConfigurationBuilder.  In Tang's default implementation this returns an instance or JavaConfigurationBuilder if ch is backed by a Java classloader.
+   */
+  public ConfigurationBuilder newConfigurationBuilder(ClassHierarchy ch);
+
+  /**
+   * Create a new ConfigurationBuilder that is backed by the default
+   * classloader and the provided jars.  Following standard Java's semantics,
+   * when looking up a class, Tang will consult the default classloader first,
+   * then the first classpath entry / jar passed to this method, then the
+   * second, and so on.
+   *
+   * @return a new JavaConfigurationBuilder
+   */
+  public JavaConfigurationBuilder newConfigurationBuilder(URL... jars);
+
+  /**
+   * Merge a set of configurations into a new JavaConfiurationBuilder.  If
+   * the configurations conflict, this method will throw a bind exception.
+   * <p/>
+   * The underlying ClassHierarchies and parameter parsers of the
+   * configurations will be checked for consistency.  The returned
+   * configuration builder will be backed by a ClassHierachy that incorporates
+   * the classpath and parsers from all of the provided Configurations.
+   *
+   * @return a new ConfigurationBuilder
+   * @throws BindException if any of the configurations contain duplicated or
+   *                       conflicting bindings, or if the backing ClassHierarchy objects conflict
+   *                       in some way.
+   */
+  public JavaConfigurationBuilder newConfigurationBuilder(Configuration... confs)
+      throws BindException;
+
+  /**
+   * Create an empty JavaConfigurationBuilder that is capable of parsing
+   * application-specific configuration values.  The returned
+   * JavaConfigurationBuilder will be backed by the default classloader.
+   *
+   * @return a new ConfigurationBuilder
+   */
+  public JavaConfigurationBuilder newConfigurationBuilder(@SuppressWarnings("unchecked") Class<? extends ExternalConstructor<?>>... parameterParsers)
+      throws BindException;
+
+  /**
+   * Create a new JavaConfiguration builder that has additional jars,
+   * incorporates existing configuration data and / or can parse
+   * application-specific types.
+   *
+   * @see The documentation for the other newConfigurationBuilder methods in
+   * this class for detailed information about each of the parameters to
+   * this method.
+   */
+  public JavaConfigurationBuilder newConfigurationBuilder(URL[] jars,
+                                                          Configuration[] confs, Class<? extends ExternalConstructor<?>>[] parameterParsers) throws BindException;
+
+  /**
+   * Create a new empty ConfigurationBuilder that is backed by the default
+   * classloader.
+   */
+  public JavaConfigurationBuilder newConfigurationBuilder();
+
+  /**
+   * @return an instance of JavaClassHierarchy that is backed by the default
+   * Java classloader.  ClassHierarchy objects are immutable, so multiple
+   * invocations of this method may return the same instance.
+   */
+  public JavaClassHierarchy getDefaultClassHierarchy();
+
+  /**
+   * @return a custom instance of JavaClassHierarchy.  ClassHierarchy objects
+   * are immutable, so multiple invocations of this method may return the
+   * same instance.
+   * @TODO Is the class hierarchy returned here backed by the default
+   * classloader or not?  If not, then callers will need to merge it with
+   * getDefaultClassHierarchy().  If so, we should add a new method like
+   * getNonDefaultClassHiearchy() that takes the same options as this one.
+   */
+  public JavaClassHierarchy getDefaultClassHierarchy(URL[] jars, Class<? extends ExternalConstructor<?>>[] parsers);
+
+  /**
+   * A factory that returns the default implementation of the Tang interface.
+   */
+  public final class Factory {
+    /**
+     * Return an instance of the default implementation of Tang.
+     *
+     * @return
+     */
+    public static Tang getTang() {
+      return new TangImpl();
+    }
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/DefaultImplementation.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/DefaultImplementation.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/DefaultImplementation.java
new file mode 100644
index 0000000..cfeb13b
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/DefaultImplementation.java
@@ -0,0 +1,42 @@
+/**
+ * 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.reef.tang.annotations;
+
+import java.lang.annotation.*;
+
+/**
+ * Allows interfaces to specify a default implementation.
+ * <p/>
+ * Note that the default can be overridden after the fact
+ * by explicitly binding a different implementation to the
+ * interface.
+ * <p/>
+ * For "normal" injections of a given library, this reduces
+ * the amount of boilerplate configuration code needed,
+ * and also shrinks the Tang configuration objects that
+ * need to be passed around.
+ */
+@Target(ElementType.TYPE)
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+public @interface DefaultImplementation {
+  Class<?> value() default Void.class;
+
+  String name() default "";
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/Name.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/Name.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/Name.java
new file mode 100644
index 0000000..f450e1f
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/Name.java
@@ -0,0 +1,23 @@
+/**
+ * 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.reef.tang.annotations;
+
+public interface Name<T> {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/NamedParameter.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/NamedParameter.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/NamedParameter.java
new file mode 100644
index 0000000..2b400f1
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/NamedParameter.java
@@ -0,0 +1,40 @@
+/**
+ * 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.reef.tang.annotations;
+
+import java.lang.annotation.*;
+
+@Target(ElementType.TYPE)
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+public @interface NamedParameter {
+  //Class<?> type() default String.class;
+  String doc() default "";
+
+  String short_name() default "";
+
+  // One of the following should be set.
+  String default_value() default "";
+
+  Class<?> default_class() default Void.class;
+
+  String[] default_values() default {};
+
+  Class<?>[] default_classes() default {};
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/Parameter.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/Parameter.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/Parameter.java
new file mode 100644
index 0000000..543843e
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/Parameter.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.tang.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+@Target(ElementType.PARAMETER)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Parameter {
+  Class<? extends Name<? extends Object>> value();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/Unit.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/Unit.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/Unit.java
new file mode 100644
index 0000000..093069c
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/Unit.java
@@ -0,0 +1,47 @@
+/**
+ * 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.reef.tang.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * A TANG Unit consists of an outer class and some non-static inner classes.
+ * TANG injectors automatically treat all the classes in a unit as singletons.
+ * <p/>
+ * In order to inject the singleton instance of each inner class, TANG first
+ * instantiates the outer class and then uses the resulting instance to
+ * instantiate each inner class.
+ * <p/>
+ * Classes annotated in this way must have at least one non-static inner class
+ * and no static inner classes. The inner classes must not declare any
+ * constructors.
+ * <p/>
+ * Furthermore, classes annotated with Unit may not have injectable (or Unit)
+ * subclasses.
+ *
+ * @author sears
+ */
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Unit {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/package-info.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/package-info.java
new file mode 100644
index 0000000..b8d11f2
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/annotations/package-info.java
@@ -0,0 +1,23 @@
+/**
+ * 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.
+ */
+/**
+ Annotations that application developers can use to register configuration
+ metadata with Tang.
+ */
+package org.apache.reef.tang.annotations;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/PrintTypeHierarchy.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/PrintTypeHierarchy.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/PrintTypeHierarchy.java
new file mode 100644
index 0000000..1f60718
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/PrintTypeHierarchy.java
@@ -0,0 +1,105 @@
+/**
+ * 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.reef.tang.examples;
+
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.ConfigurationBuilder;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.CommandLine;
+import org.apache.reef.tang.implementation.InjectionPlan;
+import org.apache.reef.tang.util.walk.graphviz.GraphvizConfigVisitor;
+import org.apache.reef.tang.util.walk.graphviz.GraphvizInjectionPlanVisitor;
+
+import javax.inject.Inject;
+import java.io.FileWriter;
+import java.io.IOException;
+
+/**
+ * Build a Graphviz representation of TANG configuration and injection plan.
+ */
+public final class PrintTypeHierarchy {
+
+  /**
+   * Parameter to test the injection.
+   */
+  private final transient int id;
+
+  /**
+   * Constructor to test the parameter injection.
+   *
+   * @param aId test parameter
+   */
+  @Inject
+  public PrintTypeHierarchy(@Parameter(PrintTypeHierarchy.Id.class) final int id) {
+    this.id = id;
+  }
+
+  /**
+   * @param args command line arguments.
+   * @throws BindException      configuration error.
+   * @throws InjectionException configuration error.
+   * @throws IOException        cannot process command line parameters.
+   */
+  public static void main(final String[] args)
+      throws BindException, InjectionException, IOException {
+
+    final Tang tang = Tang.Factory.getTang();
+    final ConfigurationBuilder confBuilder = tang.newConfigurationBuilder();
+
+    new CommandLine(confBuilder).processCommandLine(args);
+    final Configuration config = confBuilder.build();
+
+    final Injector injector = tang.newInjector(config);
+    final PrintTypeHierarchy myself = injector.getInstance(PrintTypeHierarchy.class);
+
+    try (final FileWriter out = new FileWriter("type-hierarchy.dot")) {
+      out.write(GraphvizConfigVisitor.getGraphvizString(config, true, true));
+    }
+
+    final InjectionPlan<PrintTypeHierarchy> plan =
+        injector.getInjectionPlan(PrintTypeHierarchy.class);
+
+    try (final FileWriter out = new FileWriter("injection-plan.dot")) {
+      out.write(GraphvizInjectionPlanVisitor.getGraphvizString(plan, true));
+    }
+
+    System.out.println(myself);
+  }
+
+  /**
+   * @return string representation of the object.
+   */
+  @Override
+  public String toString() {
+    return this.getClass().getName() + " :: " + this.id;
+  }
+
+  /**
+   * Parameter to test the injection.
+   */
+  @NamedParameter(default_value = "999", doc = "Test parameter", short_name = "id")
+  class Id implements Name<Integer> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/Timer.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/Timer.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/Timer.java
new file mode 100644
index 0000000..5cc5e34
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/Timer.java
@@ -0,0 +1,73 @@
+/**
+ * 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.reef.tang.examples;
+
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.formats.CommandLine;
+import org.apache.reef.tang.formats.ConfigurationFile;
+import org.apache.reef.tang.implementation.InjectionPlan;
+import org.apache.reef.tang.implementation.java.InjectorImpl;
+
+import javax.inject.Inject;
+
+public class Timer {
+  private final int seconds;
+
+  @Inject
+  public Timer(@Parameter(Seconds.class) int seconds) {
+    if (seconds < 0) {
+      throw new IllegalArgumentException("Cannot sleep for negative time!");
+    }
+    this.seconds = seconds;
+  }
+
+  public static void main(String[] args) throws Exception {
+    Tang tang = Tang.Factory.getTang();
+    JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
+    CommandLine cl = new CommandLine(cb);
+    cl.registerShortNameOfClass(Timer.Seconds.class);
+    cl.processCommandLine(args);
+    Configuration conf = cb.build();
+    System.out.println("start conf");
+    System.out.println(ConfigurationFile.toConfigurationString(conf));
+    System.out.println("end conf");
+    InjectorImpl injector = (InjectorImpl) tang.newInjector(conf);
+    InjectionPlan<Timer> ip = injector.getInjectionPlan(Timer.class);
+    System.out.println(ip.toPrettyString());
+    System.out.println("Number of plans:" + ip.getNumAlternatives());
+    Timer timer = injector.getInstance(Timer.class);
+    System.out.println("Tick...");
+    timer.sleep();
+    System.out.println("Tock.");
+  }
+
+  public void sleep() throws InterruptedException {
+    java.lang.Thread.sleep(seconds * 1000);
+  }
+
+  @NamedParameter(default_value = "10",
+      doc = "Number of seconds to sleep", short_name = "sec")
+  class Seconds implements Name<Integer> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/TimerV1.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/TimerV1.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/TimerV1.java
new file mode 100644
index 0000000..fca0635
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/TimerV1.java
@@ -0,0 +1,66 @@
+/**
+ * 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.reef.tang.examples;
+
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+
+import javax.inject.Inject;
+
+public class TimerV1 {
+
+  private final int seconds;
+
+  @Inject
+  public TimerV1(@Parameter(Seconds.class) int seconds) {
+    this.seconds = seconds;
+  }
+
+  public static void main(String[] args) throws BindException, InjectionException {
+    Tang tang = Tang.Factory.getTang();
+    JavaConfigurationBuilder cb = (JavaConfigurationBuilder) tang.newConfigurationBuilder();
+    Configuration conf = cb.build();
+    Injector injector = tang.newInjector(conf);
+    TimerV1 timer = injector.getInstance(TimerV1.class);
+
+    try {
+      System.out.println("Tick...");
+      timer.sleep();
+      System.out.println("Tock.");
+    } catch (InterruptedException e) {
+      e.printStackTrace();
+    }
+  }
+
+  public void sleep() throws InterruptedException {
+    java.lang.Thread.sleep(seconds * 1000);
+  }
+
+  @NamedParameter(default_value = "10",
+      doc = "Number of seconds to sleep", short_name = "sec")
+  class Seconds implements Name<Integer> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/package-info.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/package-info.java
new file mode 100644
index 0000000..d0b62aa
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Example code from the tutorial on Tang's home page.
+ */
+package org.apache.reef.tang.examples;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/timer/Timer.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/timer/Timer.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/timer/Timer.java
new file mode 100644
index 0000000..b1bed6e
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/timer/Timer.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.tang.examples.timer;
+
+import org.apache.reef.tang.annotations.DefaultImplementation;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+@DefaultImplementation(TimerImpl.class)
+public interface Timer {
+  public void sleep() throws Exception;
+
+  @NamedParameter(default_value = "10",
+      doc = "Number of seconds to sleep", short_name = "sec")
+  public static class Seconds implements Name<Integer> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/timer/TimerImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/timer/TimerImpl.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/timer/TimerImpl.java
new file mode 100644
index 0000000..09f990c
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/timer/TimerImpl.java
@@ -0,0 +1,42 @@
+/**
+ * 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.reef.tang.examples.timer;
+
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+
+public class TimerImpl implements Timer {
+
+  private final int seconds;
+
+  @Inject
+  public TimerImpl(@Parameter(Timer.Seconds.class) int seconds) {
+    if (seconds < 0) {
+      throw new IllegalArgumentException("Cannot sleep for negative time!");
+    }
+    this.seconds = seconds;
+  }
+
+  @Override
+  public void sleep() throws Exception {
+    java.lang.Thread.sleep(seconds);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/timer/TimerMock.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/timer/TimerMock.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/timer/TimerMock.java
new file mode 100644
index 0000000..fe8b41c
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/timer/TimerMock.java
@@ -0,0 +1,66 @@
+/**
+ * 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.reef.tang.examples.timer;
+
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.OptionalParameter;
+
+import javax.inject.Inject;
+
+public class TimerMock implements Timer {
+
+  public static final ConfigurationModule CONF = new TimerMockConf()
+      .bindImplementation(Timer.class, TimerMock.class)
+      .bindNamedParameter(Timer.Seconds.class, TimerMockConf.MOCK_SLEEP_TIME)
+      .build();
+  private final int seconds;
+
+  @Inject
+  TimerMock(@Parameter(Timer.Seconds.class) int seconds) {
+    if (seconds < 0) {
+      throw new IllegalArgumentException("Cannot sleep for negative time!");
+    }
+    this.seconds = seconds;
+  }
+
+  public static void main(String[] args) throws BindException, InjectionException, Exception {
+    Configuration c = TimerMock.CONF
+        .set(TimerMockConf.MOCK_SLEEP_TIME, 1)
+        .build();
+    Timer t = Tang.Factory.getTang().newInjector(c).getInstance(Timer.class);
+    System.out.println("Tick...");
+    t.sleep();
+    System.out.println("...tock.");
+  }
+
+  @Override
+  public void sleep() {
+    System.out.println("Would have slept for " + seconds + "sec.");
+  }
+
+  public static class TimerMockConf extends ConfigurationModuleBuilder {
+    public static final OptionalParameter<Integer> MOCK_SLEEP_TIME = new OptionalParameter<>();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/timer/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/timer/package-info.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/timer/package-info.java
new file mode 100644
index 0000000..765dab9
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/examples/timer/package-info.java
@@ -0,0 +1,23 @@
+/**
+ * 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.
+ */
+/**
+ *  A more complicated version of the Timer example, including delegating
+ *  interfaces to default implementations. 
+ */
+package org.apache.reef.tang.examples.timer;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/BindException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/BindException.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/BindException.java
new file mode 100644
index 0000000..996b344
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/BindException.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.tang.exceptions;
+
+/**
+ * Thrown when an illegal or contradictory configuration option is encountered.
+ * <p/>
+ * While binding configuration values and merging Configuration objects, Tang
+ * checks each configuration option to make sure that it is correctly typed,
+ * and that it does not override some other setting (even if the two settings
+ * bind the same configuration option to the same value).  When a bad
+ * configuration option is encountered, a BindException is thrown.
+ *
+ * @see NameResolutionException which covers the special case where an unknown
+ * configuration option or class is encountered.
+ */
+public class BindException extends RuntimeException {
+  private static final long serialVersionUID = 1L;
+
+  public BindException(String msg, Throwable cause) {
+    super(msg, cause);
+  }
+
+  public BindException(String msg) {
+    super(msg);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/ClassHierarchyException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/ClassHierarchyException.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/ClassHierarchyException.java
new file mode 100644
index 0000000..c16722a
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/ClassHierarchyException.java
@@ -0,0 +1,40 @@
+/**
+ * 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.reef.tang.exceptions;
+
+/**
+ * This exception is thrown when Tang detects improper or inconsistent class
+ * annotations.  This is a runtime exception because it denotes a problem that
+ * existed during compilation.
+ */
+public class ClassHierarchyException extends RuntimeException {
+  private static final long serialVersionUID = 1L;
+
+  public ClassHierarchyException(Throwable cause) {
+    super(cause);
+  }
+
+  public ClassHierarchyException(String msg) {
+    super(msg);
+  }
+
+  public ClassHierarchyException(String msg, Throwable cause) {
+    super(msg, cause);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/InjectionException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/InjectionException.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/InjectionException.java
new file mode 100644
index 0000000..6b93923
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/exceptions/InjectionException.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.tang.exceptions;
+
+/**
+ * Thrown when an injection fails.  Injections commonly fail for two reasons.
+ * The first is that the InjectionPlan that Tang produced is ambiguous or
+ * infeasible.  The second is that a constructor invoked by Tang itself threw
+ * an exception.
+ * <p/>
+ * A third, less common issue arises when constructors obtain a handle to the
+ * Tang Injector that created them, and then attempt to modify its state.
+ * Doing so is illegal, and results in a runtime exception that Tang converts
+ * into an InjectionException.  Code involved in such exceptions is typically
+ * attempting to perform cyclic object injections, and should use an
+ * InjectionFuture instead.
+ */
+public class InjectionException extends Exception {
+  private static final long serialVersionUID = 1L;
+
+  public InjectionException(String msg, Throwable cause) {
+    super(msg, cause);
+  }
+
+  public InjectionException(String msg) {
+    super(msg);
+  }
+}


[38/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/package-info.java
new file mode 100644
index 0000000..cc60934
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/defaults/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Default implementations for the optional driver-side event handlers.
+ */
+package org.apache.reef.runtime.common.driver.defaults;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/AllocatedEvaluatorImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/AllocatedEvaluatorImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/AllocatedEvaluatorImpl.java
new file mode 100644
index 0000000..462d6c9
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/AllocatedEvaluatorImpl.java
@@ -0,0 +1,224 @@
+/**
+ * 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.reef.runtime.common.driver.evaluator;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorDescriptor;
+import org.apache.reef.driver.evaluator.EvaluatorType;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.evaluator.EvaluatorConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationSerializer;
+import org.apache.reef.util.Optional;
+import org.apache.reef.util.logging.LoggingScope;
+import org.apache.reef.util.logging.LoggingScopeFactory;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Driver-Side representation of an allocated evaluator.
+ */
+@DriverSide
+@Private
+final class AllocatedEvaluatorImpl implements AllocatedEvaluator {
+
+  private final static Logger LOG = Logger.getLogger(AllocatedEvaluatorImpl.class.getName());
+
+  private final EvaluatorManager evaluatorManager;
+  private final String remoteID;
+  private final ConfigurationSerializer configurationSerializer;
+  private final String jobIdentifier;
+  private final LoggingScopeFactory loggingScopeFactory;
+
+  /**
+   * The set of files to be places on the Evaluator.
+   */
+  private final Collection<File> files = new HashSet<>();
+  /**
+   * The set of libraries
+   */
+  private final Collection<File> libraries = new HashSet<>();
+
+  AllocatedEvaluatorImpl(final EvaluatorManager evaluatorManager,
+                         final String remoteID,
+                         final ConfigurationSerializer configurationSerializer,
+                         final String jobIdentifier,
+                         final LoggingScopeFactory loggingScopeFactory) {
+    this.evaluatorManager = evaluatorManager;
+    this.remoteID = remoteID;
+    this.configurationSerializer = configurationSerializer;
+    this.jobIdentifier = jobIdentifier;
+    this.loggingScopeFactory = loggingScopeFactory;
+  }
+
+  @Override
+  public String getId() {
+    return this.evaluatorManager.getId();
+  }
+
+  @Override
+  public void close() {
+    this.evaluatorManager.close();
+  }
+
+  @Override
+  public void submitTask(final Configuration taskConfiguration) {
+    final Configuration contextConfiguration = ContextConfiguration.CONF
+        .set(ContextConfiguration.IDENTIFIER, "RootContext_" + this.getId())
+        .build();
+    this.submitContextAndTask(contextConfiguration, taskConfiguration);
+
+  }
+
+  @Override
+  public EvaluatorDescriptor getEvaluatorDescriptor() {
+    return this.evaluatorManager.getEvaluatorDescriptor();
+  }
+
+
+  @Override
+  public void submitContext(final Configuration contextConfiguration) {
+    launch(contextConfiguration, Optional.<Configuration>empty(), Optional.<Configuration>empty());
+  }
+
+  @Override
+  public void submitContextAndService(final Configuration contextConfiguration,
+                                      final Configuration serviceConfiguration) {
+    launch(contextConfiguration, Optional.of(serviceConfiguration), Optional.<Configuration>empty());
+  }
+
+  @Override
+  public void submitContextAndTask(final Configuration contextConfiguration,
+                                   final Configuration taskConfiguration) {
+    launch(contextConfiguration, Optional.<Configuration>empty(), Optional.of(taskConfiguration));
+  }
+
+  @Override
+  public void submitContextAndServiceAndTask(final Configuration contextConfiguration,
+                                             final Configuration serviceConfiguration,
+                                             final Configuration taskConfiguration) {
+    launch(contextConfiguration, Optional.of(serviceConfiguration), Optional.of(taskConfiguration));
+  }
+
+  @Override
+  public void setType(final EvaluatorType type) {
+    this.evaluatorManager.setType(type);
+  }
+
+  @Override
+  public void addFile(final File file) {
+    this.files.add(file);
+  }
+
+  @Override
+  public void addLibrary(final File file) {
+    this.libraries.add(file);
+  }
+
+  private final void launch(final Configuration contextConfiguration,
+                            final Optional<Configuration> serviceConfiguration,
+                            final Optional<Configuration> taskConfiguration) {
+    try (final LoggingScope lb = loggingScopeFactory.evaluatorLaunch(this.getId())) {
+      try {
+        final ConfigurationModule evaluatorConfigurationModule = EvaluatorConfiguration.CONF
+            .set(EvaluatorConfiguration.APPLICATION_IDENTIFIER, this.jobIdentifier)
+            .set(EvaluatorConfiguration.DRIVER_REMOTE_IDENTIFIER, this.remoteID)
+            .set(EvaluatorConfiguration.EVALUATOR_IDENTIFIER, this.getId());
+
+        final String encodedContextConfigurationString = this.configurationSerializer.toString(contextConfiguration);
+        // Add the (optional) service configuration
+        final ConfigurationModule contextConfigurationModule;
+        if (serviceConfiguration.isPresent()) {
+          // With service configuration
+          final String encodedServiceConfigurationString = this.configurationSerializer.toString(serviceConfiguration.get());
+          contextConfigurationModule = evaluatorConfigurationModule
+              .set(EvaluatorConfiguration.ROOT_SERVICE_CONFIGURATION, encodedServiceConfigurationString)
+              .set(EvaluatorConfiguration.ROOT_CONTEXT_CONFIGURATION, encodedContextConfigurationString);
+        } else {
+          // No service configuration
+          contextConfigurationModule = evaluatorConfigurationModule
+              .set(EvaluatorConfiguration.ROOT_CONTEXT_CONFIGURATION, encodedContextConfigurationString);
+        }
+
+        // Add the (optional) task configuration
+        final Configuration evaluatorConfiguration;
+        if (taskConfiguration.isPresent()) {
+          final String encodedTaskConfigurationString = this.configurationSerializer.toString(taskConfiguration.get());
+          evaluatorConfiguration = contextConfigurationModule
+              .set(EvaluatorConfiguration.TASK_CONFIGURATION, encodedTaskConfigurationString).build();
+        } else {
+          evaluatorConfiguration = contextConfigurationModule.build();
+        }
+
+        final DriverRuntimeProtocol.ResourceLaunchProto.Builder rbuilder =
+            DriverRuntimeProtocol.ResourceLaunchProto.newBuilder()
+                .setIdentifier(this.evaluatorManager.getId())
+                .setRemoteId(this.remoteID)
+                .setEvaluatorConf(configurationSerializer.toString(evaluatorConfiguration));
+
+        for (final File file : this.files) {
+          rbuilder.addFile(ReefServiceProtos.FileResourceProto.newBuilder()
+              .setName(file.getName())
+              .setPath(file.getPath())
+              .setType(ReefServiceProtos.FileType.PLAIN)
+              .build());
+        }
+
+        for (final File lib : this.libraries) {
+          rbuilder.addFile(ReefServiceProtos.FileResourceProto.newBuilder()
+              .setName(lib.getName())
+              .setPath(lib.getPath().toString())
+              .setType(ReefServiceProtos.FileType.LIB)
+              .build());
+        }
+
+        { // Set the type
+          switch (this.evaluatorManager.getEvaluatorDescriptor().getType()) {
+            case CLR:
+              rbuilder.setType(ReefServiceProtos.ProcessType.CLR);
+              break;
+            default:
+              rbuilder.setType(ReefServiceProtos.ProcessType.JVM);
+          }
+        }
+
+        this.evaluatorManager.onResourceLaunch(rbuilder.build());
+
+      } catch (final BindException ex) {
+        LOG.log(Level.SEVERE, "Bad Evaluator configuration", ex);
+        throw new RuntimeException("Bad Evaluator configuration", ex);
+      }
+    }
+  }
+
+  @Override
+  public String toString() {
+    return "AllocatedEvaluator{ID='" + getId() + "\'}";
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/CompletedEvaluatorImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/CompletedEvaluatorImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/CompletedEvaluatorImpl.java
new file mode 100644
index 0000000..78e4446
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/CompletedEvaluatorImpl.java
@@ -0,0 +1,49 @@
+/**
+ * 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.reef.runtime.common.driver.evaluator;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.evaluator.CompletedEvaluator;
+
+/**
+ * Implementation of CompletedEvaluator.
+ */
+@DriverSide
+@Private
+final class CompletedEvaluatorImpl implements CompletedEvaluator {
+
+  private final String id;
+
+  CompletedEvaluatorImpl(final String id) {
+    this.id = id;
+  }
+
+  @Override
+  public String getId() {
+    return this.id;
+  }
+
+  @Override
+  public String toString() {
+    return "CompletedEvaluator{" +
+        "id='" + id + '\'' +
+        '}';
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorControlHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorControlHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorControlHandler.java
new file mode 100644
index 0000000..ce62027
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorControlHandler.java
@@ -0,0 +1,100 @@
+/**
+ * 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.reef.runtime.common.driver.evaluator;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.EvaluatorRuntimeProtocol;
+import org.apache.reef.runtime.common.utils.RemoteManager;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This class handles the sending of Evaluator control messages to the Evaluator.
+ */
+@DriverSide
+@Private
+public final class EvaluatorControlHandler {
+
+  private static Logger LOG = Logger.getLogger(EvaluatorControlHandler.class.getName());
+  private final EvaluatorStatusManager stateManager;
+  private final RemoteManager remoteManager;
+  private final String evaluatorId;
+  private Optional<EventHandler<EvaluatorRuntimeProtocol.EvaluatorControlProto>> wrapped = Optional.empty();
+
+  /**
+   * @param stateManager  used to check whether the Evaluator is running before sending a message.
+   * @param remoteManager used to establish the communications link as soon as the remote ID has been set.
+   */
+  @Inject
+  EvaluatorControlHandler(final EvaluatorStatusManager stateManager,
+                          final RemoteManager remoteManager,
+                          final @Parameter(EvaluatorManager.EvaluatorIdentifier.class) String evaluatorId) {
+    this.stateManager = stateManager;
+    this.remoteManager = remoteManager;
+    this.evaluatorId = evaluatorId;
+    LOG.log(Level.FINE, "Instantiated 'EvaluatorControlHandler'");
+  }
+
+  /**
+   * Send the evaluatorControlProto to the Evaluator.
+   *
+   * @param evaluatorControlProto
+   * @throws java.lang.IllegalStateException if the remote ID hasn't been set via setRemoteID() prior to this call
+   * @throws java.lang.IllegalStateException if the Evaluator isn't running.
+   */
+  public synchronized void send(final EvaluatorRuntimeProtocol.EvaluatorControlProto evaluatorControlProto) {
+    if (!this.wrapped.isPresent()) {
+      throw new IllegalStateException("Trying to send an EvaluatorControlProto before the Evaluator ID is set.");
+    }
+    if (!this.stateManager.isRunning()) {
+      final String msg = new StringBuilder()
+          .append("Trying to send an EvaluatorControlProto to Evaluator [")
+          .append(this.evaluatorId)
+          .append("] that is in state [")
+          .append(this.stateManager.toString())
+          .append("], not [RUNNING]. The control message was: ")
+          .append(evaluatorControlProto.toString())
+          .toString();
+      throw new IllegalStateException(msg);
+    }
+    this.wrapped.get().onNext(evaluatorControlProto);
+  }
+
+  /**
+   * Set the remote ID used to communicate with this Evaluator.
+   *
+   * @param evaluatorRID
+   * @throws java.lang.IllegalStateException if the remote ID has been set before.
+   */
+  synchronized void setRemoteID(final String evaluatorRID) {
+    if (this.wrapped.isPresent()) {
+      throw new IllegalStateException("Trying to reset the evaluator ID. This isn't supported.");
+    } else {
+      LOG.log(Level.FINE, "Registering remoteId [{0}] for Evaluator [{1}]", new Object[]{evaluatorRID, evaluatorId});
+      this.wrapped = Optional.of(remoteManager.getHandler(evaluatorRID, EvaluatorRuntimeProtocol.EvaluatorControlProto.class));
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorDescriptorImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorDescriptorImpl.java
new file mode 100644
index 0000000..1a0bbcc
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorDescriptorImpl.java
@@ -0,0 +1,75 @@
+/**
+ * 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.reef.runtime.common.driver.evaluator;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.catalog.NodeDescriptor;
+import org.apache.reef.driver.evaluator.EvaluatorDescriptor;
+import org.apache.reef.driver.evaluator.EvaluatorType;
+
+/**
+ * A simple all-data implementation of EvaluatorDescriptor
+ */
+@Private
+@DriverSide
+final class EvaluatorDescriptorImpl implements EvaluatorDescriptor {
+
+  private final NodeDescriptor nodeDescriptor;
+  private final int megaBytes;
+  private final int numberOfCores;
+  private EvaluatorType type;
+
+  public EvaluatorDescriptorImpl(final NodeDescriptor nodeDescriptor,
+                                 final EvaluatorType type,
+                                 final int megaBytes,
+                                 final int numberOfCores) {
+    this.nodeDescriptor = nodeDescriptor;
+    this.type = type;
+    this.megaBytes = megaBytes;
+    this.numberOfCores = numberOfCores;
+  }
+
+  @Override
+  public NodeDescriptor getNodeDescriptor() {
+    return this.nodeDescriptor;
+  }
+
+  @Override
+  public synchronized EvaluatorType getType() {
+    return this.type;
+  }
+
+  public synchronized void setType(final EvaluatorType type) {
+    if (this.getType() != EvaluatorType.UNDECIDED) {
+      throw new RuntimeException("Unable to change state of an Evaluator of Type: " + this.getType());
+    }
+    this.type = type;
+  }
+
+  @Override
+  public int getMemory() {
+    return this.megaBytes;
+  }
+
+  @Override
+  public int getNumberOfCores() {
+    return this.numberOfCores;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorHeartBeatSanityChecker.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorHeartBeatSanityChecker.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorHeartBeatSanityChecker.java
new file mode 100644
index 0000000..09d8088
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorHeartBeatSanityChecker.java
@@ -0,0 +1,57 @@
+/**
+ * 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.reef.runtime.common.driver.evaluator;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+
+import javax.inject.Inject;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Sanity checks for evaluator heartbeats.
+ */
+@DriverSide
+@Private
+final class EvaluatorHeartBeatSanityChecker {
+  private static final Logger LOG = Logger.getLogger(EvaluatorHeartBeatSanityChecker.class.getName());
+  private final Map<String, Long> knownTimeStamps = new HashMap<>(); // guarded by this
+
+  @Inject
+  EvaluatorHeartBeatSanityChecker() {
+  }
+
+  final synchronized void check(final String id, final long timeStamp) {
+    if (knownTimeStamps.containsKey(id)) {
+      final long oldTimeStamp = this.knownTimeStamps.get(id);
+      LOG.log(Level.FINEST, "TIMESTAMP CHECKER: id [ " + id + " ], old timestamp [ " + oldTimeStamp + " ], new timestamp [ " + timeStamp + " ]");
+      if (oldTimeStamp > timeStamp) {
+        final String msg = "Received an old heartbeat with timestamp `" + timeStamp +
+            "` while earlier receiving one with timestamp `" + oldTimeStamp + "`";
+        LOG.log(Level.SEVERE, msg);
+        throw new RuntimeException(msg);
+      }
+    }
+    knownTimeStamps.put(id, timeStamp);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorHeartbeatHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorHeartbeatHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorHeartbeatHandler.java
new file mode 100644
index 0000000..c90098f
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorHeartbeatHandler.java
@@ -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.reef.runtime.common.driver.evaluator;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.EvaluatorRuntimeProtocol;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.RemoteMessage;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Receives heartbeats from all Evaluators and dispatches them to the right EvaluatorManager instance.
+ */
+@Private
+@DriverSide
+public final class EvaluatorHeartbeatHandler implements EventHandler<RemoteMessage<EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto>> {
+  private static final Logger LOG = Logger.getLogger(EvaluatorHeartbeatHandler.class.getName());
+  private final Evaluators evaluators;
+  private final EvaluatorManagerFactory evaluatorManagerFactory;
+
+  @Inject
+  EvaluatorHeartbeatHandler(final Evaluators evaluators, final EvaluatorManagerFactory evaluatorManagerFactory) {
+    this.evaluators = evaluators;
+    this.evaluatorManagerFactory = evaluatorManagerFactory;
+  }
+
+  @Override
+  public void onNext(final RemoteMessage<EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto> evaluatorHeartbeatMessage) {
+    final EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto heartbeat = evaluatorHeartbeatMessage.getMessage();
+    final ReefServiceProtos.EvaluatorStatusProto status = heartbeat.getEvaluatorStatus();
+    final String evaluatorId = status.getEvaluatorId();
+
+    LOG.log(Level.FINEST, "TIME: Begin Heartbeat {0}", evaluatorId);
+    LOG.log(Level.FINEST, "Heartbeat from Evaluator {0} with state {1} timestamp {2} from remoteId {3}",
+        new Object[]{evaluatorId, status.getState(), heartbeat.getTimestamp(), evaluatorHeartbeatMessage.getIdentifier()});
+
+    final Optional<EvaluatorManager> evaluatorManager = this.evaluators.get(evaluatorId);
+    if (evaluatorManager.isPresent()) {
+      evaluatorManager.get().onEvaluatorHeartbeatMessage(evaluatorHeartbeatMessage);
+    } else {
+      final StringBuilder message = new StringBuilder("Contact from unknown Evaluator with identifier '");
+      message.append(evaluatorId);
+      if (heartbeat.hasEvaluatorStatus()) {
+        message.append("' with state '");
+        message.append(status.getState());
+      }
+      message.append('\'');
+      throw new RuntimeException(message.toString());
+    }
+    LOG.log(Level.FINEST, "TIME: End Heartbeat {0}", evaluatorId);
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorManager.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorManager.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorManager.java
new file mode 100644
index 0000000..3938e06
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorManager.java
@@ -0,0 +1,529 @@
+/**
+ * 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.reef.runtime.common.driver.evaluator;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorDescriptor;
+import org.apache.reef.driver.evaluator.EvaluatorType;
+import org.apache.reef.driver.task.FailedTask;
+import org.apache.reef.exception.EvaluatorException;
+import org.apache.reef.exception.EvaluatorKilledByResourceManagerException;
+import org.apache.reef.io.naming.Identifiable;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.proto.EvaluatorRuntimeProtocol;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.DriverRestartCompleted;
+import org.apache.reef.runtime.common.driver.DriverStatusManager;
+import org.apache.reef.runtime.common.driver.api.ResourceLaunchHandler;
+import org.apache.reef.runtime.common.driver.api.ResourceReleaseHandler;
+import org.apache.reef.runtime.common.driver.context.ContextControlHandler;
+import org.apache.reef.runtime.common.driver.context.ContextRepresenters;
+import org.apache.reef.runtime.common.driver.idle.EventHandlerIdlenessSource;
+import org.apache.reef.runtime.common.driver.task.TaskRepresenter;
+import org.apache.reef.runtime.common.utils.ExceptionCodec;
+import org.apache.reef.runtime.common.utils.RemoteManager;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.formats.ConfigurationSerializer;
+import org.apache.reef.util.Optional;
+import org.apache.reef.util.logging.LoggingScopeFactory;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.RemoteMessage;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.event.Alarm;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Manages a single Evaluator instance including all lifecycle instances:
+ * (AllocatedEvaluator, CompletedEvaluator, FailedEvaluator).
+ * <p/>
+ * A (periodic) heartbeat channel is established EvaluatorRuntime -> EvaluatorManager.
+ * The EvaluatorRuntime will (periodically) send (status) messages to the EvaluatorManager using this
+ * heartbeat channel.
+ * <p/>
+ * A (push-based) EventHandler channel is established EvaluatorManager -> EvaluatorRuntime.
+ * The EvaluatorManager uses this to forward Driver messages, launch Tasks, and initiate
+ * control information (e.g., shutdown, suspend).
+ */
+@Private
+@DriverSide
+public final class EvaluatorManager implements Identifiable, AutoCloseable {
+
+  private final static Logger LOG = Logger.getLogger(EvaluatorManager.class.getName());
+
+  private final EvaluatorHeartBeatSanityChecker sanityChecker = new EvaluatorHeartBeatSanityChecker();
+  private final Clock clock;
+  private final ResourceReleaseHandler resourceReleaseHandler;
+  private final ResourceLaunchHandler resourceLaunchHandler;
+  private final String evaluatorId;
+  private final EvaluatorDescriptorImpl evaluatorDescriptor;
+  private final ContextRepresenters contextRepresenters;
+  private final EvaluatorMessageDispatcher messageDispatcher;
+  private final EvaluatorControlHandler evaluatorControlHandler;
+  private final ContextControlHandler contextControlHandler;
+  private final EvaluatorStatusManager stateManager;
+  private final ExceptionCodec exceptionCodec;
+  private final DriverStatusManager driverStatusManager;
+  private final EventHandlerIdlenessSource idlenessSource;
+  private final LoggingScopeFactory loggingScopeFactory;
+
+
+  // Mutable fields
+  private Optional<TaskRepresenter> task = Optional.empty();
+  private boolean isResourceReleased = false;
+
+  @Inject
+  private EvaluatorManager(
+      final Clock clock,
+      final RemoteManager remoteManager,
+      final ResourceReleaseHandler resourceReleaseHandler,
+      final ResourceLaunchHandler resourceLaunchHandler,
+      final @Parameter(EvaluatorIdentifier.class) String evaluatorId,
+      final @Parameter(EvaluatorDescriptorName.class) EvaluatorDescriptorImpl evaluatorDescriptor,
+      final ContextRepresenters contextRepresenters,
+      final ConfigurationSerializer configurationSerializer,
+      final EvaluatorMessageDispatcher messageDispatcher,
+      final EvaluatorControlHandler evaluatorControlHandler,
+      final ContextControlHandler contextControlHandler,
+      final EvaluatorStatusManager stateManager,
+      final DriverStatusManager driverStatusManager,
+      final ExceptionCodec exceptionCodec,
+      final EventHandlerIdlenessSource idlenessSource,
+      final LoggingScopeFactory loggingScopeFactory) {
+    this.contextRepresenters = contextRepresenters;
+    this.idlenessSource = idlenessSource;
+    LOG.log(Level.FINEST, "Instantiating 'EvaluatorManager' for evaluator: {0}", evaluatorId);
+    this.clock = clock;
+    this.resourceReleaseHandler = resourceReleaseHandler;
+    this.resourceLaunchHandler = resourceLaunchHandler;
+    this.evaluatorId = evaluatorId;
+    this.evaluatorDescriptor = evaluatorDescriptor;
+
+    this.messageDispatcher = messageDispatcher;
+    this.evaluatorControlHandler = evaluatorControlHandler;
+    this.contextControlHandler = contextControlHandler;
+    this.stateManager = stateManager;
+    this.driverStatusManager = driverStatusManager;
+    this.exceptionCodec = exceptionCodec;
+    this.loggingScopeFactory = loggingScopeFactory;
+
+    final AllocatedEvaluator allocatedEvaluator =
+        new AllocatedEvaluatorImpl(this, remoteManager.getMyIdentifier(), configurationSerializer, getJobIdentifier(), loggingScopeFactory);
+    LOG.log(Level.FINEST, "Firing AllocatedEvaluator event for Evaluator with ID [{0}]", evaluatorId);
+    this.messageDispatcher.onEvaluatorAllocated(allocatedEvaluator);
+    LOG.log(Level.FINEST, "Instantiated 'EvaluatorManager' for evaluator: [{0}]", this.getId());
+  }
+
+  /**
+   * Get the id of current job/application
+   */
+  public static String getJobIdentifier() {
+    // TODO: currently we obtain the job id directly by parsing execution (container) directory path
+    // #845 is open to get the id from RM properly
+    for (File directory = new File(System.getProperty("user.dir"));
+         directory != null; directory = directory.getParentFile()) {
+      final String currentDirectoryName = directory.getName();
+      if (currentDirectoryName.toLowerCase().contains("application_")) {
+        return currentDirectoryName;
+      }
+    }
+    // cannot find a directory that contains application_, presumably we are on local runtime
+    // again, this is a hack for now, we need #845 as a proper solution
+    return "REEF_LOCAL_RUNTIME";
+  }
+
+  private static boolean isDoneOrFailedOrKilled(final DriverRuntimeProtocol.ResourceStatusProto resourceStatusProto) {
+    return resourceStatusProto.getState() == ReefServiceProtos.State.DONE ||
+        resourceStatusProto.getState() == ReefServiceProtos.State.FAILED ||
+        resourceStatusProto.getState() == ReefServiceProtos.State.KILLED;
+  }
+
+  @Override
+  public String getId() {
+    return this.evaluatorId;
+  }
+
+  public void setType(final EvaluatorType type) {
+    this.evaluatorDescriptor.setType(type);
+  }
+
+  public EvaluatorDescriptor getEvaluatorDescriptor() {
+    return this.evaluatorDescriptor;
+  }
+
+  @Override
+  public void close() {
+    synchronized (this.evaluatorDescriptor) {
+      if (this.stateManager.isRunning()) {
+        LOG.log(Level.WARNING, "Dirty shutdown of running evaluator id[{0}]", getId());
+        try {
+          // Killing the evaluator means that it doesn't need to send a confirmation; it just dies.
+          final EvaluatorRuntimeProtocol.EvaluatorControlProto evaluatorControlProto =
+              EvaluatorRuntimeProtocol.EvaluatorControlProto.newBuilder()
+                  .setTimestamp(System.currentTimeMillis())
+                  .setIdentifier(getId())
+                  .setKillEvaluator(EvaluatorRuntimeProtocol.KillEvaluatorProto.newBuilder().build())
+                  .build();
+          sendEvaluatorControlMessage(evaluatorControlProto);
+        } finally {
+          this.stateManager.setKilled();
+        }
+      }
+
+
+      if (!this.isResourceReleased) {
+        this.isResourceReleased = true;
+        try {
+        /* We need to wait awhile before returning the container to the RM in order to
+         * give the EvaluatorRuntime (and Launcher) time to cleanly exit. */
+          this.clock.scheduleAlarm(100, new EventHandler<Alarm>() {
+            @Override
+            public void onNext(final Alarm alarm) {
+              EvaluatorManager.this.resourceReleaseHandler.onNext(
+                  DriverRuntimeProtocol.ResourceReleaseProto.newBuilder()
+                      .setIdentifier(EvaluatorManager.this.evaluatorId).build()
+              );
+            }
+          });
+        } catch (final IllegalStateException e) {
+          LOG.log(Level.WARNING, "Force resource release because the client closed the clock.", e);
+          EvaluatorManager.this.resourceReleaseHandler.onNext(
+              DriverRuntimeProtocol.ResourceReleaseProto.newBuilder()
+                  .setIdentifier(EvaluatorManager.this.evaluatorId).build()
+          );
+        }
+      }
+    }
+    this.idlenessSource.check();
+  }
+
+  /**
+   * Return true if the state is DONE, FAILED, or KILLED,
+   * <em>and</em> there are no messages queued or in processing.
+   */
+  public boolean isClosed() {
+    return this.messageDispatcher.isEmpty() &&
+        (this.stateManager.isDoneOrFailedOrKilled());
+  }
+
+  /**
+   * EvaluatorException will trigger is FailedEvaluator and state transition to FAILED
+   *
+   * @param exception on the EvaluatorRuntime
+   */
+  public void onEvaluatorException(final EvaluatorException exception) {
+    synchronized (this.evaluatorDescriptor) {
+      if (this.stateManager.isDoneOrFailedOrKilled()) {
+        LOG.log(Level.FINE, "Ignoring an exception receivedfor Evaluator {0} which is already in state {1}.",
+            new Object[]{this.getId(), this.stateManager});
+        return;
+      }
+
+      LOG.log(Level.WARNING, "Failed evaluator: " + getId(), exception);
+
+      try {
+
+        final List<FailedContext> failedContextList = this.contextRepresenters.getFailedContextsForEvaluatorFailure();
+
+        final Optional<FailedTask> failedTaskOptional;
+        if (this.task.isPresent()) {
+          final String taskId = this.task.get().getId();
+          final Optional<ActiveContext> evaluatorContext = Optional.empty();
+          final Optional<byte[]> bytes = Optional.empty();
+          final Optional<Throwable> taskException = Optional.<Throwable>of(new Exception("Evaluator crash"));
+          final String message = "Evaluator crash";
+          final Optional<String> description = Optional.empty();
+          final FailedTask failedTask = new FailedTask(taskId, message, description, taskException, bytes, evaluatorContext);
+          failedTaskOptional = Optional.of(failedTask);
+        } else {
+          failedTaskOptional = Optional.empty();
+        }
+
+
+        this.messageDispatcher.onEvaluatorFailed(new FailedEvaluatorImpl(exception, failedContextList, failedTaskOptional, this.evaluatorId));
+
+      } catch (final Exception e) {
+        LOG.log(Level.SEVERE, "Exception while handling FailedEvaluator", e);
+      } finally {
+        this.stateManager.setFailed();
+        close();
+      }
+    }
+  }
+
+  public synchronized void onEvaluatorHeartbeatMessage(
+      final RemoteMessage<EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto> evaluatorHeartbeatProtoRemoteMessage) {
+
+    final EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto evaluatorHeartbeatProto =
+        evaluatorHeartbeatProtoRemoteMessage.getMessage();
+    LOG.log(Level.FINEST, "Evaluator heartbeat: {0}", evaluatorHeartbeatProto);
+
+    if (this.stateManager.isDoneOrFailedOrKilled()) {
+      LOG.log(Level.FINE, "Ignoring an heartbeat received for Evaluator {0} which is already in state {1}.",
+          new Object[]{this.getId(), this.stateManager});
+      return;
+    }
+
+    this.sanityChecker.check(evaluatorId, evaluatorHeartbeatProto.getTimestamp());
+    final String evaluatorRID = evaluatorHeartbeatProtoRemoteMessage.getIdentifier().toString();
+
+    // first message from a running evaluator trying to re-establish communications
+    if (evaluatorHeartbeatProto.getRecovery()) {
+      this.evaluatorControlHandler.setRemoteID(evaluatorRID);
+      this.stateManager.setRunning();
+
+      this.driverStatusManager.oneContainerRecovered();
+      final int numRecoveredContainers = this.driverStatusManager.getNumRecoveredContainers();
+
+      LOG.log(Level.FINE, "Received recovery heartbeat from evaluator {0}.", this.evaluatorId);
+      final int expectedEvaluatorsNumber = this.driverStatusManager.getNumPreviousContainers();
+
+      if (numRecoveredContainers > expectedEvaluatorsNumber) {
+        LOG.log(Level.SEVERE, "expecting only [{0}] recovered evaluators, but [{1}] evaluators have checked in.",
+            new Object[]{expectedEvaluatorsNumber, numRecoveredContainers});
+        throw new RuntimeException("More then expected number of evaluators are checking in during recovery.");
+      } else if (numRecoveredContainers == expectedEvaluatorsNumber) {
+        LOG.log(Level.INFO, "All [{0}] expected evaluators have checked in. Recovery completed.", expectedEvaluatorsNumber);
+        this.driverStatusManager.setRestartCompleted();
+        this.messageDispatcher.OnDriverRestartCompleted(new DriverRestartCompleted(System.currentTimeMillis()));
+      } else {
+        LOG.log(Level.INFO, "expecting [{0}] recovered evaluators, [{1}] evaluators have checked in.",
+            new Object[]{expectedEvaluatorsNumber, numRecoveredContainers});
+      }
+    }
+
+    // If this is the first message from this Evaluator, register it.
+    if (this.stateManager.isSubmitted()) {
+      this.evaluatorControlHandler.setRemoteID(evaluatorRID);
+      this.stateManager.setRunning();
+      LOG.log(Level.FINEST, "Evaluator {0} is running", this.evaluatorId);
+    }
+
+    // Process the Evaluator status message
+    if (evaluatorHeartbeatProto.hasEvaluatorStatus()) {
+      this.onEvaluatorStatusMessage(evaluatorHeartbeatProto.getEvaluatorStatus());
+    }
+
+    // Process the Context status message(s)
+    final boolean informClientOfNewContexts = !evaluatorHeartbeatProto.hasTaskStatus();
+    this.contextRepresenters.onContextStatusMessages(evaluatorHeartbeatProto.getContextStatusList(),
+        informClientOfNewContexts);
+
+    // Process the Task status message
+    if (evaluatorHeartbeatProto.hasTaskStatus()) {
+      this.onTaskStatusMessage(evaluatorHeartbeatProto.getTaskStatus());
+    }
+    LOG.log(Level.FINE, "DONE with evaluator heartbeat from Evaluator {0}", this.getId());
+  }
+
+  /**
+   * Process a evaluator status message.
+   *
+   * @param message
+   */
+  private synchronized void onEvaluatorStatusMessage(final ReefServiceProtos.EvaluatorStatusProto message) {
+
+    switch (message.getState()) {
+      case DONE:
+        this.onEvaluatorDone(message);
+        break;
+      case FAILED:
+        this.onEvaluatorFailed(message);
+        break;
+      case INIT:
+      case KILLED:
+      case RUNNING:
+      case SUSPEND:
+        break;
+    }
+  }
+
+  /**
+   * Process an evaluator message that indicates that the evaluator shut down cleanly.
+   *
+   * @param message
+   */
+  private synchronized void onEvaluatorDone(final ReefServiceProtos.EvaluatorStatusProto message) {
+    assert (message.getState() == ReefServiceProtos.State.DONE);
+    LOG.log(Level.FINEST, "Evaluator {0} done.", getId());
+    this.stateManager.setDone();
+    this.messageDispatcher.onEvaluatorCompleted(new CompletedEvaluatorImpl(this.evaluatorId));
+    close();
+  }
+
+  /**
+   * Process an evaluator message that indicates a crash.
+   *
+   * @param evaluatorStatusProto
+   */
+  private synchronized void onEvaluatorFailed(final ReefServiceProtos.EvaluatorStatusProto evaluatorStatusProto) {
+    assert (evaluatorStatusProto.getState() == ReefServiceProtos.State.FAILED);
+    final EvaluatorException evaluatorException;
+    if (evaluatorStatusProto.hasError()) {
+      final Optional<Throwable> exception = this.exceptionCodec.fromBytes(evaluatorStatusProto.getError().toByteArray());
+      if (exception.isPresent()) {
+        evaluatorException = new EvaluatorException(getId(), exception.get());
+      } else {
+        evaluatorException = new EvaluatorException(getId(), new Exception("Exception sent, but can't be deserialized"));
+      }
+    } else {
+      evaluatorException = new EvaluatorException(getId(), new Exception("No exception sent"));
+    }
+    onEvaluatorException(evaluatorException);
+  }
+
+  public void onResourceLaunch(final DriverRuntimeProtocol.ResourceLaunchProto resourceLaunchProto) {
+    synchronized (this.evaluatorDescriptor) {
+      if (this.stateManager.isAllocated()) {
+        this.stateManager.setSubmitted();
+        this.resourceLaunchHandler.onNext(resourceLaunchProto);
+      } else {
+        throw new RuntimeException("Evaluator manager expected " + EvaluatorState.ALLOCATED +
+            " state but instead is in state " + this.stateManager);
+      }
+    }
+  }
+
+  /**
+   * Packages the ContextControlProto in an EvaluatorControlProto and forward it to the EvaluatorRuntime
+   *
+   * @param contextControlProto message contains context control info.
+   */
+  public void sendContextControlMessage(final EvaluatorRuntimeProtocol.ContextControlProto contextControlProto) {
+    synchronized (this.evaluatorDescriptor) {
+      LOG.log(Level.FINEST, "Context control message to {0}", this.evaluatorId);
+      this.contextControlHandler.send(contextControlProto);
+    }
+  }
+
+  /**
+   * Forward the EvaluatorControlProto to the EvaluatorRuntime
+   *
+   * @param evaluatorControlProto message contains evaluator control information.
+   */
+  void sendEvaluatorControlMessage(final EvaluatorRuntimeProtocol.EvaluatorControlProto evaluatorControlProto) {
+    synchronized (this.evaluatorDescriptor) {
+      this.evaluatorControlHandler.send(evaluatorControlProto);
+    }
+  }
+
+  /**
+   * Handle task status messages.
+   *
+   * @param taskStatusProto message contains the current task status.
+   */
+  private void onTaskStatusMessage(final ReefServiceProtos.TaskStatusProto taskStatusProto) {
+
+    if (!(this.task.isPresent() && this.task.get().getId().equals(taskStatusProto.getTaskId()))) {
+      if (taskStatusProto.getState() == ReefServiceProtos.State.INIT ||
+          taskStatusProto.getState() == ReefServiceProtos.State.FAILED ||
+          taskStatusProto.getRecovery() // for task from recovered evaluators
+          ) {
+
+        // FAILED is a legal first state of a Task as it could have failed during construction.
+        this.task = Optional.of(
+            new TaskRepresenter(taskStatusProto.getTaskId(),
+                this.contextRepresenters.getContext(taskStatusProto.getContextId()),
+                this.messageDispatcher,
+                this,
+                this.exceptionCodec));
+      } else {
+        throw new RuntimeException("Received an message of state " + taskStatusProto.getState() +
+            ", not INIT or FAILED for Task " + taskStatusProto.getTaskId() + " which we haven't heard from before.");
+      }
+    }
+    this.task.get().onTaskStatusMessage(taskStatusProto);
+
+    if (this.task.get().isNotRunning()) {
+      LOG.log(Level.FINEST, "Task no longer running. De-registering it.");
+      this.task = Optional.empty();
+    }
+  }
+
+  /**
+   * Resource status information from the (actual) resource manager.
+   */
+  public void onResourceStatusMessage(final DriverRuntimeProtocol.ResourceStatusProto resourceStatusProto) {
+    synchronized (this.evaluatorDescriptor) {
+      LOG.log(Level.FINEST, "Resource manager state update: {0}", resourceStatusProto.getState());
+      if (this.stateManager.isDoneOrFailedOrKilled()) {
+        LOG.log(Level.FINE, "Ignoring resource status update for Evaluator {0} which is already in state {1}.",
+            new Object[]{this.getId(), this.stateManager});
+      } else if (isDoneOrFailedOrKilled(resourceStatusProto) && this.stateManager.isAllocatedOrSubmittedOrRunning()) {
+        // something is wrong. The resource manager reports that the Evaluator is done or failed, but the Driver assumes
+        // it to be alive.
+        final StringBuilder messageBuilder = new StringBuilder("Evaluator [")
+            .append(this.evaluatorId)
+            .append("] is assumed to be in state [")
+            .append(this.stateManager.toString())
+            .append("]. But the resource manager reports it to be in state [")
+            .append(resourceStatusProto.getState())
+            .append("].");
+
+        if (this.stateManager.isSubmitted()) {
+          messageBuilder
+              .append(" This most likely means that the Evaluator suffered a failure before establishing a communications link to the driver.");
+        } else if (this.stateManager.isAllocated()) {
+          messageBuilder.append(" This most likely means that the Evaluator suffered a failure before being used.");
+        } else if (this.stateManager.isRunning()) {
+          messageBuilder.append(" This means that the Evaluator failed but wasn't able to send an error message back to the driver.");
+        }
+        if (this.task.isPresent()) {
+          messageBuilder.append(" Task [")
+              .append(this.task.get().getId())
+              .append("] was running when the Evaluator crashed.");
+        }
+        this.isResourceReleased = true;
+
+        if (resourceStatusProto.getState() == ReefServiceProtos.State.KILLED) {
+          this.onEvaluatorException(new EvaluatorKilledByResourceManagerException(this.evaluatorId, messageBuilder.toString()));
+        } else {
+          this.onEvaluatorException(new EvaluatorException(this.evaluatorId, messageBuilder.toString()));
+        }
+      }
+    }
+  }
+
+  @Override
+  public String toString() {
+    return "EvaluatorManager:"
+        + " id=" + this.evaluatorId
+        + " state=" + this.stateManager
+        + " task=" + this.task;
+  }
+
+  // Dynamic Parameters
+  @NamedParameter(doc = "The Evaluator Identifier.")
+  public final static class EvaluatorIdentifier implements Name<String> {
+  }
+
+  @NamedParameter(doc = "The Evaluator Host.")
+  public final static class EvaluatorDescriptorName implements Name<EvaluatorDescriptorImpl> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorManagerFactory.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorManagerFactory.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorManagerFactory.java
new file mode 100644
index 0000000..d6e7757
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorManagerFactory.java
@@ -0,0 +1,105 @@
+/**
+ * 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.reef.runtime.common.driver.evaluator;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.catalog.NodeDescriptor;
+import org.apache.reef.driver.catalog.ResourceCatalog;
+import org.apache.reef.driver.evaluator.EvaluatorType;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.resourcemanager.NodeDescriptorHandler;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Helper class that creates new EvaluatorManager instances from alloations.
+ */
+@Private
+@DriverSide
+public final class EvaluatorManagerFactory {
+  private static final Logger LOG = Logger.getLogger(EvaluatorManagerFactory.class.getName());
+
+  private final Injector injector;
+  private final ResourceCatalog resourceCatalog;
+
+  @Inject
+  EvaluatorManagerFactory(final Injector injector, final ResourceCatalog resourceCatalog, final NodeDescriptorHandler nodeDescriptorHandler) {
+    this.injector = injector;
+    this.resourceCatalog = resourceCatalog;
+  }
+
+  /**
+   * Helper method to create a new EvaluatorManager instance
+   *
+   * @param id   identifier of the Evaluator
+   * @param desc NodeDescriptor on which the Evaluator executes.
+   * @return a new EvaluatorManager instance.
+   */
+  private final EvaluatorManager getNewEvaluatorManagerInstance(final String id, final EvaluatorDescriptorImpl desc) {
+    LOG.log(Level.FINEST, "Creating Evaluator Manager for Evaluator ID {0}", id);
+    final Injector child = this.injector.forkInjector();
+
+    try {
+      child.bindVolatileParameter(EvaluatorManager.EvaluatorIdentifier.class, id);
+      child.bindVolatileParameter(EvaluatorManager.EvaluatorDescriptorName.class, desc);
+    } catch (final BindException e) {
+      throw new RuntimeException("Unable to bind evaluator identifier and name.", e);
+    }
+
+    final EvaluatorManager result;
+    try {
+      result = child.getInstance(EvaluatorManager.class);
+    } catch (final InjectionException e) {
+      throw new RuntimeException("Unable to instantiate a new EvaluatorManager for Evaluator ID: " + id, e);
+    }
+    return result;
+  }
+
+  /**
+   * Instantiates a new EvaluatorManager based on a resource allocation.
+   *
+   * @param resourceAllocationProto
+   * @return
+   */
+  public final EvaluatorManager getNewEvaluatorManager(final DriverRuntimeProtocol.ResourceAllocationProto resourceAllocationProto) {
+    final NodeDescriptor nodeDescriptor = this.resourceCatalog.getNode(resourceAllocationProto.getNodeId());
+
+    if (nodeDescriptor == null) {
+      throw new RuntimeException("Unknown resource: " + resourceAllocationProto.getNodeId());
+    }
+    final EvaluatorDescriptorImpl evaluatorDescriptor = new EvaluatorDescriptorImpl(nodeDescriptor,
+        EvaluatorType.UNDECIDED, resourceAllocationProto.getResourceMemory(), resourceAllocationProto.getVirtualCores());
+
+    LOG.log(Level.FINEST, "Resource allocation: new evaluator id[{0}]", resourceAllocationProto.getIdentifier());
+    return this.getNewEvaluatorManagerInstance(resourceAllocationProto.getIdentifier(), evaluatorDescriptor);
+  }
+
+  public final EvaluatorManager createForEvaluatorFailedDuringDriverRestart(final DriverRuntimeProtocol.ResourceStatusProto resourceStatusProto) {
+    if (!resourceStatusProto.getIsFromPreviousDriver()) {
+      throw new RuntimeException("Invalid resourceStatusProto, must be status for resource from previous Driver.");
+    }
+    return getNewEvaluatorManagerInstance(resourceStatusProto.getIdentifier(), new EvaluatorDescriptorImpl(null, EvaluatorType.UNDECIDED, 128, 1));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorMessageDispatcher.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorMessageDispatcher.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorMessageDispatcher.java
new file mode 100644
index 0000000..709cd30
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorMessageDispatcher.java
@@ -0,0 +1,247 @@
+/**
+ * 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.reef.runtime.common.driver.evaluator;
+
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ClosedContext;
+import org.apache.reef.driver.context.ContextMessage;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.CompletedEvaluator;
+import org.apache.reef.driver.evaluator.FailedEvaluator;
+import org.apache.reef.driver.parameters.*;
+import org.apache.reef.driver.task.*;
+import org.apache.reef.runtime.common.DriverRestartCompleted;
+import org.apache.reef.runtime.common.driver.DriverExceptionHandler;
+import org.apache.reef.runtime.common.utils.DispatchingEStage;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Central dispatcher for all Evaluator related events. This exists once per Evaluator.
+ */
+public final class EvaluatorMessageDispatcher {
+
+  private static final Logger LOG = Logger.getLogger(EvaluatorMessageDispatcher.class.getName());
+
+  /**
+   * Dispatcher used for application provided event handlers.
+   */
+  private final DispatchingEStage applicationDispatcher;
+
+  /**
+   * Dispatcher used for service provided event handlers.
+   */
+  private final DispatchingEStage serviceDispatcher;
+
+
+  /**
+   * Dispatcher used for application provided driver-restart specific event handlers.
+   */
+  private final DispatchingEStage driverRestartApplicationDispatcher;
+
+  /**
+   * Dispatcher used for service provided driver-restart specific event handlers.
+   */
+  private final DispatchingEStage driverRestartServiceDispatcher;
+
+  @Inject
+  EvaluatorMessageDispatcher(
+      // Application-provided Context event handlers
+      final @Parameter(ContextActiveHandlers.class) Set<EventHandler<ActiveContext>> contextActiveHandlers,
+      final @Parameter(ContextClosedHandlers.class) Set<EventHandler<ClosedContext>> contextClosedHandlers,
+      final @Parameter(ContextFailedHandlers.class) Set<EventHandler<FailedContext>> contextFailedHandlers,
+      final @Parameter(ContextMessageHandlers.class) Set<EventHandler<ContextMessage>> contextMessageHandlers,
+      // Service-provided Context event handlers
+      final @Parameter(ServiceContextActiveHandlers.class) Set<EventHandler<ActiveContext>> serviceContextActiveHandlers,
+      final @Parameter(ServiceContextClosedHandlers.class) Set<EventHandler<ClosedContext>> serviceContextClosedHandlers,
+      final @Parameter(ServiceContextFailedHandlers.class) Set<EventHandler<FailedContext>> serviceContextFailedHandlers,
+      final @Parameter(ServiceContextMessageHandlers.class) Set<EventHandler<ContextMessage>> serviceContextMessageHandlers,
+      // Application-provided Task event handlers
+      final @Parameter(TaskRunningHandlers.class) Set<EventHandler<RunningTask>> taskRunningHandlers,
+      final @Parameter(TaskCompletedHandlers.class) Set<EventHandler<CompletedTask>> taskCompletedHandlers,
+      final @Parameter(TaskSuspendedHandlers.class) Set<EventHandler<SuspendedTask>> taskSuspendedHandlers,
+      final @Parameter(TaskMessageHandlers.class) Set<EventHandler<TaskMessage>> taskMessageEventHandlers,
+      final @Parameter(TaskFailedHandlers.class) Set<EventHandler<FailedTask>> taskExceptionEventHandlers,
+      // Service-provided Task event handlers
+      final @Parameter(ServiceTaskRunningHandlers.class) Set<EventHandler<RunningTask>> serviceTaskRunningEventHandlers,
+      final @Parameter(ServiceTaskCompletedHandlers.class) Set<EventHandler<CompletedTask>> serviceTaskCompletedEventHandlers,
+      final @Parameter(ServiceTaskSuspendedHandlers.class) Set<EventHandler<SuspendedTask>> serviceTaskSuspendedEventHandlers,
+      final @Parameter(ServiceTaskMessageHandlers.class) Set<EventHandler<TaskMessage>> serviceTaskMessageEventHandlers,
+      final @Parameter(ServiceTaskFailedHandlers.class) Set<EventHandler<FailedTask>> serviceTaskExceptionEventHandlers,
+      // Application-provided Evaluator event handlers
+      final @Parameter(EvaluatorAllocatedHandlers.class) Set<EventHandler<AllocatedEvaluator>> evaluatorAllocatedHandlers,
+      final @Parameter(EvaluatorFailedHandlers.class) Set<EventHandler<FailedEvaluator>> evaluatorFailedHandlers,
+      final @Parameter(EvaluatorCompletedHandlers.class) Set<EventHandler<CompletedEvaluator>> evaluatorCompletedHandlers,
+      // Service-provided Evaluator event handlers
+      final @Parameter(ServiceEvaluatorAllocatedHandlers.class) Set<EventHandler<AllocatedEvaluator>> serviceEvaluatorAllocatedEventHandlers,
+      final @Parameter(ServiceEvaluatorFailedHandlers.class) Set<EventHandler<FailedEvaluator>> serviceEvaluatorFailedHandlers,
+      final @Parameter(ServiceEvaluatorCompletedHandlers.class) Set<EventHandler<CompletedEvaluator>> serviceEvaluatorCompletedHandlers,
+
+      // Application event handlers specific to a Driver restart
+      final @Parameter(DriverRestartTaskRunningHandlers.class) Set<EventHandler<RunningTask>> driverRestartTaskRunningHandlers,
+      final @Parameter(DriverRestartContextActiveHandlers.class) Set<EventHandler<ActiveContext>> driverRestartActiveContextHandlers,
+      final @Parameter(DriverRestartCompletedHandlers.class) Set<EventHandler<DriverRestartCompleted>> driverRestartCompletedHandlers,
+
+      // Service-provided event handlers specific to a Driver restart
+      final @Parameter(ServiceDriverRestartTaskRunningHandlers.class) Set<EventHandler<RunningTask>> serviceDriverRestartTaskRunningHandlers,
+      final @Parameter(ServiceDriverRestartContextActiveHandlers.class) Set<EventHandler<ActiveContext>> serviceDriverRestartActiveContextHandlers,
+      final @Parameter(ServiceDriverRestartCompletedHandlers.class) Set<EventHandler<DriverRestartCompleted>> serviceDriverRestartCompletedHandlers,
+
+      final @Parameter(EvaluatorDispatcherThreads.class) int numberOfThreads,
+      final @Parameter(EvaluatorManager.EvaluatorIdentifier.class) String evaluatorIdentifier,
+      final DriverExceptionHandler driverExceptionHandler) {
+
+    this.serviceDispatcher = new DispatchingEStage(driverExceptionHandler, numberOfThreads, evaluatorIdentifier);
+    this.applicationDispatcher = new DispatchingEStage(this.serviceDispatcher);
+    this.driverRestartApplicationDispatcher = new DispatchingEStage(this.serviceDispatcher);
+    this.driverRestartServiceDispatcher = new DispatchingEStage(this.serviceDispatcher);
+
+    { // Application Context event handlers
+      this.applicationDispatcher.register(ActiveContext.class, contextActiveHandlers);
+      this.applicationDispatcher.register(ClosedContext.class, contextClosedHandlers);
+      this.applicationDispatcher.register(FailedContext.class, contextFailedHandlers);
+      this.applicationDispatcher.register(ContextMessage.class, contextMessageHandlers);
+    }
+    { // Service Context event handlers
+      this.serviceDispatcher.register(ActiveContext.class, serviceContextActiveHandlers);
+      this.serviceDispatcher.register(ClosedContext.class, serviceContextClosedHandlers);
+      this.serviceDispatcher.register(FailedContext.class, serviceContextFailedHandlers);
+      this.serviceDispatcher.register(ContextMessage.class, serviceContextMessageHandlers);
+    }
+    { // Application Task event handlers.
+      this.applicationDispatcher.register(RunningTask.class, taskRunningHandlers);
+      this.applicationDispatcher.register(CompletedTask.class, taskCompletedHandlers);
+      this.applicationDispatcher.register(SuspendedTask.class, taskSuspendedHandlers);
+      this.applicationDispatcher.register(TaskMessage.class, taskMessageEventHandlers);
+      this.applicationDispatcher.register(FailedTask.class, taskExceptionEventHandlers);
+    }
+    { // Service Task event handlers
+      this.serviceDispatcher.register(RunningTask.class, serviceTaskRunningEventHandlers);
+      this.serviceDispatcher.register(CompletedTask.class, serviceTaskCompletedEventHandlers);
+      this.serviceDispatcher.register(SuspendedTask.class, serviceTaskSuspendedEventHandlers);
+      this.serviceDispatcher.register(TaskMessage.class, serviceTaskMessageEventHandlers);
+      this.serviceDispatcher.register(FailedTask.class, serviceTaskExceptionEventHandlers);
+    }
+    { // Application Evaluator event handlers
+      this.applicationDispatcher.register(FailedEvaluator.class, evaluatorFailedHandlers);
+      this.applicationDispatcher.register(CompletedEvaluator.class, evaluatorCompletedHandlers);
+      this.applicationDispatcher.register(AllocatedEvaluator.class, evaluatorAllocatedHandlers);
+    }
+    { // Service Evaluator event handlers
+      this.serviceDispatcher.register(FailedEvaluator.class, serviceEvaluatorFailedHandlers);
+      this.serviceDispatcher.register(CompletedEvaluator.class, serviceEvaluatorCompletedHandlers);
+      this.serviceDispatcher.register(AllocatedEvaluator.class, serviceEvaluatorAllocatedEventHandlers);
+    }
+
+    // Application event handlers specific to a Driver restart
+    {
+      this.driverRestartApplicationDispatcher.register(RunningTask.class, driverRestartTaskRunningHandlers);
+      this.driverRestartApplicationDispatcher.register(ActiveContext.class, driverRestartActiveContextHandlers);
+      this.driverRestartApplicationDispatcher.register(DriverRestartCompleted.class, driverRestartCompletedHandlers);
+    }
+
+    // Service event handlers specific to a Driver restart
+    {
+      this.driverRestartServiceDispatcher.register(RunningTask.class, serviceDriverRestartTaskRunningHandlers);
+      this.driverRestartServiceDispatcher.register(ActiveContext.class, serviceDriverRestartActiveContextHandlers);
+      this.driverRestartServiceDispatcher.register(DriverRestartCompleted.class, serviceDriverRestartCompletedHandlers);
+    }
+    LOG.log(Level.FINE, "Instantiated 'EvaluatorMessageDispatcher'");
+  }
+
+  public void onEvaluatorAllocated(final AllocatedEvaluator allocatedEvaluator) {
+    this.dispatch(AllocatedEvaluator.class, allocatedEvaluator);
+  }
+
+  public void onEvaluatorFailed(final FailedEvaluator failedEvaluator) {
+    this.dispatch(FailedEvaluator.class, failedEvaluator);
+  }
+
+  public void onEvaluatorCompleted(final CompletedEvaluator completedEvaluator) {
+    this.dispatch(CompletedEvaluator.class, completedEvaluator);
+  }
+
+  public void onTaskRunning(final RunningTask runningTask) {
+    this.dispatch(RunningTask.class, runningTask);
+  }
+
+  public void onTaskCompleted(final CompletedTask completedTask) {
+    this.dispatch(CompletedTask.class, completedTask);
+  }
+
+  public void onTaskSuspended(final SuspendedTask suspendedTask) {
+    this.dispatch(SuspendedTask.class, suspendedTask);
+  }
+
+  public void onTaskMessage(final TaskMessage taskMessage) {
+    this.dispatch(TaskMessage.class, taskMessage);
+  }
+
+  public void onTaskFailed(final FailedTask failedTask) {
+    this.dispatch(FailedTask.class, failedTask);
+  }
+
+  public void onContextActive(final ActiveContext activeContext) {
+    this.dispatch(ActiveContext.class, activeContext);
+  }
+
+  public void onContextClose(final ClosedContext closedContext) {
+    this.dispatch(ClosedContext.class, closedContext);
+  }
+
+  public void onContextFailed(final FailedContext failedContext) {
+    this.dispatch(FailedContext.class, failedContext);
+  }
+
+  public void onContextMessage(final ContextMessage contextMessage) {
+    this.dispatch(ContextMessage.class, contextMessage);
+  }
+
+  public void onDriverRestartTaskRunning(final RunningTask runningTask) {
+    this.dispatchForRestartedDriver(RunningTask.class, runningTask);
+  }
+
+  public void OnDriverRestartContextActive(final ActiveContext activeContext) {
+    this.dispatchForRestartedDriver(ActiveContext.class, activeContext);
+  }
+
+  public void OnDriverRestartCompleted(final DriverRestartCompleted restartCompleted) {
+    this.dispatchForRestartedDriver(DriverRestartCompleted.class, restartCompleted);
+  }
+
+  boolean isEmpty() {
+    return this.applicationDispatcher.isEmpty();
+  }
+
+  private <T, U extends T> void dispatch(final Class<T> type, final U message) {
+    this.serviceDispatcher.onNext(type, message);
+    this.applicationDispatcher.onNext(type, message);
+  }
+
+  private <T, U extends T> void dispatchForRestartedDriver(final Class<T> type, final U message) {
+    this.driverRestartApplicationDispatcher.onNext(type, message);
+    this.driverRestartServiceDispatcher.onNext(type, message);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorResourceManagerErrorHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorResourceManagerErrorHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorResourceManagerErrorHandler.java
new file mode 100644
index 0000000..1b9a4ca
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorResourceManagerErrorHandler.java
@@ -0,0 +1,67 @@
+/**
+ * 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.reef.runtime.common.driver.evaluator;
+
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.client.FailedRuntime;
+import org.apache.reef.exception.EvaluatorException;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.RemoteMessage;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The error handler receives all resourcemanager errors from all evaluators in the system.
+ * Its primary function is to dispatch these to the appropriate EvaluatorManager.
+ */
+@Private
+public final class EvaluatorResourceManagerErrorHandler implements EventHandler<RemoteMessage<ReefServiceProtos.RuntimeErrorProto>> {
+  private static final Logger LOG = Logger.getLogger(EvaluatorResourceManagerErrorHandler.class.toString());
+  private final Evaluators evaluators;
+
+
+  @Inject
+  EvaluatorResourceManagerErrorHandler(final Evaluators evaluators) {
+    this.evaluators = evaluators;
+    LOG.log(Level.FINE, "Instantiated 'EvaluatorResourceManagerErrorHandler'");
+  }
+
+  @Override
+  public void onNext(final RemoteMessage<ReefServiceProtos.RuntimeErrorProto> runtimeErrorProtoRemoteMessage) {
+    final ReefServiceProtos.RuntimeErrorProto runtimeErrorProto = runtimeErrorProtoRemoteMessage.getMessage();
+    final FailedRuntime error = new FailedRuntime(runtimeErrorProto);
+    final String evaluatorId = error.getId();
+    LOG.log(Level.WARNING, "Runtime error: " + error);
+
+    final EvaluatorException evaluatorException = error.getReason().isPresent() ?
+        new EvaluatorException(evaluatorId, error.getReason().get()) :
+        new EvaluatorException(evaluatorId, "Runtime error");
+
+    final Optional<EvaluatorManager> evaluatorManager = this.evaluators.get(evaluatorId);
+    if (evaluatorManager.isPresent()) {
+      evaluatorManager.get().onEvaluatorException(evaluatorException);
+    } else {
+      LOG.log(Level.WARNING, "Unknown evaluator runtime error: " + error);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorState.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorState.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorState.java
new file mode 100644
index 0000000..e1e778e
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorState.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.runtime.common.driver.evaluator;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+
+/**
+ * Various states that the EvaluatorManager could be in. The EvaluatorManager is
+ * created when a resource has been allocated by the ResourceManager.
+ */
+@DriverSide
+@Private
+enum EvaluatorState {
+  ALLOCATED,  // initial state
+  SUBMITTED,  // client called AllocatedEvaluator.submitTask() and we're waiting for first contact
+  RUNNING,    // first contact received, all communication channels established, Evaluator sent to client.
+  // TODO: Add CLOSING state
+  DONE,       // clean shutdown
+  FAILED,     // some failure occurred.
+  KILLED      // unclean shutdown
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorStatusManager.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorStatusManager.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorStatusManager.java
new file mode 100644
index 0000000..ba8a62f
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/EvaluatorStatusManager.java
@@ -0,0 +1,106 @@
+/**
+ * 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.reef.runtime.common.driver.evaluator;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Manages Status of a single Evaluator.
+ */
+@DriverSide
+@Private
+final class EvaluatorStatusManager {
+  private static final Logger LOG = Logger.getLogger(EvaluatorStatusManager.class.getName());
+  /**
+   * The state managed.
+   */
+  private EvaluatorState state = EvaluatorState.ALLOCATED;
+
+  @Inject
+  private EvaluatorStatusManager() {
+    LOG.log(Level.FINE, "Instantiated 'EvaluatorStatusManager'");
+  }
+
+  private static boolean isLegal(final EvaluatorState from, final EvaluatorState to) {
+    // TODO
+    return true;
+  }
+
+  synchronized void setRunning() {
+    this.setState(EvaluatorState.RUNNING);
+  }
+
+  synchronized void setSubmitted() {
+    this.setState(EvaluatorState.SUBMITTED);
+  }
+
+  synchronized void setDone() {
+    this.setState(EvaluatorState.DONE);
+  }
+
+  synchronized void setFailed() {
+    this.setState(EvaluatorState.FAILED);
+  }
+
+  synchronized void setKilled() {
+    this.setState(EvaluatorState.KILLED);
+  }
+
+  synchronized boolean isRunning() {
+    return this.state.equals(EvaluatorState.RUNNING);
+  }
+
+  synchronized boolean isDoneOrFailedOrKilled() {
+    return (this.state == EvaluatorState.DONE ||
+        this.state == EvaluatorState.FAILED ||
+        this.state == EvaluatorState.KILLED);
+  }
+
+  synchronized boolean isAllocatedOrSubmittedOrRunning() {
+    return (this.state == EvaluatorState.ALLOCATED ||
+        this.state == EvaluatorState.SUBMITTED ||
+        this.state == EvaluatorState.RUNNING);
+  }
+
+  synchronized boolean isSubmitted() {
+    return EvaluatorState.SUBMITTED == this.state;
+  }
+
+  synchronized boolean isAllocated() {
+    return EvaluatorState.ALLOCATED == this.state;
+  }
+
+  @Override
+  public synchronized String toString() {
+    return this.state.toString();
+  }
+
+  private synchronized void setState(final EvaluatorState state) {
+    if (!isLegal(this.state, state)) {
+      throw new IllegalStateException("Illegal state transition from '" + this.state + "' to '" + state + "'");
+    }
+    this.state = state;
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/Evaluators.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/Evaluators.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/Evaluators.java
new file mode 100644
index 0000000..dde4e70
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/Evaluators.java
@@ -0,0 +1,128 @@
+/**
+ * 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.reef.runtime.common.driver.evaluator;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.util.Optional;
+import org.apache.reef.util.SingletonAsserter;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Manages all Evaluators.
+ * See EvaluatorManager for the Driver side representation of a single Evaluator.
+ */
+@DriverSide
+@Private
+public final class Evaluators implements AutoCloseable {
+
+  private static final Logger LOG = Logger.getLogger(Evaluators.class.getName());
+
+  /**
+   * A map between evaluatorId and the EvaluatorManager that handles this evaluator.
+   */
+  private final Map<String, EvaluatorManager> evaluators = new HashMap<>();
+
+
+  @Inject
+  Evaluators() {
+    LOG.log(Level.FINE, "Instantiated 'Evaluators'");
+    assert (SingletonAsserter.assertSingleton(Evaluators.class));
+  }
+
+  /**
+   * Closes all EvaluatorManager instances managed.
+   */
+  @Override
+  public void close() {
+    final List<EvaluatorManager> evaluatorsCopy;
+    synchronized (this) {
+      evaluatorsCopy = new ArrayList<>(this.evaluators.values());
+    }
+    for (final EvaluatorManager evaluatorManager : evaluatorsCopy) {
+      LOG.log(Level.WARNING, "Unclean shutdown of evaluator {0}", evaluatorManager.getId());
+      if (!evaluatorManager.isClosed()) {
+        evaluatorManager.close();
+      }
+    }
+  }
+
+  /**
+   * Return true if <em>all</em> evaluators are in closed state
+   * (and their processing queues are empty).
+   */
+  public synchronized boolean allEvaluatorsAreClosed() {
+    synchronized (this.evaluators) {
+      for (final EvaluatorManager eval : this.evaluators.values()) {
+        if (!eval.isClosed()) {
+          return false;
+        }
+      }
+    }
+    return true;
+  }
+
+  /**
+   * @param evaluatorId
+   * @return the EvaluatorManager for the given id, if one exists.
+   */
+  public synchronized Optional<EvaluatorManager> get(final String evaluatorId) {
+    return Optional.ofNullable(this.evaluators.get(evaluatorId));
+  }
+
+  /**
+   * Create new EvaluatorManager and add it to the collection.
+   * <p/>
+   * FIXME: This method is a temporary fix for the race condition
+   * described in issues #828 and #839.
+   *
+   * @param evaluatorManagerFactory Factory that builds new EvaluatorManager objects.
+   * @param evaluatorMsg            Resource allocation message that contains data on the new evaluator.
+   * @throws java.lang.IllegalArgumentException if the EvaluatorManager is already known.
+   */
+  public synchronized void put(
+      final EvaluatorManagerFactory evaluatorManagerFactory,
+      final DriverRuntimeProtocol.ResourceAllocationProto evaluatorMsg) {
+    this.put(evaluatorManagerFactory.getNewEvaluatorManager(evaluatorMsg));
+  }
+
+  /**
+   * Adds an EvaluatorManager.
+   *
+   * @param evaluatorManager
+   * @throws java.lang.IllegalArgumentException if the EvaluatorManager is already known.
+   */
+  public synchronized void put(final EvaluatorManager evaluatorManager) {
+    final String evaluatorId = evaluatorManager.getId();
+    final EvaluatorManager prev = this.evaluators.put(evaluatorId, evaluatorManager);
+    LOG.log(Level.FINEST, "Adding: {0} previous: {1}", new Object[]{evaluatorId, prev});
+    if (prev != null) {
+      throw new IllegalArgumentException(
+          "Trying to re-add an Evaluator that is already known: " + evaluatorId);
+    }
+  }
+}


[19/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/ClassPathBuilder.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/ClassPathBuilder.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/ClassPathBuilder.java
new file mode 100644
index 0000000..fa7780b
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/ClassPathBuilder.java
@@ -0,0 +1,109 @@
+/**
+ * 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.reef.runtime.yarn;
+
+import org.apache.reef.util.HadoopEnvironment;
+
+import javax.annotation.concurrent.NotThreadSafe;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
+
+/**
+ * A helper class to assemble a class path.
+ * <p/>
+ * It uses a TreeSet internally for both a prefix and a suffix of the classpath. This makes sure that duplicate entries
+ * are avoided.
+ */
+@NotThreadSafe
+final class ClassPathBuilder {
+  private final LinkedHashSet<String> prefix = new LinkedHashSet<>();
+  private final LinkedHashSet<String> suffix = new LinkedHashSet<>();
+
+  /**
+   * The oracle that tells us whether a given path could be a YARN configuration path.
+   *
+   * @param path
+   * @return
+   */
+  private static boolean couldBeYarnConfigurationPath(final String path) {
+    return path.contains("conf") ||
+        path.contains("etc") ||
+        path.contains(HadoopEnvironment.HADOOP_CONF_DIR);
+  }
+
+  /**
+   * Adds the given classpath entry. A guess will be made whether it refers to a configuration folder, in which case
+   * it will be added to the prefix. Else, it will be added to the suffix.
+   *
+   * @param classPathEntry
+   */
+  void add(final String classPathEntry) {
+    // Make sure that the cluster configuration is in front of user classes
+    if (couldBeYarnConfigurationPath(classPathEntry)) {
+      this.addToPrefix(classPathEntry);
+    } else {
+      this.addToSuffix(classPathEntry);
+    }
+  }
+
+  /**
+   * Adds the given classPathEntry to the classpath suffix
+   *
+   * @param classPathEntry
+   */
+  void addToSuffix(final String classPathEntry) {
+    this.suffix.add(classPathEntry);
+  }
+
+  /**
+   * Adds the given classPathEntry to the classpath prefix
+   *
+   * @param classPathEntry
+   */
+  void addToPrefix(final String classPathEntry) {
+    this.prefix.add(classPathEntry);
+  }
+
+  /**
+   * Adds all entries given using the <code>add()</code> method.
+   *
+   * @param entries
+   */
+  void addAll(final String... entries) {
+    for (final String classPathEntry : entries) {
+      this.add(classPathEntry);
+    }
+  }
+
+  /**
+   * @return the suffix in an immutable list.
+   */
+  List<String> getSuffixAsImmutableList() {
+    return Collections.unmodifiableList(new ArrayList<>(this.suffix));
+  }
+
+  /**
+   * @return the prefix in an immutable list.
+   */
+  List<String> getPrefixAsImmutableList() {
+    return Collections.unmodifiableList(new ArrayList<>(this.prefix));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/YarnClasspathProvider.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/YarnClasspathProvider.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/YarnClasspathProvider.java
new file mode 100644
index 0000000..c5a83a3
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/YarnClasspathProvider.java
@@ -0,0 +1,140 @@
+/**
+ * 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.reef.runtime.yarn;
+
+import net.jcip.annotations.Immutable;
+import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.reef.runtime.common.files.RuntimeClasspathProvider;
+import org.apache.reef.util.OSUtils;
+
+import javax.inject.Inject;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Access to the classpath according to the REEF file system standard.
+ */
+@Immutable
+public final class YarnClasspathProvider implements RuntimeClasspathProvider {
+  private static final Logger LOG = Logger.getLogger(YarnClasspathProvider.class.getName());
+  private static final Level CLASSPATH_LOG_LEVEL = Level.FINE;
+
+  private static final String YARN_TOO_OLD_MESSAGE = "The version of YARN you are using is too old to support classpath assembly. Reverting to legacy method.";
+  private static final String HADOOP_CONF_DIR = OSUtils.formatVariable("HADOOP_CONF_DIR");
+  private static final String HADOOP_HOME = OSUtils.formatVariable("HADOOP_HOME");
+  private static final String HADOOP_COMMON_HOME = OSUtils.formatVariable("HADOOP_COMMON_HOME");
+  private static final String HADOOP_YARN_HOME = OSUtils.formatVariable("HADOOP_YARN_HOME");
+  private static final String HADOOP_HDFS_HOME = OSUtils.formatVariable("HADOOP_HDFS_HOME");
+  private static final String HADOOP_MAPRED_HOME = OSUtils.formatVariable("HADOOP_MAPRED_HOME");
+
+  // Used when we can't get a classpath from YARN
+  private static final String[] LEGACY_CLASSPATH_LIST = new String[]{
+      HADOOP_CONF_DIR,
+      HADOOP_HOME + "/*",
+      HADOOP_HOME + "/lib/*",
+      HADOOP_COMMON_HOME + "/*",
+      HADOOP_COMMON_HOME + "/lib/*",
+      HADOOP_YARN_HOME + "/*",
+      HADOOP_YARN_HOME + "/lib/*",
+      HADOOP_HDFS_HOME + "/*",
+      HADOOP_HDFS_HOME + "/lib/*",
+      HADOOP_MAPRED_HOME + "/*",
+      HADOOP_MAPRED_HOME + "/lib/*",
+      HADOOP_HOME + "/etc/hadoop",
+      HADOOP_HOME + "/share/hadoop/common/*",
+      HADOOP_HOME + "/share/hadoop/common/lib/*",
+      HADOOP_HOME + "/share/hadoop/yarn/*",
+      HADOOP_HOME + "/share/hadoop/yarn/lib/*",
+      HADOOP_HOME + "/share/hadoop/hdfs/*",
+      HADOOP_HOME + "/share/hadoop/hdfs/lib/*",
+      HADOOP_HOME + "/share/hadoop/mapreduce/*",
+      HADOOP_HOME + "/share/hadoop/mapreduce/lib/*"
+  };
+  private final List<String> classPathPrefix;
+  private final List<String> classPathSuffix;
+
+  @Inject
+  YarnClasspathProvider(final YarnConfiguration yarnConfiguration) {
+    boolean needsLegacyClasspath = false; // will be set to true below whenever we encounter issues with the YARN Configuration
+    final ClassPathBuilder builder = new ClassPathBuilder();
+
+    try {
+      // Add the classpath actually configured on this cluster
+      final String[] yarnClassPath = yarnConfiguration.getTrimmedStrings(YarnConfiguration.YARN_APPLICATION_CLASSPATH);
+      if (null == yarnClassPath || yarnClassPath.length == 0) {
+        needsLegacyClasspath = true;
+      } else {
+        builder.addAll(yarnClassPath);
+      }
+      final String[] yarnDefaultClassPath = YarnConfiguration.DEFAULT_YARN_CROSS_PLATFORM_APPLICATION_CLASSPATH;
+      if (null == yarnDefaultClassPath || yarnDefaultClassPath.length == 0) {
+        LOG.log(Level.SEVERE, "YarnConfiguration.DEFAULT_YARN_CROSS_PLATFORM_APPLICATION_CLASSPATH is empty. This indicates a broken cluster configuration");
+        needsLegacyClasspath = true;
+      } else {
+        builder.addAll(yarnDefaultClassPath);
+      }
+    } catch (final NoSuchFieldError e) {
+      // This means that one of the static fields above aren't actually in YarnConfiguration.
+      // The reason for that is most likely that we encounter a really old version of YARN.
+      needsLegacyClasspath = true;
+      LOG.log(Level.SEVERE, YARN_TOO_OLD_MESSAGE);
+    }
+
+    if (needsLegacyClasspath) {
+      builder.addAll(LEGACY_CLASSPATH_LIST);
+    }
+
+    this.classPathPrefix = builder.getPrefixAsImmutableList();
+    this.classPathSuffix = builder.getSuffixAsImmutableList();
+    this.logClasspath();
+  }
+
+  @Override
+  public List<String> getDriverClasspathPrefix() {
+    return this.classPathPrefix;
+  }
+
+  @Override
+  public List<String> getDriverClasspathSuffix() {
+    return this.classPathSuffix;
+  }
+
+  @Override
+  public List<String> getEvaluatorClasspathPrefix() {
+    return this.classPathPrefix;
+  }
+
+  @Override
+  public List<String> getEvaluatorClasspathSuffix() {
+    return this.classPathSuffix;
+  }
+
+
+  private void logClasspath() {
+    if (LOG.isLoggable(CLASSPATH_LOG_LEVEL)) {
+      final StringBuilder message = new StringBuilder("Classpath:\n\t");
+      message.append(StringUtils.join(classPathPrefix, "\n\t"));
+      message.append("\n--------------------------------\n\t");
+      message.append(StringUtils.join(classPathSuffix, "\n\t"));
+      LOG.log(CLASSPATH_LOG_LEVEL, message.toString());
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/YarnClientConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/YarnClientConfiguration.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/YarnClientConfiguration.java
new file mode 100644
index 0000000..c893dde
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/YarnClientConfiguration.java
@@ -0,0 +1,73 @@
+/**
+ * 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.reef.runtime.yarn.client;
+
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.client.REEF;
+import org.apache.reef.client.RunningJob;
+import org.apache.reef.runtime.common.client.REEFImplementation;
+import org.apache.reef.runtime.common.client.RunningJobImpl;
+import org.apache.reef.runtime.common.client.api.JobSubmissionHandler;
+import org.apache.reef.runtime.common.files.RuntimeClasspathProvider;
+import org.apache.reef.runtime.common.launch.REEFMessageCodec;
+import org.apache.reef.runtime.common.parameters.JVMHeapSlack;
+import org.apache.reef.runtime.yarn.YarnClasspathProvider;
+import org.apache.reef.runtime.yarn.client.parameters.JobPriority;
+import org.apache.reef.runtime.yarn.client.parameters.JobQueue;
+import org.apache.reef.runtime.yarn.util.YarnConfigurationConstructor;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.OptionalParameter;
+import org.apache.reef.util.logging.LoggingSetup;
+import org.apache.reef.wake.remote.RemoteConfiguration;
+
+/**
+ * A ConfigurationModule for the YARN resourcemanager.
+ */
+@Public
+@ClientSide
+public class YarnClientConfiguration extends ConfigurationModuleBuilder {
+  static {
+    LoggingSetup.setupCommonsLogging();
+  }
+
+  public static final OptionalParameter<String> YARN_QUEUE_NAME = new OptionalParameter<>();
+  public static final OptionalParameter<Integer> YARN_PRIORITY = new OptionalParameter<>();
+
+  public static final OptionalParameter<Double> JVM_HEAP_SLACK = new OptionalParameter<>();
+
+  public static final ConfigurationModule CONF = new YarnClientConfiguration()
+      // Bind the common resourcemanager
+      .bindImplementation(REEF.class, REEFImplementation.class)
+      .bindImplementation(RunningJob.class, RunningJobImpl.class)
+          // Bind the message codec for REEF.
+      .bindNamedParameter(RemoteConfiguration.MessageCodec.class, REEFMessageCodec.class)
+          // Bind YARN
+      .bindImplementation(JobSubmissionHandler.class, YarnJobSubmissionHandler.class)
+          // Bind the parameters given by the user
+      .bindNamedParameter(JobQueue.class, YARN_QUEUE_NAME)
+      .bindNamedParameter(JobPriority.class, YARN_PRIORITY)
+      .bindNamedParameter(JVMHeapSlack.class, JVM_HEAP_SLACK)
+      .bindImplementation(RuntimeClasspathProvider.class, YarnClasspathProvider.class)
+          // Bind external constructors. Taken from  YarnExternalConstructors.registerClientConstructors
+      .bindConstructor(org.apache.hadoop.yarn.conf.YarnConfiguration.class, YarnConfigurationConstructor.class)
+      .build();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/YarnJobSubmissionHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/YarnJobSubmissionHandler.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/YarnJobSubmissionHandler.java
new file mode 100644
index 0000000..fd2bb69
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/YarnJobSubmissionHandler.java
@@ -0,0 +1,277 @@
+/**
+ * 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.reef.runtime.yarn.client;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.fs.FileContext;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.yarn.api.ApplicationConstants;
+import org.apache.hadoop.yarn.api.protocolrecords.GetNewApplicationResponse;
+import org.apache.hadoop.yarn.api.records.*;
+import org.apache.hadoop.yarn.client.api.YarnClient;
+import org.apache.hadoop.yarn.client.api.YarnClientApplication;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.exceptions.YarnException;
+import org.apache.hadoop.yarn.util.ConverterUtils;
+import org.apache.hadoop.yarn.util.Records;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.parameters.DriverJobSubmissionDirectory;
+import org.apache.reef.proto.ClientRuntimeProtocol;
+import org.apache.reef.runtime.common.client.api.JobSubmissionHandler;
+import org.apache.reef.runtime.common.files.ClasspathProvider;
+import org.apache.reef.runtime.common.files.JobJarMaker;
+import org.apache.reef.runtime.common.files.REEFFileNames;
+import org.apache.reef.runtime.common.launch.JavaLaunchCommandBuilder;
+import org.apache.reef.runtime.common.parameters.JVMHeapSlack;
+import org.apache.reef.runtime.yarn.driver.YarnDriverConfiguration;
+import org.apache.reef.runtime.yarn.util.YarnTypes;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Configurations;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.formats.ConfigurationSerializer;
+import org.apache.reef.tang.types.NamedParameterNode;
+import org.apache.reef.tang.util.ReflectionUtilities;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Private
+@ClientSide
+final class YarnJobSubmissionHandler implements JobSubmissionHandler {
+
+  private static final Logger LOG = Logger.getLogger(YarnJobSubmissionHandler.class.getName());
+
+  private final YarnConfiguration yarnConfiguration;
+  private final YarnClient yarnClient;
+  private final JobJarMaker jobJarMaker;
+  private final REEFFileNames filenames;
+  private final ClasspathProvider classpath;
+  private final FileSystem fileSystem;
+  private final ConfigurationSerializer configurationSerializer;
+  private final double jvmSlack;
+
+  @Inject
+  YarnJobSubmissionHandler(
+      final YarnConfiguration yarnConfiguration,
+      final JobJarMaker jobJarMaker,
+      final REEFFileNames filenames,
+      final ClasspathProvider classpath,
+      final ConfigurationSerializer configurationSerializer,
+      final @Parameter(JVMHeapSlack.class) double jvmSlack) throws IOException {
+
+    this.yarnConfiguration = yarnConfiguration;
+    this.jobJarMaker = jobJarMaker;
+    this.filenames = filenames;
+    this.classpath = classpath;
+    this.configurationSerializer = configurationSerializer;
+    this.jvmSlack = jvmSlack;
+
+    this.fileSystem = FileSystem.get(yarnConfiguration);
+
+    this.yarnClient = YarnClient.createYarnClient();
+    this.yarnClient.init(this.yarnConfiguration);
+    this.yarnClient.start();
+  }
+
+  @Override
+  public void close() {
+    this.yarnClient.stop();
+  }
+
+  @Override
+  public void onNext(final ClientRuntimeProtocol.JobSubmissionProto jobSubmissionProto) {
+
+    LOG.log(Level.FINEST, "Submitting job with ID [{0}]", jobSubmissionProto.getIdentifier());
+
+    try {
+
+      LOG.log(Level.FINE, "Requesting Application ID from YARN.");
+
+      final YarnClientApplication yarnClientApplication = this.yarnClient.createApplication();
+      final GetNewApplicationResponse applicationResponse = yarnClientApplication.getNewApplicationResponse();
+
+      final ApplicationSubmissionContext applicationSubmissionContext =
+          yarnClientApplication.getApplicationSubmissionContext();
+
+      final ApplicationId applicationId = applicationSubmissionContext.getApplicationId();
+
+      LOG.log(Level.FINEST, "YARN Application ID: {0}", applicationId);
+
+      // set the application name
+      applicationSubmissionContext.setApplicationName(
+          "reef-job-" + jobSubmissionProto.getIdentifier());
+
+      LOG.log(Level.FINE, "Assembling submission JAR for the Driver.");
+
+      final Path submissionFolder = new Path(
+          "/tmp/" + this.filenames.getJobFolderPrefix() + applicationId.getId() + "/");
+
+      final Configuration driverConfiguration =
+          makeDriverConfiguration(jobSubmissionProto, submissionFolder);
+
+      final File jobSubmissionFile =
+          this.jobJarMaker.createJobSubmissionJAR(jobSubmissionProto, driverConfiguration);
+
+      final Path uploadedJobJarPath = this.uploadToJobFolder(jobSubmissionFile, submissionFolder);
+
+      final Map<String, LocalResource> resources = new HashMap<>(1);
+      resources.put(this.filenames.getREEFFolderName(),
+          this.makeLocalResourceForJarFile(uploadedJobJarPath));
+
+      // SET MEMORY RESOURCE
+      final int amMemory = getMemory(
+          jobSubmissionProto, applicationResponse.getMaximumResourceCapability().getMemory());
+      applicationSubmissionContext.setResource(Resource.newInstance(amMemory, 1));
+
+      // SET EXEC COMMAND
+      final List<String> launchCommand = new JavaLaunchCommandBuilder()
+          .setErrorHandlerRID(jobSubmissionProto.getRemoteId())
+          .setLaunchID(jobSubmissionProto.getIdentifier())
+          .setConfigurationFileName(this.filenames.getDriverConfigurationPath())
+          .setClassPath(this.classpath.getDriverClasspath())
+          .setMemory(amMemory)
+          .setStandardOut(ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/" + this.filenames.getDriverStdoutFileName())
+          .setStandardErr(ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/" + this.filenames.getDriverStderrFileName())
+          .build();
+
+      applicationSubmissionContext.setAMContainerSpec(
+          YarnTypes.getContainerLaunchContext(launchCommand, resources));
+
+      applicationSubmissionContext.setPriority(getPriority(jobSubmissionProto));
+
+      // Set the queue to which this application is to be submitted in the RM
+      applicationSubmissionContext.setQueue(getQueue(jobSubmissionProto, "default"));
+      LOG.log(Level.INFO, "Submitting REEF Application to YARN. ID: {0}", applicationId);
+
+      if (LOG.isLoggable(Level.FINEST)) {
+        LOG.log(Level.FINEST, "REEF app command: {0}", StringUtils.join(launchCommand, ' '));
+      }
+
+      // TODO: this is currently being developed on a hacked 2.4.0 bits, should be 2.4.1
+      final String minVersionKeepContainerOptionAvailable = "2.4.0";
+
+      // when supported, set KeepContainersAcrossApplicationAttempts to be true
+      // so that when driver (AM) crashes, evaluators will still be running and we can recover later.
+      if (YarnTypes.isAtOrAfterVersion(minVersionKeepContainerOptionAvailable)) {
+        LOG.log(
+            Level.FINE,
+            "Hadoop version is {0} or after with KeepContainersAcrossApplicationAttempts supported, will set it to true.",
+            minVersionKeepContainerOptionAvailable);
+
+        applicationSubmissionContext.setKeepContainersAcrossApplicationAttempts(true);
+      }
+
+      this.yarnClient.submitApplication(applicationSubmissionContext);
+
+    } catch (final YarnException | IOException e) {
+      throw new RuntimeException("Unable to submit Driver to YARN.", e);
+    }
+  }
+
+  /**
+   * Assembles the Driver configuration.
+   */
+  private Configuration makeDriverConfiguration(
+      final ClientRuntimeProtocol.JobSubmissionProto jobSubmissionProto,
+      final Path jobFolderPath) throws IOException {
+    Configuration config = this.configurationSerializer.fromString(jobSubmissionProto.getConfiguration());
+    final String userBoundJobSubmissionDirectory = config.getNamedParameter((NamedParameterNode<?>) config.getClassHierarchy().getNode(ReflectionUtilities.getFullName(DriverJobSubmissionDirectory.class)));
+    LOG.log(Level.FINE, "user bound job submission Directory: " + userBoundJobSubmissionDirectory);
+    final String finalJobFolderPath =
+        (userBoundJobSubmissionDirectory == null || userBoundJobSubmissionDirectory.isEmpty())
+            ? jobFolderPath.toString() : userBoundJobSubmissionDirectory;
+    return Configurations.merge(
+        YarnDriverConfiguration.CONF
+            .set(YarnDriverConfiguration.JOB_SUBMISSION_DIRECTORY, finalJobFolderPath)
+            .set(YarnDriverConfiguration.JOB_IDENTIFIER, jobSubmissionProto.getIdentifier())
+            .set(YarnDriverConfiguration.CLIENT_REMOTE_IDENTIFIER, jobSubmissionProto.getRemoteId())
+            .set(YarnDriverConfiguration.JVM_HEAP_SLACK, this.jvmSlack)
+            .build(),
+        this.configurationSerializer.fromString(jobSubmissionProto.getConfiguration()));
+  }
+
+  private final Path uploadToJobFolder(final File file, final Path jobFolder) throws IOException {
+    final Path source = new Path(file.getAbsolutePath());
+    final Path destination = new Path(jobFolder, file.getName());
+    LOG.log(Level.FINE, "Uploading {0} to {1}", new Object[]{source, destination});
+    this.fileSystem.copyFromLocalFile(false, true, source, destination);
+    return destination;
+  }
+
+  private Priority getPriority(final ClientRuntimeProtocol.JobSubmissionProto jobSubmissionProto) {
+    return Priority.newInstance(
+        jobSubmissionProto.hasPriority() ? jobSubmissionProto.getPriority() : 0);
+  }
+
+  /**
+   * Extract the queue name from the jobSubmissionProto or return default if none is set.
+   * <p/>
+   * TODO: Revisit this. We also have a named parameter for the queue in YarnClientConfiguration.
+   */
+  private final String getQueue(final ClientRuntimeProtocol.JobSubmissionProto jobSubmissionProto,
+                                final String defaultQueue) {
+    return jobSubmissionProto.hasQueue() && !jobSubmissionProto.getQueue().isEmpty() ?
+        jobSubmissionProto.getQueue() : defaultQueue;
+  }
+
+  /**
+   * Extract the desired driver memory from jobSubmissionProto.
+   * <p/>
+   * returns maxMemory if that desired amount is more than maxMemory
+   */
+  private int getMemory(final ClientRuntimeProtocol.JobSubmissionProto jobSubmissionProto,
+                        final int maxMemory) {
+    final int amMemory;
+    final int requestedMemory = jobSubmissionProto.getDriverMemory();
+    if (requestedMemory <= maxMemory) {
+      amMemory = requestedMemory;
+    } else {
+      LOG.log(Level.WARNING,
+          "Requested {0}MB of memory for the driver. " +
+              "The max on this YARN installation is {1}. " +
+              "Using {1} as the memory for the driver.",
+          new Object[]{requestedMemory, maxMemory});
+      amMemory = maxMemory;
+    }
+    return amMemory;
+  }
+
+  /**
+   * Creates a LocalResource instance for the JAR file referenced by the given Path
+   */
+  private LocalResource makeLocalResourceForJarFile(final Path path) throws IOException {
+    final LocalResource localResource = Records.newRecord(LocalResource.class);
+    final FileStatus status = FileContext.getFileContext(fileSystem.getUri()).getFileStatus(path);
+    localResource.setType(LocalResourceType.ARCHIVE);
+    localResource.setVisibility(LocalResourceVisibility.APPLICATION);
+    localResource.setResource(ConverterUtils.getYarnUrlFromPath(status.getPath()));
+    localResource.setTimestamp(status.getModificationTime());
+    localResource.setSize(status.getLen());
+    return localResource;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/parameters/JobPriority.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/parameters/JobPriority.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/parameters/JobPriority.java
new file mode 100644
index 0000000..a14ad98
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/parameters/JobPriority.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.runtime.yarn.client.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The prioroty of the submitted job.
+ */
+@NamedParameter(doc = "The job priority.", default_value = "0", short_name = "yarn_priority")
+public final class JobPriority implements Name<Integer> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/parameters/JobQueue.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/parameters/JobQueue.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/parameters/JobQueue.java
new file mode 100644
index 0000000..6017a55
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/client/parameters/JobQueue.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.runtime.yarn.client.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * The queue to submit a job to.
+ */
+@NamedParameter(doc = "The job queue.", default_value = "default", short_name = "yarn_queue")
+public final class JobQueue implements Name<String> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/ApplicationMasterRegistration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/ApplicationMasterRegistration.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/ApplicationMasterRegistration.java
new file mode 100644
index 0000000..63194e7
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/ApplicationMasterRegistration.java
@@ -0,0 +1,62 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+import org.apache.hadoop.yarn.api.protocolrecords.RegisterApplicationMasterResponse;
+import org.apache.reef.util.Optional;
+
+import javax.inject.Inject;
+
+/**
+ * Helper class that holds on to the AM registration.
+ */
+final class ApplicationMasterRegistration {
+
+  private Optional<RegisterApplicationMasterResponse> registration = Optional.empty();
+
+  @Inject
+  ApplicationMasterRegistration() {
+  }
+
+  /**
+   * @return the registered registration.
+   */
+  synchronized RegisterApplicationMasterResponse getRegistration() {
+    return registration.get();
+  }
+
+  /**
+   * Set the registration information. This is a set-once field.
+   *
+   * @param registration
+   */
+  synchronized void setRegistration(final RegisterApplicationMasterResponse registration) {
+    if (this.isPresent()) {
+      throw new RuntimeException("Trying to re-register the AM");
+    }
+    this.registration = Optional.of(registration);
+  }
+
+  /**
+   * @return true, if a registration was set.
+   */
+  synchronized boolean isPresent() {
+    return this.registration.isPresent();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/ContainerRequestCounter.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/ContainerRequestCounter.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/ContainerRequestCounter.java
new file mode 100644
index 0000000..59860e2
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/ContainerRequestCounter.java
@@ -0,0 +1,71 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Used to keep track of resource requests.
+ */
+@Private
+@DriverSide
+final class ContainerRequestCounter {
+  private static final Logger LOG = Logger.getLogger(ContainerRequestCounter.class.getName());
+
+  private int counter = 0;
+
+  @Inject
+  ContainerRequestCounter() {
+    LOG.log(Level.FINEST, "Instantiated 'ContainerRequestCounter'");
+  }
+
+  /**
+   * Increment the counter by the given amount.
+   *
+   * @param number
+   */
+  synchronized void incrementBy(final int number) {
+    this.counter += number;
+  }
+
+  /**
+   * @return the current value of the counter.
+   */
+  synchronized int get() {
+    return this.counter;
+  }
+
+  /**
+   * Decrement the counter by 1.
+   */
+  synchronized void decrement() {
+    if (this.counter <= 0) {
+      LOG.log(Level.WARNING, "requestedContainerCount cannot go below 0");
+      this.counter = 0;
+    } else {
+      this.counter -= 1;
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/Containers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/Containers.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/Containers.java
new file mode 100644
index 0000000..b3f4ac1
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/Containers.java
@@ -0,0 +1,109 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+
+import org.apache.hadoop.yarn.api.records.Container;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.util.Optional;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Helper class that manages the set of Containers we know about.
+ */
+@Private
+@DriverSide
+final class Containers {
+  private final Map<String, Container> containers = new ConcurrentHashMap<>();
+
+  @Inject
+  Containers() {
+  }
+
+  /**
+   * @param containerID
+   * @return the container for the given id.
+   * @throws java.lang.RuntimeException when the container is unknown.
+   */
+  synchronized Container get(final String containerID) {
+    final Container result = this.containers.get(containerID);
+    if (null == result) {
+      throw new RuntimeException("Requesting an unknown container: " + containerID);
+    }
+    return result;
+  }
+
+  /**
+   * Registers the given container
+   *
+   * @param container
+   * @throws java.lang.RuntimeException if a container with the same ID had been registered before.
+   */
+  synchronized void add(final Container container) {
+    final String containerId = container.getId().toString();
+    if (this.hasContainer(containerId)) {
+      throw new RuntimeException("Trying to add a Container that is already known: " + containerId);
+    }
+    this.containers.put(containerId, container);
+  }
+
+  /**
+   * Removes the container with the given ID.
+   *
+   * @param containerId
+   * @return the container that was registered before.
+   * @throws java.lang.RuntimeException if no such container existed.
+   */
+  synchronized Container removeAndGet(final String containerId) {
+    final Container result = this.containers.remove(containerId);
+    if (null == result) {
+      throw new RuntimeException("Unknown container to remove: " + containerId);
+    }
+    return result;
+  }
+
+  /**
+   * @param containerId
+   * @return true, if a container with this ID is known.
+   */
+  synchronized boolean hasContainer(final String containerId) {
+    return this.containers.containsKey(containerId);
+  }
+
+
+  /**
+   * @param containerId
+   * @return the Container stored under this containerId or an empty Optional.
+   */
+  synchronized Optional<Container> getOptional(final String containerId) {
+    return Optional.ofNullable(this.containers.get(containerId));
+  }
+
+  /**
+   * @return an Iterable of all the known container Ids.
+   */
+  synchronized Iterable<String> getContainerIds() {
+    return new ArrayList(this.containers.keySet());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/DefaultTrackingURLProvider.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/DefaultTrackingURLProvider.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/DefaultTrackingURLProvider.java
new file mode 100644
index 0000000..c11b2b8
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/DefaultTrackingURLProvider.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+import javax.inject.Inject;
+
+final class DefaultTrackingURLProvider implements TrackingURLProvider {
+
+  @Inject
+  DefaultTrackingURLProvider() {
+  }
+
+  @Override
+  public String getTrackingUrl() {
+    return "";
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/EvaluatorSetupHelper.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/EvaluatorSetupHelper.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/EvaluatorSetupHelper.java
new file mode 100644
index 0000000..3a2ff5c
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/EvaluatorSetupHelper.java
@@ -0,0 +1,147 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.yarn.api.records.LocalResource;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.io.TempFileCreator;
+import org.apache.reef.io.WorkingDirectoryTempFileCreator;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.runtime.common.files.JobJarMaker;
+import org.apache.reef.runtime.common.files.REEFFileNames;
+import org.apache.reef.runtime.common.parameters.DeleteTempFiles;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.formats.ConfigurationSerializer;
+import org.apache.reef.util.JARFileMaker;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Manages the global files on the driver and can produce the needed FileResources for container submissions.
+ */
+@DriverSide
+final class EvaluatorSetupHelper {
+
+  private static final Logger LOG = Logger.getLogger(EvaluatorSetupHelper.class.getName());
+
+  private final REEFFileNames fileNames;
+  private final ConfigurationSerializer configurationSerializer;
+  private final TempFileCreator tempFileCreator;
+  private final UploaderToJobFolder uploader;
+  private final GlobalJarUploader globalJarUploader;
+  private final boolean deleteTempFiles;
+
+  @Inject
+  EvaluatorSetupHelper(
+      final REEFFileNames fileNames,
+      final ConfigurationSerializer configurationSerializer,
+      final TempFileCreator tempFileCreator,
+      final @Parameter(DeleteTempFiles.class) boolean deleteTempFiles,
+      final UploaderToJobFolder uploader,
+      final GlobalJarUploader globalJarUploader) throws IOException {
+    this.tempFileCreator = tempFileCreator;
+    this.deleteTempFiles = deleteTempFiles;
+    this.globalJarUploader = globalJarUploader;
+
+    this.fileNames = fileNames;
+    this.configurationSerializer = configurationSerializer;
+    this.uploader = uploader;
+  }
+
+  /**
+   * @return the map to be used in formulating the evaluator launch submission.
+   */
+  Map<String, LocalResource> getGlobalResources() {
+    try {
+      return this.globalJarUploader.call();
+    } catch (IOException e) {
+      throw new RuntimeException("Unable to upload the global JAR file to the job folder.", e);
+    }
+  }
+
+
+  /**
+   * Sets up the LocalResources for a new Evaluator.
+   *
+   * @param resourceLaunchProto
+   * @return
+   * @throws IOException
+   */
+  Map<String, LocalResource> getResources(
+      final DriverRuntimeProtocol.ResourceLaunchProto resourceLaunchProto)
+      throws IOException {
+
+    final Map<String, LocalResource> result = new HashMap<>();
+    result.putAll(getGlobalResources());
+
+    final File localStagingFolder = this.tempFileCreator.createTempDirectory(this.fileNames.getEvaluatorFolderPrefix());
+
+    // Write the configuration
+    final File configurationFile = new File(localStagingFolder, this.fileNames.getEvaluatorConfigurationName());
+    this.configurationSerializer.toFile(makeEvaluatorConfiguration(resourceLaunchProto), configurationFile);
+
+    // Copy files to the staging folder
+    JobJarMaker.copy(resourceLaunchProto.getFileList(), localStagingFolder);
+
+    // Make a JAR file out of it
+    final File localFile = tempFileCreator.createTempFile(
+        this.fileNames.getEvaluatorFolderPrefix(), this.fileNames.getJarFileSuffix());
+    new JARFileMaker(localFile).addChildren(localStagingFolder).close();
+
+    // Upload the JAR to the job folder
+    final Path pathToEvaluatorJar = this.uploader.uploadToJobFolder(localFile);
+    result.put(this.fileNames.getLocalFolderPath(), this.uploader.makeLocalResourceForJarFile(pathToEvaluatorJar));
+
+    if (this.deleteTempFiles) {
+      LOG.log(Level.FINE, "Marking [{0}] for deletion at the exit of this JVM and deleting [{1}]",
+          new Object[]{localFile.getAbsolutePath(), localStagingFolder.getAbsolutePath()});
+      localFile.deleteOnExit();
+      localStagingFolder.delete();
+    } else {
+      LOG.log(Level.FINE, "The evaluator staging folder will be kept at [{0}], the JAR at [{1}]",
+          new Object[]{localFile.getAbsolutePath(), localStagingFolder.getAbsolutePath()});
+    }
+    return result;
+  }
+
+  /**
+   * Assembles the configuration for an Evaluator.
+   *
+   * @param resourceLaunchProto
+   * @return
+   * @throws IOException
+   */
+
+  private Configuration makeEvaluatorConfiguration(final DriverRuntimeProtocol.ResourceLaunchProto resourceLaunchProto)
+      throws IOException {
+    return Tang.Factory.getTang()
+        .newConfigurationBuilder(this.configurationSerializer.fromString(resourceLaunchProto.getEvaluatorConf()))
+        .bindImplementation(TempFileCreator.class, WorkingDirectoryTempFileCreator.class)
+        .build();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/GlobalJarUploader.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/GlobalJarUploader.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/GlobalJarUploader.java
new file mode 100644
index 0000000..c6ee91e
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/GlobalJarUploader.java
@@ -0,0 +1,92 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.yarn.api.records.LocalResource;
+import org.apache.reef.runtime.common.files.REEFFileNames;
+import org.apache.reef.util.JARFileMaker;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+/**
+ * Utility class that creates the JAR file with the global files on the driver and then uploads it to the job folder on
+ * (H)DFS.
+ */
+final class GlobalJarUploader implements Callable<Map<String, LocalResource>> {
+
+  /**
+   * Used for the file system constants.
+   */
+  private final REEFFileNames fileNames;
+  /**
+   * This will hold the actuall map to be used as the "global" resources when submitting Evaluators.
+   */
+  private final Map<String, LocalResource> globalResources = new HashMap<>(1);
+  /**
+   * Utility to actually perform the update.
+   */
+  private final UploaderToJobFolder uploader;
+  /**
+   * True, if globalResources contains the valid information which is cached after the first call to call().
+   */
+  private boolean isDone;
+
+  @Inject
+  GlobalJarUploader(final REEFFileNames fileNames,
+                    final UploaderToJobFolder uploader) {
+    this.fileNames = fileNames;
+    this.uploader = uploader;
+  }
+
+  /**
+   * Creates the JAR file with the global files on the driver and then uploads it to the job folder on
+   * (H)DFS.
+   *
+   * @return the map to be used as the "global" resources when submitting Evaluators.
+   * @throws IOException if the creation of the JAR or the upload fails
+   */
+  @Override
+  public synchronized Map<String, LocalResource> call() throws IOException {
+    if (!this.isDone) {
+      final Path pathToGlobalJar = this.uploader.uploadToJobFolder(makeGlobalJar());
+      globalResources.put(this.fileNames.getGlobalFolderPath(),
+          this.uploader.makeLocalResourceForJarFile(pathToGlobalJar));
+      this.isDone = true;
+    }
+    return this.globalResources;
+  }
+
+  /**
+   * Creates the JAR file for upload.
+   *
+   * @return
+   * @throws IOException
+   */
+  private File makeGlobalJar() throws IOException {
+    final File jarFile = new File(this.fileNames.getGlobalFolderName() + this.fileNames.getJarFileSuffix());
+    new JARFileMaker(jarFile).addChildren(this.fileNames.getGlobalFolder()).close();
+    return jarFile;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/REEFEventHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/REEFEventHandlers.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/REEFEventHandlers.java
new file mode 100644
index 0000000..ec43666
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/REEFEventHandlers.java
@@ -0,0 +1,91 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.api.RuntimeParameters;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+
+/**
+ * Helper that represents the REEF layer to the YARN runtime.
+ */
+// This is a great place to add a thread boundary, should that need arise.
+@Private
+final class REEFEventHandlers implements AutoCloseable {
+  private final EventHandler<DriverRuntimeProtocol.ResourceAllocationProto> resourceAllocationHandler;
+  private final EventHandler<DriverRuntimeProtocol.ResourceStatusProto> resourceStatusHandler;
+  private final EventHandler<DriverRuntimeProtocol.RuntimeStatusProto> runtimeStatusHandler;
+  private final EventHandler<DriverRuntimeProtocol.NodeDescriptorProto> nodeDescriptorProtoEventHandler;
+
+  @Inject
+  REEFEventHandlers(final @Parameter(RuntimeParameters.NodeDescriptorHandler.class) EventHandler<DriverRuntimeProtocol.NodeDescriptorProto> nodeDescriptorProtoEventHandler,
+                    final @Parameter(RuntimeParameters.RuntimeStatusHandler.class) EventHandler<DriverRuntimeProtocol.RuntimeStatusProto> runtimeStatusProtoEventHandler,
+                    final @Parameter(RuntimeParameters.ResourceAllocationHandler.class) EventHandler<DriverRuntimeProtocol.ResourceAllocationProto> resourceAllocationHandler,
+                    final @Parameter(RuntimeParameters.ResourceStatusHandler.class) EventHandler<DriverRuntimeProtocol.ResourceStatusProto> resourceStatusHandler) {
+    this.resourceAllocationHandler = resourceAllocationHandler;
+    this.resourceStatusHandler = resourceStatusHandler;
+    this.runtimeStatusHandler = runtimeStatusProtoEventHandler;
+    this.nodeDescriptorProtoEventHandler = nodeDescriptorProtoEventHandler;
+  }
+
+  /**
+   * Inform reef of a node.
+   *
+   * @param nodeDescriptorProto
+   */
+  void onNodeDescriptor(final DriverRuntimeProtocol.NodeDescriptorProto nodeDescriptorProto) {
+    this.nodeDescriptorProtoEventHandler.onNext(nodeDescriptorProto);
+  }
+
+  /**
+   * Update REEF's view on the runtime status.
+   *
+   * @param runtimeStatusProto
+   */
+  void onRuntimeStatus(final DriverRuntimeProtocol.RuntimeStatusProto runtimeStatusProto) {
+    this.runtimeStatusHandler.onNext(runtimeStatusProto);
+  }
+
+  /**
+   * Inform REEF of a fresh resource allocation.
+   *
+   * @param resourceAllocationProto
+   */
+  void onResourceAllocation(final DriverRuntimeProtocol.ResourceAllocationProto resourceAllocationProto) {
+    this.resourceAllocationHandler.onNext(resourceAllocationProto);
+  }
+
+  /**
+   * Update REEF on a change to the status of a resource.
+   *
+   * @param resourceStatusProto
+   */
+  void onResourceStatus(final DriverRuntimeProtocol.ResourceStatusProto resourceStatusProto) {
+    this.resourceStatusHandler.onNext(resourceStatusProto);
+  }
+
+  @Override
+  public void close() throws Exception {
+    // Empty, but here for a future where we need to close a threadpool
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/TrackingURLProvider.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/TrackingURLProvider.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/TrackingURLProvider.java
new file mode 100644
index 0000000..bbb72a6
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/TrackingURLProvider.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+import org.apache.reef.tang.annotations.DefaultImplementation;
+
+/**
+ * Implement this interface to set the tracking URL reported to YARN.
+ */
+@DefaultImplementation(DefaultTrackingURLProvider.class)
+public interface TrackingURLProvider {
+  public String getTrackingUrl();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/UploaderToJobfolder.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/UploaderToJobfolder.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/UploaderToJobfolder.java
new file mode 100644
index 0000000..afc1d9c
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/UploaderToJobfolder.java
@@ -0,0 +1,94 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+import org.apache.hadoop.fs.FileContext;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.yarn.api.records.LocalResource;
+import org.apache.hadoop.yarn.api.records.LocalResourceType;
+import org.apache.hadoop.yarn.api.records.LocalResourceVisibility;
+import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.apache.hadoop.yarn.util.ConverterUtils;
+import org.apache.hadoop.yarn.util.Records;
+import org.apache.reef.runtime.yarn.driver.parameters.JobSubmissionDirectory;
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Uploads files to the current job folder.
+ */
+final class UploaderToJobFolder {
+  private static final Logger LOG = Logger.getLogger(UploaderToJobFolder.class.getName());
+
+  /**
+   * The path on (H)DFS which is used as the job's folder.
+   */
+  private final String jobSubmissionDirectory;
+  /**
+   * The FileSystem instance to use for fs operations.
+   */
+  private final FileSystem fileSystem;
+
+  @Inject
+  UploaderToJobFolder(final @Parameter(JobSubmissionDirectory.class) String jobSubmissionDirectory,
+                      final YarnConfiguration yarnConfiguration) throws IOException {
+    this.jobSubmissionDirectory = jobSubmissionDirectory;
+    this.fileSystem = FileSystem.get(yarnConfiguration);
+  }
+
+  /**
+   * Uploads the given file to the job folder on (H)DFS.
+   *
+   * @param file
+   * @return
+   * @throws java.io.IOException
+   */
+  Path uploadToJobFolder(final File file) throws IOException {
+    final Path source = new Path(file.getAbsolutePath());
+    final Path destination = new Path(this.jobSubmissionDirectory + "/" + file.getName());
+    LOG.log(Level.FINE, "Uploading {0} to {1}", new Object[]{source, destination});
+    this.fileSystem.copyFromLocalFile(false, true, source, destination);
+    return destination;
+  }
+
+  /**
+   * Creates a LocalResource instance for the JAR file referenced by the given Path
+   *
+   * @param path
+   * @return
+   * @throws IOException
+   */
+  LocalResource makeLocalResourceForJarFile(final Path path) throws IOException {
+    final LocalResource localResource = Records.newRecord(LocalResource.class);
+    final FileStatus status = FileContext.getFileContext(this.fileSystem.getUri()).getFileStatus(path);
+    localResource.setType(LocalResourceType.ARCHIVE);
+    localResource.setVisibility(LocalResourceVisibility.APPLICATION);
+    localResource.setResource(ConverterUtils.getYarnUrlFromPath(status.getPath()));
+    localResource.setTimestamp(status.getModificationTime());
+    localResource.setSize(status.getLen());
+    return localResource;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YARNResourceLaunchHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YARNResourceLaunchHandler.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YARNResourceLaunchHandler.java
new file mode 100644
index 0000000..073cf8c
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YARNResourceLaunchHandler.java
@@ -0,0 +1,125 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.hadoop.yarn.api.ApplicationConstants;
+import org.apache.hadoop.yarn.api.records.Container;
+import org.apache.hadoop.yarn.api.records.ContainerLaunchContext;
+import org.apache.hadoop.yarn.api.records.LocalResource;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.api.ResourceLaunchHandler;
+import org.apache.reef.runtime.common.files.ClasspathProvider;
+import org.apache.reef.runtime.common.files.REEFFileNames;
+import org.apache.reef.runtime.common.launch.CLRLaunchCommandBuilder;
+import org.apache.reef.runtime.common.launch.JavaLaunchCommandBuilder;
+import org.apache.reef.runtime.common.launch.LaunchCommandBuilder;
+import org.apache.reef.runtime.common.parameters.JVMHeapSlack;
+import org.apache.reef.runtime.yarn.util.YarnTypes;
+import org.apache.reef.tang.InjectionFuture;
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Resource launch handler for YARN.
+ */
+public final class YARNResourceLaunchHandler implements ResourceLaunchHandler {
+
+  private static final Logger LOG = Logger.getLogger(YARNResourceLaunchHandler.class.getName());
+
+  private final Containers containers;
+  private final InjectionFuture<YarnContainerManager> yarnContainerManager;
+  private final EvaluatorSetupHelper evaluatorSetupHelper;
+  private final REEFFileNames filenames;
+  private final ClasspathProvider classpath;
+  private final double jvmHeapFactor;
+
+  @Inject
+  YARNResourceLaunchHandler(final Containers containers,
+                            final InjectionFuture<YarnContainerManager> yarnContainerManager,
+                            final EvaluatorSetupHelper evaluatorSetupHelper,
+                            final REEFFileNames filenames,
+                            final ClasspathProvider classpath,
+                            final @Parameter(JVMHeapSlack.class) double jvmHeapSlack) {
+    this.jvmHeapFactor = 1.0 - jvmHeapSlack;
+    LOG.log(Level.FINEST, "Instantiating 'YARNResourceLaunchHandler'");
+    this.containers = containers;
+    this.yarnContainerManager = yarnContainerManager;
+    this.evaluatorSetupHelper = evaluatorSetupHelper;
+    this.filenames = filenames;
+    this.classpath = classpath;
+    LOG.log(Level.FINE, "Instantiated 'YARNResourceLaunchHandler'");
+  }
+
+  @Override
+  public void onNext(final DriverRuntimeProtocol.ResourceLaunchProto resourceLaunchProto) {
+    try {
+
+      final String containerId = resourceLaunchProto.getIdentifier();
+      LOG.log(Level.FINEST, "TIME: Start ResourceLaunchProto {0}", containerId);
+      final Container container = this.containers.get(containerId);
+      LOG.log(Level.FINEST, "Setting up container launch container for id={0}", container.getId());
+      final Map<String, LocalResource> localResources =
+          this.evaluatorSetupHelper.getResources(resourceLaunchProto);
+
+      final LaunchCommandBuilder commandBuilder;
+      switch (resourceLaunchProto.getType()) {
+        case JVM:
+          commandBuilder = new JavaLaunchCommandBuilder()
+              .setClassPath(this.classpath.getEvaluatorClasspath());
+          break;
+        case CLR:
+          commandBuilder = new CLRLaunchCommandBuilder();
+          break;
+        default:
+          throw new IllegalArgumentException(
+              "Unsupported container type: " + resourceLaunchProto.getType());
+      }
+
+      final List<String> command = commandBuilder
+          .setErrorHandlerRID(resourceLaunchProto.getRemoteId())
+          .setLaunchID(resourceLaunchProto.getIdentifier())
+          .setConfigurationFileName(this.filenames.getEvaluatorConfigurationPath())
+          .setMemory((int) (this.jvmHeapFactor * container.getResource().getMemory()))
+          .setStandardErr(ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/" + this.filenames.getEvaluatorStderrFileName())
+          .setStandardOut(ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/" + this.filenames.getEvaluatorStdoutFileName())
+          .build();
+
+      if (LOG.isLoggable(Level.FINEST)) {
+        LOG.log(Level.FINEST,
+            "TIME: Run ResourceLaunchProto {0} command: `{1}` with resources: `{2}`",
+            new Object[]{containerId, StringUtils.join(command, ' '), localResources});
+      }
+
+      final ContainerLaunchContext ctx = YarnTypes.getContainerLaunchContext(command, localResources);
+      this.yarnContainerManager.get().submit(container, ctx);
+
+      LOG.log(Level.FINEST, "TIME: End ResourceLaunchProto {0}", containerId);
+
+    } catch (final Throwable e) {
+      LOG.log(Level.WARNING, "Error handling resource launch message: " + resourceLaunchProto, e);
+      throw new RuntimeException(e);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YARNResourceReleaseHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YARNResourceReleaseHandler.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YARNResourceReleaseHandler.java
new file mode 100644
index 0000000..dda9fb3
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YARNResourceReleaseHandler.java
@@ -0,0 +1,50 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.api.ResourceReleaseHandler;
+import org.apache.reef.tang.InjectionFuture;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * ResourceReleaseHandler for YARN.
+ */
+public final class YARNResourceReleaseHandler implements ResourceReleaseHandler {
+
+  private static final Logger LOG = Logger.getLogger(YARNResourceReleaseHandler.class.getName());
+
+  private final InjectionFuture<YarnContainerManager> yarnContainerManager;
+
+  @Inject
+  YARNResourceReleaseHandler(final InjectionFuture<YarnContainerManager> yarnContainerManager) {
+    this.yarnContainerManager = yarnContainerManager;
+    LOG.log(Level.FINE, "Instantiated 'YARNResourceReleaseHandler'");
+  }
+
+  @Override
+  public void onNext(final DriverRuntimeProtocol.ResourceReleaseProto resourceReleaseProto) {
+    final String containerId = resourceReleaseProto.getIdentifier();
+    LOG.log(Level.FINEST, "Releasing container {0}", containerId);
+    this.yarnContainerManager.get().release(containerId);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YARNRuntimeStartHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YARNRuntimeStartHandler.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YARNRuntimeStartHandler.java
new file mode 100644
index 0000000..c8ab5b2
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YARNRuntimeStartHandler.java
@@ -0,0 +1,42 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.runtime.event.RuntimeStart;
+
+import javax.inject.Inject;
+
+/**
+ * Handler of RuntimeStart for the YARN Runtime.
+ */
+public final class YARNRuntimeStartHandler implements EventHandler<RuntimeStart> {
+
+  private final YarnContainerManager yarnContainerManager;
+
+  @Inject
+  public YARNRuntimeStartHandler(final YarnContainerManager yarnContainerManager) {
+    this.yarnContainerManager = yarnContainerManager;
+  }
+
+  @Override
+  public void onNext(final RuntimeStart runtimeStart) {
+    this.yarnContainerManager.onStart();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YARNRuntimeStopHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YARNRuntimeStopHandler.java b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YARNRuntimeStopHandler.java
new file mode 100644
index 0000000..b79c906
--- /dev/null
+++ b/lang/java/reef-runtime-yarn/src/main/java/org/apache/reef/runtime/yarn/driver/YARNRuntimeStopHandler.java
@@ -0,0 +1,42 @@
+/**
+ * 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.reef.runtime.yarn.driver;
+
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.runtime.event.RuntimeStop;
+
+import javax.inject.Inject;
+
+/**
+ * Shuts down the YARN resource manager.
+ */
+public final class YARNRuntimeStopHandler implements EventHandler<RuntimeStop> {
+
+  private final YarnContainerManager yarnContainerManager;
+
+  @Inject
+  YARNRuntimeStopHandler(final YarnContainerManager yarnContainerManager) {
+    this.yarnContainerManager = yarnContainerManager;
+  }
+
+  @Override
+  public void onNext(final RuntimeStop runtimeStop) {
+    this.yarnContainerManager.onStop();
+  }
+}


[25/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/CodecRamMap.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/CodecRamMap.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/CodecRamMap.java
new file mode 100644
index 0000000..fd2e80f
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/CodecRamMap.java
@@ -0,0 +1,84 @@
+/**
+ * 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.reef.io.storage.ram;
+
+import org.apache.reef.io.ExternalMap;
+import org.apache.reef.io.serialization.Codec;
+import org.apache.reef.io.storage.util.GetAllIterable;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentSkipListMap;
+
+public class CodecRamMap<T> implements ExternalMap<T> {
+
+  private final Codec<T> c;
+  private final ConcurrentSkipListMap<CharSequence, byte[]> map;
+
+  @Inject
+  public CodecRamMap(RamStorageService ramStore,
+                     @Parameter(RamMapCodec.class) final Codec<T> c) {
+    this.c = c;
+    this.map = new ConcurrentSkipListMap<CharSequence, byte[]>();
+  }
+
+  @Override
+  public boolean containsKey(final CharSequence key) {
+    return map.containsKey(key);
+  }
+
+  @Override
+  public T get(final CharSequence key) {
+    final byte[] ret = map.get(key);
+    return ret != null ? c.decode(ret) : null;
+  }
+
+  @Override
+  public T put(final CharSequence key, T value) {
+    final byte[] ret = map.put(key, c.encode(value));
+    return ret != null ? c.decode(ret) : null;
+  }
+
+  @Override
+  public T remove(final CharSequence key) {
+    final byte[] ret = map.remove(key);
+    return ret != null ? c.decode(ret) : null;
+  }
+
+  @Override
+  public void putAll(final Map<? extends CharSequence, ? extends T> m) {
+    for (final CharSequence x : m.keySet()) {
+      map.put(x, c.encode(m.get(x)));
+    }
+  }
+
+  @Override
+  public Iterable<Map.Entry<CharSequence, T>> getAll(
+      final Set<? extends CharSequence> keys) {
+    return new GetAllIterable<T>(keys, this);
+  }
+
+  @NamedParameter
+  static public class RamMapCodec implements Name<Codec<?>> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/RamMap.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/RamMap.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/RamMap.java
new file mode 100644
index 0000000..35a20e1
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/RamMap.java
@@ -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.reef.io.storage.ram;
+
+import org.apache.reef.io.ExternalMap;
+import org.apache.reef.io.storage.util.GetAllIterable;
+
+import javax.inject.Inject;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.concurrent.ConcurrentSkipListMap;
+
+/**
+ * Simple in-memory ExternalMap implementation.  This class does not require
+ * any codecs, and so is guaranteed to be instantiable.  Therefore, it is the
+ * default ExternalMap provided by StorageManagerRam.
+ */
+public class RamMap<T> implements ExternalMap<T> {
+  private final ConcurrentSkipListMap<CharSequence, T> map
+      = new ConcurrentSkipListMap<CharSequence, T>();
+
+  @Inject
+  public RamMap(RamStorageService ramStore) {
+    //this.localStore = localStore;
+  }
+
+  @Override
+  public boolean containsKey(CharSequence key) {
+    return map.containsKey(key);
+  }
+
+  @Override
+  public T get(CharSequence key) {
+    return map.get(key);
+  }
+
+  @Override
+  public T put(CharSequence key, T value) {
+    return map.put(key, value);
+  }
+
+  @Override
+  public T remove(CharSequence key) {
+    return map.remove(key);
+  }
+
+  @Override
+  public void putAll(Map<? extends CharSequence, ? extends T> m) {
+    map.putAll(m);
+  }
+
+  @Override
+  public Iterable<Entry<CharSequence, T>> getAll(Set<? extends CharSequence> keys) {
+    return new GetAllIterable<>(keys, this);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/RamSpool.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/RamSpool.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/RamSpool.java
new file mode 100644
index 0000000..dc7e606
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/RamSpool.java
@@ -0,0 +1,72 @@
+/**
+ * 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.reef.io.storage.ram;
+
+import org.apache.reef.io.Accumulator;
+import org.apache.reef.io.Spool;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * A SpoolFile implementation that is backed by RAM.
+ * <p/>
+ * It uses an ArrayList to store the objects in.
+ */
+public final class RamSpool<T> implements Spool<T> {
+
+  private final List<T> backingStore = new ArrayList<T>();
+  private boolean canAppend = true;
+  private boolean canGetAccumulator = true;
+
+  @Inject
+  public RamSpool(RamStorageService ramStore) {
+  }
+
+  @Override
+  public Iterator<T> iterator() {
+    canAppend = false;
+    return backingStore.iterator();
+  }
+
+  @Override
+  public Accumulator<T> accumulator() {
+    if (!canGetAccumulator) {
+      throw new UnsupportedOperationException("Can only getAccumulator() once!");
+    }
+    canGetAccumulator = false;
+    return new Accumulator<T>() {
+      @Override
+      public void add(T datum) {
+        if (!canAppend) {
+          throw new ConcurrentModificationException("Attempt to append after creating iterator!");
+        }
+        backingStore.add(datum);
+      }
+
+      @Override
+      public void close() {
+        canAppend = false;
+      }
+    };
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/RamStorageService.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/RamStorageService.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/RamStorageService.java
new file mode 100644
index 0000000..64e489a
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/RamStorageService.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.io.storage.ram;
+
+import org.apache.reef.io.storage.ScratchSpace;
+import org.apache.reef.io.storage.StorageService;
+
+import javax.inject.Inject;
+
+public class RamStorageService implements StorageService {
+  @Inject
+  public RamStorageService() {
+  }
+
+  // TODO move getScratchSpace into its own class, just like everything else.
+  // TODO add context object or something to StorageService
+  @Override
+  public ScratchSpace getScratchSpace() {
+    throw new UnsupportedOperationException(
+        "No temp space / tracking of temp space for main memory (yet).");
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/SortingRamSpool.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/SortingRamSpool.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/SortingRamSpool.java
new file mode 100644
index 0000000..175c7a6
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/ram/SortingRamSpool.java
@@ -0,0 +1,90 @@
+/**
+ * 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.reef.io.storage.ram;
+
+import org.apache.reef.exception.evaluator.StorageException;
+import org.apache.reef.io.Accumulator;
+import org.apache.reef.io.Spool;
+
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.PriorityQueue;
+
+public class SortingRamSpool<T> implements Spool<T> {
+  private final PriorityQueue<T> heap;
+  private boolean ready = false;
+  private Accumulator<T> acc = new Accumulator<T>() {
+    @Override
+    public void add(T datum) throws StorageException {
+      if (ready)
+        throw new IllegalStateException("add called after close!");
+      heap.add(datum);
+    }
+
+    @Override
+    public void close() throws StorageException {
+      ready = true;
+    }
+  };
+  private Iterator<T> it = new Iterator<T>() {
+
+    @Override
+    public boolean hasNext() {
+      return !heap.isEmpty();
+    }
+
+    @Override
+    public T next() {
+      return heap.remove();
+    }
+
+    @Override
+    public void remove() {
+      throw new UnsupportedOperationException(
+          "This iterator consumes the data it returns. remove() does not make any sense!");
+    }
+
+  };
+
+  public SortingRamSpool() {
+    heap = new PriorityQueue<>();
+  }
+
+  public SortingRamSpool(Comparator<T> c) {
+    heap = new PriorityQueue<>(11, c);
+  }
+
+  @Override
+  public Iterator<T> iterator() {
+    if (!ready) {
+      throw new IllegalStateException("Cannot call iterator() while accumulator is still open!");
+    }
+    Iterator<T> ret = it;
+    it = null;
+    return ret;
+  }
+
+  @Override
+  public Accumulator<T> accumulator() throws StorageException {
+    Accumulator<T> ret = acc;
+    acc = null;
+    return ret;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/GetAllIterable.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/GetAllIterable.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/GetAllIterable.java
new file mode 100644
index 0000000..b0b892d
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/GetAllIterable.java
@@ -0,0 +1,95 @@
+/**
+ * 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.reef.io.storage.util;
+
+import org.apache.reef.io.ExternalMap;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+public class GetAllIterable<T> implements
+    Iterable<Map.Entry<CharSequence, T>> {
+  private final Set<? extends CharSequence> keys;
+  private final ExternalMap<T> map;
+
+  public GetAllIterable(Set<? extends CharSequence> keys, ExternalMap<T> map) {
+    this.keys = keys;
+    this.map = map;
+  }
+
+  @Override
+  public Iterator<Map.Entry<CharSequence, T>> iterator() {
+    final Iterator<? extends CharSequence> k = keys.iterator();
+    return new Iterator<Map.Entry<CharSequence, T>>() {
+      CharSequence lastKey = null;
+      CharSequence curKey = findNextKey();
+
+      private CharSequence findNextKey() {
+        while (k.hasNext()) {
+          CharSequence next = k.next();
+          if (map.containsKey(next)) {
+            return next;
+          }
+        }
+        return null;
+      }
+
+      @Override
+      public boolean hasNext() {
+        return curKey != null;
+      }
+
+      @Override
+      public Map.Entry<CharSequence, T> next() {
+        final CharSequence key = curKey;
+        curKey = findNextKey();
+        lastKey = key;
+        if (key == null)
+          throw new NoSuchElementException();
+
+        final T v = map.get(key);
+
+        return new Map.Entry<CharSequence, T>() {
+          @Override
+          public CharSequence getKey() {
+            return key;
+          }
+
+          @Override
+          public T getValue() {
+            return v;
+          }
+
+          @Override
+          public T setValue(T v) {
+            throw new UnsupportedOperationException(
+                "No support for mutating values via iterator");
+          }
+        };
+      }
+
+      @Override
+      public void remove() {
+        map.remove(lastKey);
+      }
+    };
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/IntegerCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/IntegerCodec.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/IntegerCodec.java
new file mode 100644
index 0000000..12e1bd9
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/IntegerCodec.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.io.storage.util;
+
+import org.apache.reef.io.serialization.Codec;
+
+public class IntegerCodec implements Codec<Integer> {
+
+  @Override
+  public byte[] encode(Integer obj) {
+    return Integer.toString(obj).getBytes();
+  }
+
+  @Override
+  public Integer decode(byte[] buf) {
+    return Integer.decode(new String(buf));
+  }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/IntegerDeserializer.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/IntegerDeserializer.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/IntegerDeserializer.java
new file mode 100644
index 0000000..5bd3641
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/IntegerDeserializer.java
@@ -0,0 +1,62 @@
+/**
+ * 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.reef.io.storage.util;
+
+import org.apache.reef.exception.evaluator.ServiceRuntimeException;
+import org.apache.reef.io.serialization.Deserializer;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+
+public class IntegerDeserializer implements
+    Deserializer<Integer, InputStream> {
+  @Override
+  public Iterable<Integer> create(InputStream arg) {
+    final DataInputStream dis = new DataInputStream(arg);
+    return new Iterable<Integer>() {
+
+      @Override
+      public Iterator<Integer> iterator() {
+        return new Iterator<Integer>() {
+
+          @Override
+          public void remove() {
+            throw new UnsupportedOperationException();
+          }
+
+          @Override
+          public Integer next() {
+            try {
+              return dis.readInt();
+            } catch (IOException e) {
+              throw new ServiceRuntimeException(e);
+            }
+          }
+
+          @Override
+          public boolean hasNext() {
+            throw new UnsupportedOperationException();
+          }
+        };
+      }
+    };
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/IntegerSerializer.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/IntegerSerializer.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/IntegerSerializer.java
new file mode 100644
index 0000000..69296cc
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/IntegerSerializer.java
@@ -0,0 +1,62 @@
+/**
+ * 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.reef.io.storage.util;
+
+import org.apache.reef.exception.evaluator.ServiceException;
+import org.apache.reef.io.Accumulable;
+import org.apache.reef.io.Accumulator;
+import org.apache.reef.io.serialization.Serializer;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class IntegerSerializer implements
+    Serializer<Integer, OutputStream> {
+  @Override
+  public Accumulable<Integer> create(OutputStream arg) {
+    final DataOutputStream dos = new DataOutputStream(arg);
+    return new Accumulable<Integer>() {
+
+      @Override
+      public Accumulator<Integer> accumulator() throws ServiceException {
+        return new Accumulator<Integer>() {
+          @Override
+          public void add(Integer datum) throws ServiceException {
+            try {
+              dos.writeInt(datum);
+            } catch (IOException e) {
+              throw new ServiceException(e);
+            }
+          }
+
+          @Override
+          public void close() throws ServiceException {
+            try {
+              dos.close();
+            } catch (IOException e) {
+              throw new ServiceException(e);
+            }
+          }
+
+        };
+      }
+    };
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/StringDeserializer.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/StringDeserializer.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/StringDeserializer.java
new file mode 100644
index 0000000..c1108f4
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/StringDeserializer.java
@@ -0,0 +1,66 @@
+/**
+ * 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.reef.io.storage.util;
+
+import org.apache.reef.exception.evaluator.ServiceRuntimeException;
+import org.apache.reef.io.serialization.Deserializer;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+
+public class StringDeserializer implements
+    Deserializer<String, InputStream> {
+  @Override
+  public Iterable<String> create(InputStream arg) {
+    final DataInputStream dis = new DataInputStream(arg);
+    return new Iterable<String>() {
+
+      @Override
+      public Iterator<String> iterator() {
+        return new Iterator<String>() {
+
+          @Override
+          public void remove() {
+            throw new UnsupportedOperationException();
+          }
+
+          @Override
+          public String next() {
+            int len = 0;
+            try {
+              len = dis.readInt();
+              byte[] b = new byte[len];
+              dis.readFully(b);
+              return new String(b);
+            } catch (IOException e) {
+              throw new ServiceRuntimeException(e);
+            }
+          }
+
+          @Override
+          public boolean hasNext() {
+            throw new UnsupportedOperationException();
+          }
+        };
+      }
+    };
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/StringSerializer.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/StringSerializer.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/StringSerializer.java
new file mode 100644
index 0000000..6cf544e
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/StringSerializer.java
@@ -0,0 +1,65 @@
+/**
+ * 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.reef.io.storage.util;
+
+import org.apache.reef.exception.evaluator.ServiceException;
+import org.apache.reef.io.Accumulable;
+import org.apache.reef.io.Accumulator;
+import org.apache.reef.io.serialization.Serializer;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class StringSerializer implements
+    Serializer<String, OutputStream> {
+  @Override
+  public Accumulable<String> create(OutputStream arg) {
+    final DataOutputStream dos = new DataOutputStream(arg);
+    return new Accumulable<String>() {
+
+      @Override
+      public Accumulator<String> accumulator() throws ServiceException {
+        return new Accumulator<String>() {
+
+          @Override
+          public void add(String datum) throws ServiceException {
+            byte[] b = datum.getBytes();
+            try {
+              dos.writeInt(b.length);
+              dos.write(b);
+            } catch (IOException e) {
+              throw new ServiceException(e);
+            }
+
+          }
+
+          @Override
+          public void close() throws ServiceException {
+            try {
+              dos.close();
+            } catch (IOException e) {
+              throw new ServiceException(e);
+            }
+          }
+        };
+      }
+    };
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/TupleKeyComparator.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/TupleKeyComparator.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/TupleKeyComparator.java
new file mode 100644
index 0000000..ae690f4
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/storage/util/TupleKeyComparator.java
@@ -0,0 +1,37 @@
+/**
+ * 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.reef.io.storage.util;
+
+import org.apache.reef.io.Tuple;
+
+import java.util.Comparator;
+
+public final class TupleKeyComparator<K, V> implements
+    Comparator<Tuple<K, V>> {
+  private final Comparator<K> c;
+
+  public TupleKeyComparator(Comparator<K> c) {
+    this.c = c;
+  }
+
+  @Override
+  public int compare(Tuple<K, V> o1, Tuple<K, V> o2) {
+    return c.compare(o1.getKey(), o2.getKey());
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/proto/ns_protocol.proto
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/proto/ns_protocol.proto b/lang/java/reef-io/src/main/proto/ns_protocol.proto
new file mode 100644
index 0000000..1a9db1e
--- /dev/null
+++ b/lang/java/reef-io/src/main/proto/ns_protocol.proto
@@ -0,0 +1,32 @@
+/**
+ * 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.
+ */
+option java_package = "org.apache.reef.io.network.proto";
+option java_outer_classname = "ReefNetworkServiceProtos";
+option java_generic_services = true;
+option java_generate_equals_and_hash = true;
+
+message NSMessagePBuf {
+  required string srcid = 2;
+  required string destid = 3;
+  repeated NSRecordPBuf msgs = 4;
+}
+
+message NSRecordPBuf {
+  required bytes data = 1;
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/test/java/org/apache/reef/services/network/NameClientTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/test/java/org/apache/reef/services/network/NameClientTest.java b/lang/java/reef-io/src/test/java/org/apache/reef/services/network/NameClientTest.java
new file mode 100644
index 0000000..f1f1a60
--- /dev/null
+++ b/lang/java/reef-io/src/test/java/org/apache/reef/services/network/NameClientTest.java
@@ -0,0 +1,123 @@
+/**
+ * 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.reef.services.network;
+
+import org.apache.reef.io.network.naming.*;
+import org.apache.reef.io.network.naming.exception.NamingException;
+import org.apache.reef.io.network.util.StringIdentifierFactory;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.wake.Identifier;
+import org.apache.reef.wake.IdentifierFactory;
+import org.apache.reef.wake.remote.NetUtils;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.net.InetSocketAddress;
+import java.util.concurrent.ExecutionException;
+
+public class NameClientTest {
+
+  static int retryCount, retryTimeout;
+
+  static {
+    Tang tang = Tang.Factory.getTang();
+    try {
+      retryCount = tang.newInjector().getNamedInstance(NameLookupClient.RetryCount.class);
+      retryTimeout = tang.newInjector().getNamedInstance(NameLookupClient.RetryTimeout.class);
+    } catch (InjectionException e1) {
+      throw new RuntimeException("Exception while trying to find default values for retryCount & Timeout", e1);
+    }
+  }
+
+  /**
+   * @throws java.lang.Exception
+   */
+  @BeforeClass
+  public static void setUpBeforeClass() throws Exception {
+  }
+
+  /**
+   * @throws java.lang.Exception
+   */
+  @AfterClass
+  public static void tearDownAfterClass() throws Exception {
+  }
+
+  /**
+   * Test method for {@link org.apache.reef.io.network.naming.NameClient#close()}.
+   *
+   * @throws Exception
+   */
+  @Test
+  public final void testClose() throws Exception {
+    IdentifierFactory factory = new StringIdentifierFactory();
+    try (NameServer server = new NameServerImpl(0, factory)) {
+      int serverPort = server.getPort();
+      try (NameClient client = new NameClient(NetUtils.getLocalAddress(), serverPort, factory, retryCount, retryTimeout,
+          new NameCache(10000))) {
+        Identifier id = factory.getNewInstance("Task1");
+        client.register(id, new InetSocketAddress(NetUtils.getLocalAddress(), 7001));
+        client.unregister(id);
+        Thread.sleep(100);
+      }
+    }
+  }
+
+  /**
+   * Test method for {@link org.apache.reef.io.network.naming.NameClient#lookup()}.
+   * To check caching behavior with expireAfterAccess & expireAfterWrite
+   * Changing NameCache's pattern to expireAfterAccess causes this test to fail
+   *
+   * @throws Exception
+   */
+  @Test
+  public final void testLookup() throws Exception {
+    IdentifierFactory factory = new StringIdentifierFactory();
+    try (NameServer server = new NameServerImpl(0, factory)) {
+      int serverPort = server.getPort();
+      try (NameClient client = new NameClient(NetUtils.getLocalAddress(), serverPort, factory, retryCount, retryTimeout,
+          new NameCache(150))) {
+        Identifier id = factory.getNewInstance("Task1");
+        client.register(id, new InetSocketAddress(NetUtils.getLocalAddress(), 7001));
+        client.lookup(id);// caches the entry
+        client.unregister(id);
+        Thread.sleep(100);
+        try {
+          InetSocketAddress addr = client.lookup(id);
+          Thread.sleep(100);
+          //With expireAfterAccess, the previous lookup would reset expiry to 150ms
+          //more and 100ms wait will not expire the item and will return the cached value
+          //With expireAfterWrite, the extra wait of 100 ms will expire the item
+          //resulting in NamingException and the test passes
+          addr = client.lookup(id);
+          Assert.assertNull("client.lookup(id)", addr);
+        } catch (Exception e) {
+          if (e instanceof ExecutionException) {
+            Assert.assertTrue("Execution Exception cause is instanceof NamingException", e.getCause() instanceof NamingException);
+          } else
+            throw e;
+        }
+      }
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/test/java/org/apache/reef/services/network/NamingTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/test/java/org/apache/reef/services/network/NamingTest.java b/lang/java/reef-io/src/test/java/org/apache/reef/services/network/NamingTest.java
new file mode 100644
index 0000000..71382e2
--- /dev/null
+++ b/lang/java/reef-io/src/test/java/org/apache/reef/services/network/NamingTest.java
@@ -0,0 +1,367 @@
+/**
+ * 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.reef.services.network;
+
+import org.apache.reef.io.naming.NameAssignment;
+import org.apache.reef.io.network.naming.*;
+import org.apache.reef.io.network.util.StringIdentifierFactory;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.wake.Identifier;
+import org.apache.reef.wake.IdentifierFactory;
+import org.apache.reef.wake.remote.NetUtils;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+import java.net.InetSocketAddress;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Naming server and client test
+ */
+public class NamingTest {
+
+  private static final Logger LOG = Logger.getLogger(NamingTest.class.getName());
+  private static final int retryCount;
+  private static final int retryTimeout;
+
+  static {
+    try {
+      final Injector injector = Tang.Factory.getTang().newInjector();
+      retryCount = injector.getNamedInstance(NameLookupClient.RetryCount.class);
+      retryTimeout = injector.getNamedInstance(NameLookupClient.RetryTimeout.class);
+    } catch (final InjectionException ex) {
+      final String msg = "Exception while trying to find default values for retryCount & Timeout";
+      LOG.log(Level.SEVERE, msg, ex);
+      throw new RuntimeException(msg, ex);
+    }
+  }
+
+  @Rule
+  public final TestName name = new TestName();
+  final long TTL = 30000;
+  final IdentifierFactory factory = new StringIdentifierFactory();
+  int port;
+
+  /**
+   * NameServer and NameLookupClient test
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testNamingLookup() throws Exception {
+
+    LOG.log(Level.FINEST, this.name.getMethodName());
+
+    // names 
+    final Map<Identifier, InetSocketAddress> idToAddrMap = new HashMap<Identifier, InetSocketAddress>();
+    idToAddrMap.put(this.factory.getNewInstance("task1"), new InetSocketAddress(NetUtils.getLocalAddress(), 7001));
+    idToAddrMap.put(this.factory.getNewInstance("task2"), new InetSocketAddress(NetUtils.getLocalAddress(), 7002));
+
+    // run a server
+    final NameServer server = new NameServerImpl(0, this.factory);
+    this.port = server.getPort();
+    for (final Identifier id : idToAddrMap.keySet()) {
+      server.register(id, idToAddrMap.get(id));
+    }
+
+    // run a client
+    final NameLookupClient client = new NameLookupClient(NetUtils.getLocalAddress(), this.port,
+        10000, this.factory, retryCount, retryTimeout, new NameCache(this.TTL));
+
+    final Identifier id1 = this.factory.getNewInstance("task1");
+    final Identifier id2 = this.factory.getNewInstance("task2");
+
+    final Map<Identifier, InetSocketAddress> respMap = new HashMap<Identifier, InetSocketAddress>();
+    InetSocketAddress addr1 = client.lookup(id1);
+    respMap.put(id1, addr1);
+    InetSocketAddress addr2 = client.lookup(id2);
+    respMap.put(id2, addr2);
+
+    for (final Identifier id : respMap.keySet()) {
+      LOG.log(Level.FINEST, "Mapping: {0} -> {1}", new Object[]{id, respMap.get(id)});
+    }
+
+    Assert.assertTrue(isEqual(idToAddrMap, respMap));
+
+    client.close();
+    server.close();
+  }
+
+  /**
+   * Test concurrent lookups (threads share a client)
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testConcurrentNamingLookup() throws Exception {
+
+    LOG.log(Level.FINEST, this.name.getMethodName());
+
+    // test it 3 times to make failure likely
+    for (int i = 0; i < 3; i++) {
+
+      LOG.log(Level.FINEST, "test {0}", i);
+
+      // names 
+      final Map<Identifier, InetSocketAddress> idToAddrMap = new HashMap<Identifier, InetSocketAddress>();
+      idToAddrMap.put(this.factory.getNewInstance("task1"), new InetSocketAddress(NetUtils.getLocalAddress(), 7001));
+      idToAddrMap.put(this.factory.getNewInstance("task2"), new InetSocketAddress(NetUtils.getLocalAddress(), 7002));
+      idToAddrMap.put(this.factory.getNewInstance("task3"), new InetSocketAddress(NetUtils.getLocalAddress(), 7003));
+
+      // run a server
+      final NameServer server = new NameServerImpl(0, this.factory);
+      this.port = server.getPort();
+      for (final Identifier id : idToAddrMap.keySet()) {
+        server.register(id, idToAddrMap.get(id));
+      }
+
+      // run a client
+      final NameLookupClient client = new NameLookupClient(NetUtils.getLocalAddress(), this.port,
+          10000, this.factory, retryCount, retryTimeout, new NameCache(this.TTL));
+
+      final Identifier id1 = this.factory.getNewInstance("task1");
+      final Identifier id2 = this.factory.getNewInstance("task2");
+      final Identifier id3 = this.factory.getNewInstance("task3");
+
+      final ExecutorService e = Executors.newCachedThreadPool();
+
+      final ConcurrentMap<Identifier, InetSocketAddress> respMap = new ConcurrentHashMap<Identifier, InetSocketAddress>();
+
+      final Future<?> f1 = e.submit(new Runnable() {
+        @Override
+        public void run() {
+          InetSocketAddress addr = null;
+          try {
+            addr = client.lookup(id1);
+          } catch (final Exception e) {
+            LOG.log(Level.SEVERE, "Lookup failed", e);
+            Assert.fail(e.toString());
+          }
+          respMap.put(id1, addr);
+        }
+      });
+      final Future<?> f2 = e.submit(new Runnable() {
+        @Override
+        public void run() {
+          InetSocketAddress addr = null;
+          try {
+            addr = client.lookup(id2);
+          } catch (final Exception e) {
+            LOG.log(Level.SEVERE, "Lookup failed", e);
+            Assert.fail(e.toString());
+          }
+          respMap.put(id2, addr);
+        }
+      });
+      final Future<?> f3 = e.submit(new Runnable() {
+        @Override
+        public void run() {
+          InetSocketAddress addr = null;
+          try {
+            addr = client.lookup(id3);
+          } catch (final Exception e) {
+            LOG.log(Level.SEVERE, "Lookup failed", e);
+            Assert.fail(e.toString());
+          }
+          respMap.put(id3, addr);
+        }
+      });
+
+      f1.get();
+      f2.get();
+      f3.get();
+
+      for (final Identifier id : respMap.keySet()) {
+        LOG.log(Level.FINEST, "Mapping: {0} -> {1}", new Object[]{id, respMap.get(id)});
+      }
+
+      Assert.assertTrue(isEqual(idToAddrMap, respMap));
+
+      client.close();
+      server.close();
+    }
+  }
+
+  /**
+   * NameServer and NameRegistryClient test
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testNamingRegistry() throws Exception {
+
+    LOG.log(Level.FINEST, this.name.getMethodName());
+
+    final NameServer server = new NameServerImpl(0, this.factory);
+    this.port = server.getPort();
+
+    // names to start with
+    final Map<Identifier, InetSocketAddress> idToAddrMap = new HashMap<Identifier, InetSocketAddress>();
+    idToAddrMap.put(this.factory.getNewInstance("task1"), new InetSocketAddress(NetUtils.getLocalAddress(), 7001));
+    idToAddrMap.put(this.factory.getNewInstance("task2"), new InetSocketAddress(NetUtils.getLocalAddress(), 7002));
+
+    // registration
+    // invoke registration from the client side
+    final NameRegistryClient client = new NameRegistryClient(
+        NetUtils.getLocalAddress(), this.port, this.factory);
+    for (final Identifier id : idToAddrMap.keySet()) {
+      client.register(id, idToAddrMap.get(id));
+    }
+
+    // wait
+    final Set<Identifier> ids = idToAddrMap.keySet();
+    busyWait(server, ids.size(), ids);
+
+    // check the server side 
+    Map<Identifier, InetSocketAddress> serverMap = new HashMap<Identifier, InetSocketAddress>();
+    Iterable<NameAssignment> nas = server.lookup(ids);
+
+    for (final NameAssignment na : nas) {
+      LOG.log(Level.FINEST, "Mapping: {0} -> {1}",
+          new Object[]{na.getIdentifier(), na.getAddress()});
+      serverMap.put(na.getIdentifier(), na.getAddress());
+    }
+
+    Assert.assertTrue(isEqual(idToAddrMap, serverMap));
+
+    // un-registration
+    for (final Identifier id : idToAddrMap.keySet()) {
+      client.unregister(id);
+    }
+
+    // wait
+    busyWait(server, 0, ids);
+
+    serverMap = new HashMap<Identifier, InetSocketAddress>();
+    nas = server.lookup(ids);
+    for (final NameAssignment na : nas)
+      serverMap.put(na.getIdentifier(), na.getAddress());
+
+    Assert.assertEquals(0, serverMap.size());
+
+    client.close();
+    server.close();
+  }
+
+  /**
+   * NameServer and NameClient test
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testNameClient() throws Exception {
+
+    LOG.log(Level.FINEST, this.name.getMethodName());
+
+    final NameServer server = new NameServerImpl(0, this.factory);
+    this.port = server.getPort();
+
+    final Map<Identifier, InetSocketAddress> idToAddrMap = new HashMap<Identifier, InetSocketAddress>();
+    idToAddrMap.put(this.factory.getNewInstance("task1"), new InetSocketAddress(NetUtils.getLocalAddress(), 7001));
+    idToAddrMap.put(this.factory.getNewInstance("task2"), new InetSocketAddress(NetUtils.getLocalAddress(), 7002));
+
+    // registration
+    // invoke registration from the client side
+    final NameClient client = new NameClient(NetUtils.getLocalAddress(), this.port,
+        this.factory, retryCount, retryTimeout, new NameCache(this.TTL));
+    for (final Identifier id : idToAddrMap.keySet()) {
+      client.register(id, idToAddrMap.get(id));
+    }
+
+    // wait
+    final Set<Identifier> ids = idToAddrMap.keySet();
+    busyWait(server, ids.size(), ids);
+
+    // lookup
+    final Identifier id1 = this.factory.getNewInstance("task1");
+    final Identifier id2 = this.factory.getNewInstance("task2");
+
+    final Map<Identifier, InetSocketAddress> respMap = new HashMap<Identifier, InetSocketAddress>();
+    InetSocketAddress addr1 = client.lookup(id1);
+    respMap.put(id1, addr1);
+    InetSocketAddress addr2 = client.lookup(id2);
+    respMap.put(id2, addr2);
+
+    for (final Identifier id : respMap.keySet()) {
+      LOG.log(Level.FINEST, "Mapping: {0} -> {1}", new Object[]{id, respMap.get(id)});
+    }
+
+    Assert.assertTrue(isEqual(idToAddrMap, respMap));
+
+    // un-registration
+    for (final Identifier id : idToAddrMap.keySet()) {
+      client.unregister(id);
+    }
+
+    // wait
+    busyWait(server, 0, ids);
+
+    final Map<Identifier, InetSocketAddress> serverMap = new HashMap<Identifier, InetSocketAddress>();
+    addr1 = server.lookup(id1);
+    if (addr1 != null) serverMap.put(id1, addr1);
+    addr2 = server.lookup(id1);
+    if (addr2 != null) serverMap.put(id2, addr2);
+
+    Assert.assertEquals(0, serverMap.size());
+
+    client.close();
+    server.close();
+  }
+
+  private boolean isEqual(final Map<Identifier, InetSocketAddress> map1,
+                          final Map<Identifier, InetSocketAddress> map2) {
+
+    if (map1.size() != map2.size()) {
+      return false;
+    }
+
+    for (final Identifier id : map1.keySet()) {
+      final InetSocketAddress addr1 = map1.get(id);
+      final InetSocketAddress addr2 = map2.get(id);
+      if (!addr1.equals(addr2)) {
+        return false;
+      }
+    }
+
+    return true;
+  }
+
+  private void busyWait(final NameServer server, final int expected, final Set<Identifier> ids) {
+    int count = 0;
+    for (; ; ) {
+      final Iterable<NameAssignment> nas = server.lookup(ids);
+      for (final @SuppressWarnings("unused") NameAssignment na : nas) {
+        ++count;
+      }
+      if (count == expected) {
+        break;
+      }
+      count = 0;
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/test/java/org/apache/reef/services/network/NetworkServiceTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/test/java/org/apache/reef/services/network/NetworkServiceTest.java b/lang/java/reef-io/src/test/java/org/apache/reef/services/network/NetworkServiceTest.java
new file mode 100644
index 0000000..96cf7d4
--- /dev/null
+++ b/lang/java/reef-io/src/test/java/org/apache/reef/services/network/NetworkServiceTest.java
@@ -0,0 +1,495 @@
+/**
+ * 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.reef.services.network;
+
+import org.apache.reef.exception.evaluator.NetworkException;
+import org.apache.reef.io.network.Connection;
+import org.apache.reef.io.network.Message;
+import org.apache.reef.io.network.impl.MessagingTransportFactory;
+import org.apache.reef.io.network.impl.NetworkService;
+import org.apache.reef.io.network.naming.NameServer;
+import org.apache.reef.io.network.naming.NameServerImpl;
+import org.apache.reef.io.network.util.StringIdentifierFactory;
+import org.apache.reef.services.network.util.Monitor;
+import org.apache.reef.services.network.util.StringCodec;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.Identifier;
+import org.apache.reef.wake.IdentifierFactory;
+import org.apache.reef.wake.remote.NetUtils;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+import org.junit.Assert;
+import java.net.InetSocketAddress;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Network service test
+ */
+public class NetworkServiceTest {
+  private static final Logger LOG = Logger.getLogger(NetworkServiceTest.class.getName());
+
+  @Rule
+  public TestName name = new TestName();
+
+  /**
+   * NetworkService messaging test
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testMessagingNetworkService() throws Exception {
+    LOG.log(Level.FINEST, name.getMethodName());
+
+    IdentifierFactory factory = new StringIdentifierFactory();
+    String nameServerAddr = NetUtils.getLocalAddress();
+
+    NameServer server = new NameServerImpl(0, factory);
+    int nameServerPort = server.getPort();
+
+    final int numMessages = 10;
+    final Monitor monitor = new Monitor();
+
+    LOG.log(Level.FINEST, "=== Test network service receiver start");
+    // network service
+    final String name2 = "task2";
+    NetworkService<String> ns2 = new NetworkService<String>(
+        factory, 0, nameServerAddr, nameServerPort,
+        new StringCodec(), new MessagingTransportFactory(),
+        new MessageHandler<String>(name2, monitor, numMessages), new ExceptionHandler());
+    ns2.registerId(factory.getNewInstance(name2));
+    final int port2 = ns2.getTransport().getListeningPort();
+    server.register(factory.getNewInstance("task2"), new InetSocketAddress(nameServerAddr, port2));
+
+    LOG.log(Level.FINEST, "=== Test network service sender start");
+    final String name1 = "task1";
+    final NetworkService<String> ns1 = new NetworkService<String>(factory, 0, nameServerAddr, nameServerPort,
+        new StringCodec(), new MessagingTransportFactory(),
+        new MessageHandler<String>(name1, null, 0), new ExceptionHandler());
+    ns1.registerId(factory.getNewInstance(name1));
+    final int port1 = ns1.getTransport().getListeningPort();
+    server.register(factory.getNewInstance("task1"), new InetSocketAddress(nameServerAddr, port1));
+
+    final Identifier destId = factory.getNewInstance(name2);
+    final Connection<String> conn = ns1.newConnection(destId);
+    try {
+      conn.open();
+      for (int count = 0; count < numMessages; ++count) {
+        conn.write("hello! " + count);
+      }
+      monitor.mwait();
+
+    } catch (NetworkException e) {
+      e.printStackTrace();
+    }
+    conn.close();
+
+    ns1.close();
+    ns2.close();
+
+    server.close();
+  }
+
+  /**
+   * NetworkService messaging rate benchmark
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testMessagingNetworkServiceRate() throws Exception {
+    LOG.log(Level.FINEST, name.getMethodName());
+
+    IdentifierFactory factory = new StringIdentifierFactory();
+    String nameServerAddr = NetUtils.getLocalAddress();
+
+    NameServer server = new NameServerImpl(0, factory);
+    int nameServerPort = server.getPort();
+
+    final int[] messageSizes = {1, 16, 32, 64, 512, 64 * 1024, 1024 * 1024};
+
+    for (int size : messageSizes) {
+      final int numMessages = 300000 / (Math.max(1, size / 512));
+      final Monitor monitor = new Monitor();
+
+      LOG.log(Level.FINEST, "=== Test network service receiver start");
+      // network service
+      final String name2 = "task2";
+      NetworkService<String> ns2 = new NetworkService<String>(
+          factory, 0, nameServerAddr, nameServerPort,
+          new StringCodec(), new MessagingTransportFactory(),
+          new MessageHandler<String>(name2, monitor, numMessages), new ExceptionHandler());
+      ns2.registerId(factory.getNewInstance(name2));
+      final int port2 = ns2.getTransport().getListeningPort();
+      server.register(factory.getNewInstance("task2"), new InetSocketAddress(nameServerAddr, port2));
+
+      LOG.log(Level.FINEST, "=== Test network service sender start");
+      final String name1 = "task1";
+      NetworkService<String> ns1 = new NetworkService<String>(
+          factory, 0, nameServerAddr, nameServerPort,
+          new StringCodec(), new MessagingTransportFactory(),
+          new MessageHandler<String>(name1, null, 0), new ExceptionHandler());
+      ns1.registerId(factory.getNewInstance(name1));
+      final int port1 = ns1.getTransport().getListeningPort();
+      server.register(factory.getNewInstance("task1"), new InetSocketAddress(nameServerAddr, port1));
+
+      Identifier destId = factory.getNewInstance(name2);
+      Connection<String> conn = ns1.newConnection(destId);
+
+      // build the message
+      StringBuilder msb = new StringBuilder();
+      for (int i = 0; i < size; i++) {
+        msb.append("1");
+      }
+      String message = msb.toString();
+
+      long start = System.currentTimeMillis();
+      try {
+        for (int i = 0; i < numMessages; i++) {
+          conn.open();
+          conn.write(message);
+        }
+        monitor.mwait();
+      } catch (NetworkException e) {
+        e.printStackTrace();
+      }
+      long end = System.currentTimeMillis();
+      double runtime = ((double) end - start) / 1000;
+      LOG.log(Level.FINEST, "size: " + size + "; messages/s: " + numMessages / runtime + " bandwidth(bytes/s): " + ((double) numMessages * 2 * size) / runtime);// x2 for unicode chars
+      conn.close();
+
+      ns1.close();
+      ns2.close();
+    }
+
+    server.close();
+  }
+
+  /**
+   * NetworkService messaging rate benchmark
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testMessagingNetworkServiceRateDisjoint() throws Exception {
+    LOG.log(Level.FINEST, name.getMethodName());
+
+    final IdentifierFactory factory = new StringIdentifierFactory();
+    final String nameServerAddr = NetUtils.getLocalAddress();
+
+    final NameServer server = new NameServerImpl(0, factory);
+    final int nameServerPort = server.getPort();
+
+    BlockingQueue<Object> barrier = new LinkedBlockingQueue<Object>();
+
+    int numThreads = 4;
+    final int size = 2000;
+    final int numMessages = 300000 / (Math.max(1, size / 512));
+    final int totalNumMessages = numMessages * numThreads;
+
+    ExecutorService e = Executors.newCachedThreadPool();
+    for (int t = 0; t < numThreads; t++) {
+      final int tt = t;
+
+      e.submit(new Runnable() {
+        public void run() {
+          try {
+            Monitor monitor = new Monitor();
+
+            LOG.log(Level.FINEST, "=== Test network service receiver start");
+            // network service
+            final String name2 = "task2-" + tt;
+            NetworkService<String> ns2 = new NetworkService<String>(
+                factory, 0, nameServerAddr, nameServerPort,
+                new StringCodec(), new MessagingTransportFactory(),
+                new MessageHandler<String>(name2, monitor, numMessages), new ExceptionHandler());
+            ns2.registerId(factory.getNewInstance(name2));
+            final int port2 = ns2.getTransport().getListeningPort();
+            server.register(factory.getNewInstance(name2), new InetSocketAddress(nameServerAddr, port2));
+
+            LOG.log(Level.FINEST, "=== Test network service sender start");
+            final String name1 = "task1-" + tt;
+            NetworkService<String> ns1 = new NetworkService<String>(
+                factory, 0, nameServerAddr, nameServerPort,
+                new StringCodec(), new MessagingTransportFactory(),
+                new MessageHandler<String>(name1, null, 0), new ExceptionHandler());
+            ns1.registerId(factory.getNewInstance(name1));
+            final int port1 = ns1.getTransport().getListeningPort();
+            server.register(factory.getNewInstance(name1), new InetSocketAddress(nameServerAddr, port1));
+
+            Identifier destId = factory.getNewInstance(name2);
+            Connection<String> conn = ns1.newConnection(destId);
+
+            // build the message
+            StringBuilder msb = new StringBuilder();
+            for (int i = 0; i < size; i++) {
+              msb.append("1");
+            }
+            String message = msb.toString();
+
+
+            try {
+              for (int i = 0; i < numMessages; i++) {
+                conn.open();
+                conn.write(message);
+              }
+              monitor.mwait();
+            } catch (NetworkException e) {
+              e.printStackTrace();
+            }
+            conn.close();
+
+            ns1.close();
+            ns2.close();
+          } catch (Exception e) {
+            e.printStackTrace();
+
+          }
+        }
+      });
+    }
+
+    // start and time
+    long start = System.currentTimeMillis();
+    Object ignore = new Object();
+    for (int i = 0; i < numThreads; i++) barrier.add(ignore);
+    e.shutdown();
+    e.awaitTermination(100, TimeUnit.SECONDS);
+    long end = System.currentTimeMillis();
+
+    double runtime = ((double) end - start) / 1000;
+    LOG.log(Level.FINEST, "size: " + size + "; messages/s: " + totalNumMessages / runtime + " bandwidth(bytes/s): " + ((double) totalNumMessages * 2 * size) / runtime);// x2 for unicode chars
+
+    server.close();
+  }
+
+  @Test
+  public void testMultithreadedSharedConnMessagingNetworkServiceRate() throws Exception {
+    LOG.log(Level.FINEST, name.getMethodName());
+
+    IdentifierFactory factory = new StringIdentifierFactory();
+    String nameServerAddr = NetUtils.getLocalAddress();
+
+    NameServer server = new NameServerImpl(0, factory);
+    int nameServerPort = server.getPort();
+
+    final int[] messageSizes = {2000};// {1,16,32,64,512,64*1024,1024*1024};
+
+    for (int size : messageSizes) {
+      final int numMessages = 300000 / (Math.max(1, size / 512));
+      int numThreads = 2;
+      int totalNumMessages = numMessages * numThreads;
+      final Monitor monitor = new Monitor();
+
+      LOG.log(Level.FINEST, "=== Test network service receiver start");
+      // network service
+      final String name2 = "task2";
+      NetworkService<String> ns2 = new NetworkService<String>(
+          factory, 0, nameServerAddr, nameServerPort,
+          new StringCodec(), new MessagingTransportFactory(),
+          new MessageHandler<String>(name2, monitor, totalNumMessages), new ExceptionHandler());
+      ns2.registerId(factory.getNewInstance(name2));
+      final int port2 = ns2.getTransport().getListeningPort();
+      server.register(factory.getNewInstance("task2"), new InetSocketAddress(nameServerAddr, port2));
+
+      LOG.log(Level.FINEST, "=== Test network service sender start");
+      final String name1 = "task1";
+      NetworkService<String> ns1 = new NetworkService<String>(
+          factory, 0, nameServerAddr, nameServerPort,
+          new StringCodec(), new MessagingTransportFactory(),
+          new MessageHandler<String>(name1, null, 0), new ExceptionHandler());
+      ns1.registerId(factory.getNewInstance(name1));
+      final int port1 = ns1.getTransport().getListeningPort();
+      server.register(factory.getNewInstance("task1"), new InetSocketAddress(nameServerAddr, port1));
+
+      Identifier destId = factory.getNewInstance(name2);
+      final Connection<String> conn = ns1.newConnection(destId);
+      conn.open();
+
+      // build the message
+      StringBuilder msb = new StringBuilder();
+      for (int i = 0; i < size; i++) {
+        msb.append("1");
+      }
+      final String message = msb.toString();
+
+      ExecutorService e = Executors.newCachedThreadPool();
+
+      long start = System.currentTimeMillis();
+      for (int i = 0; i < numThreads; i++) {
+        e.submit(new Runnable() {
+
+          @Override
+          public void run() {
+            try {
+              for (int i = 0; i < numMessages; i++) {
+                conn.write(message);
+              }
+            } catch (NetworkException e) {
+              e.printStackTrace();
+            }
+          }
+        });
+      }
+
+
+      e.shutdown();
+      e.awaitTermination(30, TimeUnit.SECONDS);
+      monitor.mwait();
+
+      long end = System.currentTimeMillis();
+      double runtime = ((double) end - start) / 1000;
+
+      LOG.log(Level.FINEST, "size: " + size + "; messages/s: " + totalNumMessages / runtime + " bandwidth(bytes/s): " + ((double) totalNumMessages * 2 * size) / runtime);// x2 for unicode chars
+      conn.close();
+
+      ns1.close();
+      ns2.close();
+    }
+
+    server.close();
+  }
+
+  /**
+   * NetworkService messaging rate benchmark
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testMessagingNetworkServiceBatchingRate() throws Exception {
+    LOG.log(Level.FINEST, name.getMethodName());
+
+    IdentifierFactory factory = new StringIdentifierFactory();
+    String nameServerAddr = NetUtils.getLocalAddress();
+
+    NameServer server = new NameServerImpl(0, factory);
+    int nameServerPort = server.getPort();
+
+    final int batchSize = 1024 * 1024;
+    final int[] messageSizes = {32, 64, 512};
+
+    for (int size : messageSizes) {
+      final int numMessages = 300 / (Math.max(1, size / 512));
+      final Monitor monitor = new Monitor();
+
+      LOG.log(Level.FINEST, "=== Test network service receiver start");
+      // network service
+      final String name2 = "task2";
+      NetworkService<String> ns2 = new NetworkService<String>(
+          factory, 0, nameServerAddr, nameServerPort,
+          new StringCodec(), new MessagingTransportFactory(),
+          new MessageHandler<String>(name2, monitor, numMessages), new ExceptionHandler());
+      ns2.registerId(factory.getNewInstance(name2));
+      final int port2 = ns2.getTransport().getListeningPort();
+      server.register(factory.getNewInstance("task2"), new InetSocketAddress(nameServerAddr, port2));
+
+      LOG.log(Level.FINEST, "=== Test network service sender start");
+      final String name1 = "task1";
+      NetworkService<String> ns1 = new NetworkService<String>(
+          factory, 0, nameServerAddr, nameServerPort,
+          new StringCodec(), new MessagingTransportFactory(),
+          new MessageHandler<String>(name1, null, 0), new ExceptionHandler());
+      ns1.registerId(factory.getNewInstance(name1));
+      final int port1 = ns1.getTransport().getListeningPort();
+      server.register(factory.getNewInstance("task1"), new InetSocketAddress(nameServerAddr, port1));
+
+      Identifier destId = factory.getNewInstance(name2);
+      Connection<String> conn = ns1.newConnection(destId);
+
+      // build the message
+      StringBuilder msb = new StringBuilder();
+      for (int i = 0; i < size; i++) {
+        msb.append("1");
+      }
+      String message = msb.toString();
+
+      long start = System.currentTimeMillis();
+      try {
+        for (int i = 0; i < numMessages; i++) {
+          StringBuilder sb = new StringBuilder();
+          for (int j = 0; j < batchSize / size; j++) {
+            sb.append(message);
+          }
+          conn.open();
+          conn.write(sb.toString());
+        }
+        monitor.mwait();
+      } catch (NetworkException e) {
+        e.printStackTrace();
+      }
+      long end = System.currentTimeMillis();
+      double runtime = ((double) end - start) / 1000;
+      long numAppMessages = numMessages * batchSize / size;
+      LOG.log(Level.FINEST, "size: " + size + "; messages/s: " + numAppMessages / runtime + " bandwidth(bytes/s): " + ((double) numAppMessages * 2 * size) / runtime);// x2 for unicode chars
+      conn.close();
+
+      ns1.close();
+      ns2.close();
+    }
+
+    server.close();
+  }
+
+  /**
+   * Test message handler
+   *
+   * @param <T> type
+   */
+  class MessageHandler<T> implements EventHandler<Message<T>> {
+
+    private final String name;
+    private final int expected;
+    private final Monitor monitor;
+    private AtomicInteger count = new AtomicInteger(0);
+
+    MessageHandler(String name, Monitor monitor, int expected) {
+      this.name = name;
+      this.monitor = monitor;
+      this.expected = expected;
+    }
+
+    @Override
+    public void onNext(Message<T> value) {
+      count.incrementAndGet();
+
+      //System.out.print(name + " received " + value.getData() + " from " + value.getSrcId() + " to " + value.getDestId());
+      for (T obj : value.getData()) {
+        // System.out.print(" data: " + obj);
+      }
+      //LOG.log(Level.FINEST, );
+      if (count.get() == expected) {
+        monitor.mnotify();
+      }
+    }
+  }
+
+  /**
+   * Test exception handler
+   */
+  class ExceptionHandler implements EventHandler<Exception> {
+    @Override
+    public void onNext(Exception error) {
+      System.err.println(error);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/test/java/org/apache/reef/services/network/TestEvent.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/test/java/org/apache/reef/services/network/TestEvent.java b/lang/java/reef-io/src/test/java/org/apache/reef/services/network/TestEvent.java
new file mode 100644
index 0000000..c325ab9
--- /dev/null
+++ b/lang/java/reef-io/src/test/java/org/apache/reef/services/network/TestEvent.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.services.network;
+
+import java.io.Serializable;
+
+/**
+ * Event for testing
+ */
+public class TestEvent implements Serializable {
+
+  private static final long serialVersionUID = 1L;
+  private String message;
+
+  public TestEvent(String message) {
+    this.message = message;
+  }
+
+  public String getMessage() {
+    return message;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/LoggingUtils.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/LoggingUtils.java b/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/LoggingUtils.java
new file mode 100644
index 0000000..0d96670
--- /dev/null
+++ b/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/LoggingUtils.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.services.network.util;
+
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class LoggingUtils {
+  public static void setLoggingLevel(Level level) {
+    Handler[] handlers = Logger.getLogger("").getHandlers();
+    ConsoleHandler ch = null;
+    for (Handler h : handlers) {
+      if (h instanceof ConsoleHandler) {
+        ch = (ConsoleHandler) h;
+        break;
+      }
+    }
+    if (ch == null) {
+      ch = new ConsoleHandler();
+      Logger.getLogger("").addHandler(ch);
+    }
+    ch.setLevel(level);
+    Logger.getLogger("").setLevel(level);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/Monitor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/Monitor.java b/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/Monitor.java
new file mode 100644
index 0000000..ccfb54c
--- /dev/null
+++ b/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/Monitor.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.services.network.util;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+public class Monitor {
+  private AtomicBoolean finished = new AtomicBoolean(false);
+
+  public void mwait() throws InterruptedException {
+    synchronized (this) {
+      while (!finished.get())
+        this.wait();
+    }
+  }
+
+  public void mnotify() {
+    synchronized (this) {
+      finished.compareAndSet(false, true);
+      this.notifyAll();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/StringCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/StringCodec.java b/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/StringCodec.java
new file mode 100644
index 0000000..9c55976
--- /dev/null
+++ b/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/StringCodec.java
@@ -0,0 +1,34 @@
+/**
+ * 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.reef.services.network.util;
+
+import org.apache.reef.wake.remote.Codec;
+
+
+public class StringCodec implements Codec<String> {
+  @Override
+  public byte[] encode(String obj) {
+    return obj.getBytes();
+  }
+
+  @Override
+  public String decode(byte[] buf) {
+    return new String(buf);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/TimeoutHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/TimeoutHandler.java b/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/TimeoutHandler.java
new file mode 100644
index 0000000..575ed33
--- /dev/null
+++ b/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/TimeoutHandler.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.services.network.util;
+
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.impl.PeriodicEvent;
+
+public class TimeoutHandler implements EventHandler<PeriodicEvent> {
+
+  private final Monitor monitor;
+
+  public TimeoutHandler(Monitor monitor) {
+    this.monitor = monitor;
+  }
+
+  @Override
+  public void onNext(PeriodicEvent event) {
+    monitor.mnotify();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/package-info.java b/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/package-info.java
new file mode 100644
index 0000000..f40b8c4
--- /dev/null
+++ b/lang/java/reef-io/src/test/java/org/apache/reef/services/network/util/package-info.java
@@ -0,0 +1,19 @@
+/**
+ * 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.reef.services.network.util;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/ExternalMapTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/ExternalMapTest.java b/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/ExternalMapTest.java
new file mode 100644
index 0000000..7451ac8
--- /dev/null
+++ b/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/ExternalMapTest.java
@@ -0,0 +1,94 @@
+/**
+ * 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.reef.services.storage;
+
+import org.apache.reef.io.ExternalMap;
+import org.apache.reef.io.serialization.Codec;
+import org.apache.reef.io.storage.ram.CodecRamMap;
+import org.apache.reef.io.storage.ram.RamMap;
+import org.apache.reef.io.storage.ram.RamStorageService;
+import org.apache.reef.io.storage.util.IntegerCodec;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.*;
+
+
+public class ExternalMapTest {
+  @Test
+  public void testCodecRamMap() {
+    RamStorageService ramStore = new RamStorageService();
+    Codec<Integer> c = new IntegerCodec();
+    ExternalMap<Integer> m = new CodecRamMap<>(ramStore, c);
+    genericTest(m);
+  }
+
+  @Test
+  public void testRamMap() {
+    RamStorageService ramStore = new RamStorageService();
+    ExternalMap<Integer> m = new RamMap<>(ramStore);
+    genericTest(m);
+  }
+
+
+  void genericTest(ExternalMap<Integer> m) {
+    m.put("foo", 42);
+    Map<String, Integer> smallMap = new HashMap<>();
+    smallMap.put("bar", 43);
+    smallMap.put("baz", 44);
+
+    m.putAll(smallMap);
+
+    Assert.assertEquals(44, (int) m.get("baz"));
+    Assert.assertEquals(43, (int) m.get("bar"));
+    Assert.assertEquals(42, (int) m.get("foo"));
+    Assert.assertNull(m.get("quuz"));
+
+    Assert.assertTrue(m.containsKey("bar"));
+    Assert.assertFalse(m.containsKey("quuz"));
+
+    Set<String> barBaz = new HashSet<>();
+    barBaz.add("bar");
+    barBaz.add("baz");
+    barBaz.add("quuz");
+
+    Iterable<Map.Entry<CharSequence, Integer>> it = m.getAll(barBaz);
+
+    Map<CharSequence, Integer> found = new TreeMap<>();
+
+    for (Map.Entry<CharSequence, Integer> e : it) {
+      found.put(e.getKey(), e.getValue());
+    }
+    Iterator<CharSequence> it2 = found.keySet().iterator();
+    Assert.assertTrue(it2.hasNext());
+    CharSequence s = it2.next();
+    Assert.assertEquals(s, "bar");
+    Assert.assertEquals((int) found.get(s), 43);
+    Assert.assertTrue(it2.hasNext());
+    s = it2.next();
+    Assert.assertEquals(s, "baz");
+    Assert.assertEquals((int) found.get(s), 44);
+    Assert.assertFalse(it2.hasNext());
+
+    Assert.assertEquals(44, (int) m.remove("baz"));
+    Assert.assertFalse(m.containsKey("baz"));
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/FramingTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/FramingTest.java b/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/FramingTest.java
new file mode 100644
index 0000000..55857f9
--- /dev/null
+++ b/lang/java/reef-io/src/test/java/org/apache/reef/services/storage/FramingTest.java
@@ -0,0 +1,104 @@
+/**
+ * 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.reef.services.storage;
+
+import org.apache.reef.exception.evaluator.ServiceException;
+import org.apache.reef.io.Accumulator;
+import org.apache.reef.io.storage.FramingInputStream;
+import org.apache.reef.io.storage.FramingOutputStream;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+
+public class FramingTest {
+
+  @Test
+  public void frameRoundTripTest() throws IOException, ServiceException {
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
+    FramingOutputStream o = new FramingOutputStream(baos);
+    FramingOutputStream o2 = new FramingOutputStream(baos2);
+    Accumulator<byte[]> a = o2.accumulator();
+    int offset = 0;
+    for (int i = 0; i < 256; i++) {
+      byte[] b = new byte[i];
+      Arrays.fill(b, (byte) i);
+      o.write(b);
+      if (i == 255) {
+        o.close();
+      } else {
+        o.nextFrame();
+      }
+      offset += (4 + i);
+      Assert.assertEquals(offset, o.getCurrentOffset());
+      a.add(b);
+      Assert.assertEquals(offset, o2.getCurrentOffset());
+    }
+    a.close();
+    o2.close();
+    byte[] b1 = baos.toByteArray();
+    byte[] b2 = baos2.toByteArray();
+    Assert.assertArrayEquals(b1, b2);
+    FramingInputStream inA1 = new FramingInputStream(new ByteArrayInputStream(b1));
+    FramingInputStream inA2 = new FramingInputStream(new ByteArrayInputStream(b2));
+    for (int i = 0; i <= 256; i++) {
+      byte[] b = new byte[i];
+      Arrays.fill(b, (byte) i);
+      byte[] f = inA1.readFrame();
+      byte[] g = inA2.readFrame();
+      if (i == 256) {
+        Assert.assertNull(f);
+        Assert.assertNull(g);
+      } else {
+        Assert.assertArrayEquals(b, f);
+        Assert.assertArrayEquals(b, g);
+      }
+    }
+    inA2.close();
+    inA1.close();
+
+    FramingInputStream inB1 = new FramingInputStream(new ByteArrayInputStream(b1));
+    int i = 0;
+    for (byte[] bin : inB1) {
+      byte[] b = new byte[i];
+      Arrays.fill(b, (byte) i);
+      Assert.assertArrayEquals(b, bin);
+      i++;
+    }
+    Assert.assertEquals(256, i);
+    inB1.close();
+
+    FramingInputStream inB2 = new FramingInputStream(new ByteArrayInputStream(b2));
+    i = 0;
+    for (byte[] bin : inB2) {
+      byte[] b = new byte[i];
+      Arrays.fill(b, (byte) i);
+      Assert.assertArrayEquals(b, bin);
+      i++;
+    }
+    Assert.assertEquals(256, i);
+    inB2.close();
+    Assert.assertArrayEquals(b1, b2);
+  }
+
+}


[13/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/InjectorImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/InjectorImpl.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/InjectorImpl.java
new file mode 100644
index 0000000..16ce791
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/InjectorImpl.java
@@ -0,0 +1,760 @@
+/**
+ * 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.reef.tang.implementation.java;
+
+import org.apache.reef.tang.*;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.exceptions.*;
+import org.apache.reef.tang.implementation.*;
+import org.apache.reef.tang.types.*;
+import org.apache.reef.tang.util.MonotonicHashSet;
+import org.apache.reef.tang.util.MonotonicSet;
+import org.apache.reef.tang.util.ReflectionUtilities;
+import org.apache.reef.tang.util.TracingMonotonicTreeMap;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.*;
+
+public class InjectorImpl implements Injector {
+  static final InjectionPlan<?> BUILDING = new InjectionPlan<Object>(null) {
+    @Override
+    public int getNumAlternatives() {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public String toString() {
+      return "BUILDING INJECTION PLAN";
+    }
+
+    @Override
+    public boolean isAmbiguous() {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean isInjectable() {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    protected String toAmbiguousInjectString() {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    protected String toInfeasibleInjectString() {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    protected boolean isInfeasibleLeaf() {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public String toShallowString() {
+      throw new UnsupportedOperationException();
+    }
+
+  };
+  final Map<ClassNode<?>, Object> instances = new TracingMonotonicTreeMap<>();
+  final Map<NamedParameterNode<?>, Object> namedParameterInstances = new TracingMonotonicTreeMap<>();
+  private final Configuration c;
+  private final ClassHierarchy namespace;
+  private final JavaClassHierarchy javaNamespace;
+  private final Set<InjectionFuture<?>> pendingFutures = new HashSet<>();
+  private boolean concurrentModificationGuard = false;
+  private Aspect aspect;
+
+  public InjectorImpl(Configuration c) throws BindException {
+    this.c = c;
+    this.namespace = c.getClassHierarchy();
+    this.javaNamespace = (ClassHierarchyImpl) this.namespace;
+  }
+
+  private static InjectorImpl copy(InjectorImpl old,
+                                   Configuration... configurations) throws BindException {
+    final InjectorImpl i;
+    try {
+      final ConfigurationBuilder cb = old.c.newBuilder();
+      for (Configuration c : configurations) {
+        cb.addConfiguration(c);
+      }
+      i = new InjectorImpl(cb.build());
+    } catch (BindException e) {
+      throw new IllegalStateException(
+          "Unexpected error copying configuration!", e);
+    }
+    for (ClassNode<?> cn : old.instances.keySet()) {
+      if (cn.getFullName().equals(ReflectionUtilities.getFullName(Injector.class))
+          || cn.getFullName().equals(ReflectionUtilities.getFullName(InjectorImpl.class))) {
+        // This would imply that we're treating injector as a singleton somewhere.  It should be copied fresh each time.
+        throw new IllegalStateException();
+      }
+      try {
+        ClassNode<?> new_cn = (ClassNode<?>) i.namespace.getNode(cn
+            .getFullName());
+        i.instances.put(new_cn, old.instances.get(cn));
+      } catch (BindException e) {
+        throw new IllegalStateException("Could not resolve name "
+            + cn.getFullName() + " when copying injector");
+      }
+    }
+    // Copy references to the remaining (which must have been set with
+    // bindVolatileParameter())
+    for (NamedParameterNode<?> np : old.namedParameterInstances.keySet()) {
+      // if (!builder.namedParameters.containsKey(np)) {
+      Object o = old.namedParameterInstances.get(np);
+      NamedParameterNode<?> new_np = (NamedParameterNode<?>) i.namespace
+          .getNode(np.getFullName());
+      i.namedParameterInstances.put(new_np, o);
+    }
+    // Fork the aspect (if any)
+    if (old.aspect != null) {
+      i.bindAspect(old.aspect.createChildAspect());
+    }
+    return i;
+  }
+
+  private void assertNotConcurrent() {
+    if (concurrentModificationGuard) {
+      throw new ConcurrentModificationException("Detected attempt to use Injector from within an injected constructor!");
+    }
+  }
+
+  @SuppressWarnings("unchecked")
+  private <T> T getCachedInstance(ClassNode<T> cn) {
+    if (cn.getFullName().equals("org.apache.reef.tang.Injector")) {
+      return (T) this;// TODO: We should be insisting on injection futures here! .forkInjector();
+    } else {
+      T t = (T) instances.get(cn);
+      if (t instanceof InjectionFuture) {
+        throw new IllegalStateException("Found an injection future in getCachedInstance: " + cn);
+      }
+      return t;
+    }
+  }
+
+  /**
+   * Produce a list of "interesting" constructors from a set of ClassNodes.
+   * <p/>
+   * Tang Constructors expose a isMoreSpecificThan function that embeds all
+   * a skyline query over the lattices.  Precisely:
+   * <p/>
+   * Let candidateConstructors be the union of all constructors defined by
+   * ClassNodes in candidateImplementations.
+   * <p/>
+   * This function returns a set called filteredImplementations, defined as
+   * follows:
+   * <p/>
+   * For each member f of filteredConstructors, there does not exist
+   * a g in candidateConstructors s.t. g.isMoreSpecificThan(f).
+   */
+  private <T> List<InjectionPlan<T>> filterCandidateConstructors(
+      final List<ClassNode<T>> candidateImplementations,
+      final Map<Node, InjectionPlan<?>> memo) {
+
+    final List<InjectionPlan<T>> sub_ips = new ArrayList<>();
+    for (final ClassNode<T> thisCN : candidateImplementations) {
+      final List<Constructor<T>> constructors = new ArrayList<>();
+      final List<ConstructorDef<T>> constructorList = new ArrayList<>();
+      if (null != c.getLegacyConstructor(thisCN)) {
+        constructorList.add(c.getLegacyConstructor(thisCN));
+      }
+      constructorList
+          .addAll(Arrays.asList(thisCN.getInjectableConstructors()));
+
+      for (ConstructorDef<T> def : constructorList) {
+        final List<InjectionPlan<?>> args = new ArrayList<InjectionPlan<?>>();
+        final ConstructorArg[] defArgs = def.getArgs();
+
+        for (final ConstructorArg arg : defArgs) {
+          if (!arg.isInjectionFuture()) {
+            try {
+              final Node argNode = namespace.getNode(arg.getName());
+              buildInjectionPlan(argNode, memo);
+              args.add(memo.get(argNode));
+            } catch (NameResolutionException e) {
+              throw new IllegalStateException("Detected unresolvable "
+                  + "constructor arg while building injection plan.  "
+                  + "This should have been caught earlier!", e);
+            }
+          } else {
+            try {
+              args.add(new InjectionFuturePlan<>(namespace.getNode(arg
+                  .getName())));
+            } catch (NameResolutionException e) {
+              throw new IllegalStateException("Detected unresolvable "
+                  + "constructor arg while building injection plan.  "
+                  + "This should have been caught earlier!", e);
+            }
+          }
+        }
+        final Constructor<T> constructor = new Constructor<T>(thisCN, def,
+            args.toArray(new InjectionPlan[0]));
+        constructors.add(constructor);
+      }
+      // The constructors are embedded in a lattice defined by
+      // isMoreSpecificThan().  We want to see if, amongst the injectable
+      // plans, there is a unique dominant plan, and select it.
+
+      // First, compute the set of injectable plans.
+      final List<Integer> liveIndices = new ArrayList<>();
+      for (int i = 0; i < constructors.size(); i++) {
+        if (constructors.get(i).getNumAlternatives() > 0) {
+          liveIndices.add(i);
+        }
+      }
+      // Now, do an all-by-all comparison, removing indices that are dominated
+      // by others.
+      for (int i = 0; i < liveIndices.size(); i++) {
+        for (int j = i + 1; j < liveIndices.size(); j++) {
+          final ConstructorDef<T> ci = constructors.get(liveIndices.get(i))
+              .getConstructorDef();
+          final ConstructorDef<T> cj = constructors.get(liveIndices.get(j))
+              .getConstructorDef();
+
+          if (ci.isMoreSpecificThan(cj)) {
+            liveIndices.remove(j);
+            j--;
+          } else if (cj.isMoreSpecificThan(ci)) {
+            liveIndices.remove(i);
+            // Done with this inner loop invocation. Check the new ci.
+            i--;
+            break;
+          }
+        }
+      }
+      if (constructors.size() > 0) {
+        sub_ips.add(wrapInjectionPlans(thisCN, constructors, false,
+            liveIndices.size() == 1 ? liveIndices.get(0) : -1));
+      }
+    }
+    return sub_ips;
+  }
+
+  @SuppressWarnings("unchecked")
+  private <T> InjectionPlan<T> buildClassNodeInjectionPlan(ClassNode<T> cn,
+                                                           T cachedInstance,
+                                                           ClassNode<ExternalConstructor<T>> externalConstructor,
+                                                           ClassNode<T> boundImpl,
+                                                           ClassNode<T> defaultImpl,
+                                                           Map<Node, InjectionPlan<?>> memo) {
+
+    if (cachedInstance != null) {
+      return new JavaInstance<T>(cn, cachedInstance);
+    } else if (externalConstructor != null) {
+      buildInjectionPlan(externalConstructor, memo);
+      return new Subplan<>(cn, 0, (InjectionPlan<T>) memo.get(externalConstructor));
+    } else if (boundImpl != null && !cn.equals(boundImpl)) {
+      // We need to delegate to boundImpl, so recurse.
+      buildInjectionPlan(boundImpl, memo);
+      return new Subplan<>(cn, 0, (InjectionPlan<T>) memo.get(boundImpl));
+    } else if (defaultImpl != null && !cn.equals(defaultImpl)) {
+      buildInjectionPlan(defaultImpl, memo);
+      return new Subplan<>(cn, 0, (InjectionPlan<T>) memo.get(defaultImpl));
+    } else {
+      // if we're here and there isn't a bound impl or a default impl,
+      // then we're bound / defaulted to ourselves, so don't add
+      // other impls to the list of things to consider.
+      final List<ClassNode<T>> candidateImplementations = new ArrayList<>();
+      candidateImplementations.add(cn);
+      final List<InjectionPlan<T>> sub_ips = filterCandidateConstructors(candidateImplementations, memo);
+      if (sub_ips.size() == 1) {
+        return wrapInjectionPlans(cn, sub_ips, false, -1);
+      } else {
+        return wrapInjectionPlans(cn, sub_ips, true, -1);
+      }
+    }
+  }
+
+  @SuppressWarnings("unchecked")
+  private <T> InjectionPlan<T> wrapInjectionPlans(ClassNode<T> infeasibleNode,
+                                                  List<? extends InjectionPlan<T>> list, boolean forceAmbiguous, int selectedIndex) {
+    if (list.size() == 0) {
+      return new Subplan<>(infeasibleNode);
+    } else if ((!forceAmbiguous) && list.size() == 1) {
+      return list.get(0);
+    } else {
+      return new Subplan<>(infeasibleNode, selectedIndex, list.toArray(new InjectionPlan[0]));
+    }
+  }
+
+  /**
+   * Parse the bound value of np.  When possible, this returns a cached instance.
+   *
+   * @return null if np has not been bound.
+   * @throws ParseException
+   */
+  @SuppressWarnings("unchecked")
+  private <T> T parseBoundNamedParameter(NamedParameterNode<T> np) {
+    final T ret;
+
+    @SuppressWarnings("rawtypes")
+    final Set<Object> boundSet = c.getBoundSet((NamedParameterNode) np);
+    if (!boundSet.isEmpty()) {
+      Set<T> ret2 = new MonotonicSet<>();
+      for (Object o : boundSet) {
+        if (o instanceof String) {
+          try {
+            ret2.add(javaNamespace.parse(np, (String) o));
+          } catch (ParseException e) {
+            // Parsability is now pre-checked in bindSet, so it should not be reached!
+            throw new IllegalStateException("Could not parse " + o + " which was passed into " + np + " FIXME: Parsability is not currently checked by bindSetEntry(Node,String)");
+          }
+        } else if (o instanceof Node) {
+          ret2.add((T) o);
+        } else {
+          throw new IllegalStateException("Unexpected object " + o + " in bound set.  Should consist of nodes and strings");
+        }
+      }
+      return (T) ret2;
+    }
+    final List<Object> boundList = c.getBoundList((NamedParameterNode) np);
+    if (boundList != null) {
+      List<T> ret2 = new ArrayList<>();
+      for (Object o : boundList) {
+        if (o instanceof String) {
+          try {
+            ret2.add(javaNamespace.parse(np, (String) o));
+          } catch (ParseException e) {
+            // Parsability is now pre-checked in bindList, so it should not be reached!
+            throw new IllegalStateException("Could not parse " + o + " which was passed into " + np + " FIXME: " +
+                "Parsability is not currently checked by bindList(Node,List)");
+          }
+        } else if (o instanceof Node) {
+          ret2.add((T) o);
+        } else {
+          throw new IllegalStateException("Unexpected object " + o + " in bound list.  Should consist of nodes and " +
+              "strings");
+        }
+      }
+      return (T) ret2;
+    } else if (namedParameterInstances.containsKey(np)) {
+      ret = (T) namedParameterInstances.get(np);
+    } else {
+      final String value = c.getNamedParameter(np);
+      if (value == null) {
+        ret = null;
+      } else {
+        try {
+          ret = javaNamespace.parse(np, value);
+          namedParameterInstances.put(np, ret);
+        } catch (BindException e) {
+          throw new IllegalStateException(
+              "Could not parse pre-validated value", e);
+        }
+      }
+    }
+    return ret;
+  }
+
+  @SuppressWarnings("unchecked")
+  private <T> ClassNode<T> parseDefaultImplementation(ClassNode<T> cn) {
+    if (cn.getDefaultImplementation() != null) {
+      try {
+        return (ClassNode<T>) javaNamespace.getNode(cn.getDefaultImplementation());
+      } catch (ClassCastException | NameResolutionException e) {
+        throw new IllegalStateException("After validation, " + cn + " had a bad default implementation named " + cn.getDefaultImplementation(), e);
+      }
+    } else {
+      return null;
+    }
+  }
+
+  @SuppressWarnings({"unchecked"})
+  private <T> void buildInjectionPlan(final Node n,
+                                      Map<Node, InjectionPlan<?>> memo) {
+    if (memo.containsKey(n)) {
+      if (BUILDING == memo.get(n)) {
+        StringBuilder loopyList = new StringBuilder("[");
+        for (Node node : memo.keySet()) {
+          if (memo.get(node) == BUILDING) {
+            loopyList.append(" " + node.getFullName());
+          }
+        }
+        loopyList.append(" ]");
+        throw new ClassHierarchyException("Detected loopy constructor involving "
+            + loopyList.toString());
+      } else {
+        return;
+      }
+    }
+    memo.put(n, BUILDING);
+    final InjectionPlan<T> ip;
+    if (n instanceof NamedParameterNode) {
+      final NamedParameterNode<T> np = (NamedParameterNode<T>) n;
+
+      final T boundInstance = parseBoundNamedParameter(np);
+      final T defaultInstance = javaNamespace.parseDefaultValue(np);
+      final T instance = boundInstance != null ? boundInstance : defaultInstance;
+
+      if (instance instanceof Node) {
+        buildInjectionPlan((Node) instance, memo);
+        ip = new Subplan<T>(n, 0, (InjectionPlan<T>) memo.get(instance));
+      } else if (instance instanceof Set) {
+        Set<T> entries = (Set<T>) instance;
+        Set<InjectionPlan<T>> plans = new MonotonicHashSet<>();
+        for (T entry : entries) {
+          if (entry instanceof ClassNode) {
+            buildInjectionPlan((ClassNode<?>) entry, memo);
+            plans.add((InjectionPlan<T>) memo.get(entry));
+          } else {
+            plans.add(new JavaInstance<T>(n, entry));
+          }
+
+        }
+        ip = new SetInjectionPlan<T>(n, plans);
+      } else if (instance instanceof List) {
+        List<T> entries = (List<T>) instance;
+        List<InjectionPlan<T>> plans = new ArrayList<>();
+        for (T entry : entries) {
+          if (entry instanceof ClassNode) {
+            buildInjectionPlan((ClassNode<?>) entry, memo);
+            plans.add((InjectionPlan<T>) memo.get(entry));
+          } else {
+            plans.add(new JavaInstance<T>(n, entry));
+          }
+        }
+        ip = new ListInjectionPlan<T>(n, plans);
+      } else {
+        ip = new JavaInstance<T>(np, instance);
+      }
+    } else if (n instanceof ClassNode) {
+      final ClassNode<T> cn = (ClassNode<T>) n;
+
+      // Any (or all) of the next four values might be null; that's fine.
+      final T cached = getCachedInstance(cn);
+      final ClassNode<T> boundImpl = c.getBoundImplementation(cn);
+      final ClassNode<T> defaultImpl = parseDefaultImplementation(cn);
+      final ClassNode<ExternalConstructor<T>> ec = c.getBoundConstructor(cn);
+
+      ip = buildClassNodeInjectionPlan(cn, cached, ec, boundImpl, defaultImpl, memo);
+    } else if (n instanceof PackageNode) {
+      throw new IllegalArgumentException(
+          "Request to instantiate Java package as object");
+    } else {
+      throw new IllegalStateException(
+          "Type hierarchy contained unknown node type!:" + n);
+    }
+    memo.put(n, ip);
+  }
+
+  /**
+   * Return an injection plan for the given class / parameter name.
+   *
+   * @param n The name of an injectable class or interface, or a NamedParameter.
+   * @return
+   * @throws NameResolutionException
+   */
+  public InjectionPlan<?> getInjectionPlan(final Node n) {
+    Map<Node, InjectionPlan<?>> memo = new HashMap<>();
+    buildInjectionPlan(n, memo);
+    return memo.get(n);
+  }
+
+  @Override
+  public InjectionPlan<?> getInjectionPlan(String name) throws NameResolutionException {
+    return getInjectionPlan(namespace.getNode(name));
+  }
+
+  @SuppressWarnings("unchecked")
+  public <T> InjectionPlan<T> getInjectionPlan(Class<T> name) {
+    return (InjectionPlan<T>) getInjectionPlan(javaNamespace.getNode(name));
+  }
+
+  @Override
+  public boolean isInjectable(String name) throws NameResolutionException {
+    return getInjectionPlan(namespace.getNode(name)).isInjectable();
+  }
+
+  @Override
+  public boolean isInjectable(Class<?> clazz) {
+    try {
+      return isInjectable(ReflectionUtilities.getFullName(clazz));
+    } catch (NameResolutionException e) {
+      throw new IllegalStateException("Could not round trip " + clazz + " through ClassHierarchy", e);
+    }
+  }
+
+  @Override
+  public boolean isParameterSet(String name) throws NameResolutionException {
+    InjectionPlan<?> p = getInjectionPlan(namespace.getNode(name));
+    return p.isInjectable();
+  }
+
+  @Override
+  public boolean isParameterSet(Class<? extends Name<?>> name)
+      throws BindException {
+    return isParameterSet(name.getName());
+  }
+
+  private <U> U getInstance(Node n) throws InjectionException {
+    assertNotConcurrent();
+    @SuppressWarnings("unchecked")
+    InjectionPlan<U> plan = (InjectionPlan<U>) getInjectionPlan(n);
+    U u = (U) injectFromPlan(plan);
+
+    while (!pendingFutures.isEmpty()) {
+      Iterator<InjectionFuture<?>> i = pendingFutures.iterator();
+      InjectionFuture<?> f = i.next();
+      pendingFutures.remove(f);
+      f.get();
+    }
+    return u;
+  }
+
+  @Override
+  public <U> U getInstance(Class<U> clazz) throws InjectionException {
+    if (Name.class.isAssignableFrom(clazz)) {
+      throw new InjectionException("getInstance() called on Name "
+          + ReflectionUtilities.getFullName(clazz)
+          + " Did you mean to call getNamedInstance() instead?");
+    }
+    return getInstance(javaNamespace.getNode(clazz));
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public <U> U getInstance(String clazz) throws InjectionException, NameResolutionException {
+    return (U) getInstance(namespace.getNode(clazz));
+  }
+
+  @Override
+  @SuppressWarnings("unchecked")
+  public <T> T getNamedInstance(Class<? extends Name<T>> clazz)
+      throws InjectionException {
+    return (T) getInstance(javaNamespace.getNode(clazz));
+  }
+
+  public <T> T getNamedParameter(Class<? extends Name<T>> clazz)
+      throws InjectionException {
+    return getNamedInstance(clazz);
+  }
+
+  private <T> java.lang.reflect.Constructor<T> getConstructor(
+      ConstructorDef<T> constructor) throws ClassNotFoundException,
+      NoSuchMethodException, SecurityException {
+    @SuppressWarnings("unchecked")
+    Class<T> clazz = (Class<T>) javaNamespace.classForName(constructor
+        .getClassName());
+    ConstructorArg[] args = constructor.getArgs();
+    Class<?> parameterTypes[] = new Class[args.length];
+    for (int i = 0; i < args.length; i++) {
+      if (args[i].isInjectionFuture()) {
+        parameterTypes[i] = InjectionFuture.class;
+      } else {
+        parameterTypes[i] = javaNamespace.classForName(args[i].getType());
+      }
+    }
+    java.lang.reflect.Constructor<T> cons = clazz
+        .getDeclaredConstructor(parameterTypes);
+    cons.setAccessible(true);
+    return cons;
+  }
+
+  /**
+   * This gets really nasty now that constructors can invoke operations on us.
+   * The upshot is that we should check to see if instances have been
+   * registered by callees after each recursive invocation of injectFromPlan or
+   * constructor invocations. The error handling currently bails if the thing we
+   * just instantiated should be discarded.
+   * <p/>
+   * This could happen if (for instance), a constructor did a
+   * bindVolatileInstance of its own class to an instance, or somehow triggered
+   * an injection of itself with a different plan (an injection of itself with
+   * the same plan would lead to an infinite recursion, so it's not really our
+   * problem).
+   *
+   * @param plan
+   * @return
+   * @throws InjectionException
+   */
+  @SuppressWarnings("unchecked")
+  private <T> T injectFromPlan(InjectionPlan<T> plan) throws InjectionException {
+
+    if (!plan.isFeasible()) {
+      throw new InjectionException("Cannot inject " + plan.getNode().getFullName() + ": "
+          + plan.toCantInjectString());
+    }
+    if (plan.isAmbiguous()) {
+      throw new InjectionException("Cannot inject " + plan.getNode().getFullName() + " "
+          + plan.toCantInjectString());
+    }
+    if (plan instanceof InjectionFuturePlan) {
+      InjectionFuturePlan<T> fut = (InjectionFuturePlan<T>) plan;
+      final String key = fut.getNode().getFullName();
+      try {
+        InjectionFuture<?> ret = new InjectionFuture<>(this, javaNamespace.classForName(fut.getNode().getFullName()));
+        pendingFutures.add(ret);
+        return (T) ret;
+      } catch (ClassNotFoundException e) {
+        throw new InjectionException("Could not get class for " + key);
+      }
+    } else if (plan.getNode() instanceof ClassNode && null != getCachedInstance((ClassNode<T>) plan.getNode())) {
+      return getCachedInstance((ClassNode<T>) plan.getNode());
+    } else if (plan instanceof JavaInstance) {
+      // TODO: Must be named parameter node.  Check.
+//      throw new IllegalStateException("Instance from plan not in Injector's set of instances?!?");
+      return ((JavaInstance<T>) plan).instance;
+    } else if (plan instanceof Constructor) {
+      final Constructor<T> constructor = (Constructor<T>) plan;
+      final Object[] args = new Object[constructor.getArgs().length];
+      final InjectionPlan<?>[] argPlans = constructor.getArgs();
+
+      for (int i = 0; i < argPlans.length; i++) {
+        args[i] = injectFromPlan(argPlans[i]);
+      }
+      try {
+        concurrentModificationGuard = true;
+        T ret;
+        try {
+          ConstructorDef<T> def = (ConstructorDef<T>) constructor.getConstructorDef();
+          java.lang.reflect.Constructor<T> c = getConstructor(def);
+
+          if (aspect != null) {
+            ret = aspect.inject(def, c, args);
+          } else {
+            ret = c.newInstance(args);
+          }
+        } catch (IllegalArgumentException e) {
+          StringBuilder sb = new StringBuilder("Internal Tang error?  Could not call constructor " + constructor.getConstructorDef() + " with arguments [");
+          for (Object o : args) {
+            sb.append("\n\t" + o);
+          }
+          sb.append("]");
+          throw new IllegalStateException(sb.toString(), e);
+        }
+        if (ret instanceof ExternalConstructor) {
+          ret = ((ExternalConstructor<T>) ret).newInstance();
+        }
+        instances.put(constructor.getNode(), ret);
+        return ret;
+      } catch (ReflectiveOperationException e) {
+        throw new InjectionException("Could not invoke constructor: " + plan, e instanceof InvocationTargetException ? e.getCause() : e);
+      } finally {
+        concurrentModificationGuard = false;
+      }
+    } else if (plan instanceof Subplan) {
+      Subplan<T> ambiguous = (Subplan<T>) plan;
+      return injectFromPlan(ambiguous.getDelegatedPlan());
+    } else if (plan instanceof SetInjectionPlan) {
+      SetInjectionPlan<T> setPlan = (SetInjectionPlan<T>) plan;
+      Set<T> ret = new MonotonicHashSet<>();
+      for (InjectionPlan<T> subplan : setPlan.getEntryPlans()) {
+        ret.add(injectFromPlan(subplan));
+      }
+      return (T) ret;
+    } else if (plan instanceof ListInjectionPlan) {
+      ListInjectionPlan<T> listPlan = (ListInjectionPlan<T>) plan;
+      List<T> ret = new ArrayList<>();
+      for (InjectionPlan<T> subplan : listPlan.getEntryPlans()) {
+        ret.add(injectFromPlan(subplan));
+      }
+      return (T) ret;
+    } else {
+      throw new IllegalStateException("Unknown plan type: " + plan);
+    }
+  }
+
+  @Override
+  public <T> void bindVolatileInstance(Class<T> c, T o) throws BindException {
+    bindVolatileInstanceNoCopy(c, o);
+  }
+
+  @Override
+  public <T> void bindVolatileParameter(Class<? extends Name<T>> c, T o)
+      throws BindException {
+    bindVolatileParameterNoCopy(c, o);
+  }
+
+  <T> void bindVolatileInstanceNoCopy(Class<T> c, T o) throws BindException {
+    assertNotConcurrent();
+    Node n = javaNamespace.getNode(c);
+    if (n instanceof ClassNode) {
+      ClassNode<?> cn = (ClassNode<?>) n;
+      Object old = getCachedInstance(cn);
+      if (old != null) {
+        throw new BindException("Attempt to re-bind instance.  Old value was "
+            + old + " new value is " + o);
+      }
+      instances.put(cn, o);
+    } else {
+      throw new IllegalArgumentException("Expected Class but got " + c
+          + " (probably a named parameter).");
+    }
+  }
+
+  <T> void bindVolatileParameterNoCopy(Class<? extends Name<T>> c, T o)
+      throws BindException {
+    Node n = javaNamespace.getNode(c);
+    if (n instanceof NamedParameterNode) {
+      NamedParameterNode<?> np = (NamedParameterNode<?>) n;
+      Object old = this.c.getNamedParameter(np);
+      if (old != null) {
+        // XXX need to get the binding site here!
+        throw new BindException(
+            "Attempt to re-bind named parameter " + ReflectionUtilities.getFullName(c) + ".  Old value was [" + old
+                + "] new value is [" + o + "]");
+      }
+      try {
+        namedParameterInstances.put(np, o);
+      } catch (IllegalArgumentException e) {
+        throw new BindException(
+            "Attempt to re-bind named parameter " + ReflectionUtilities.getFullName(c) + ".  Old value was [" + old
+                + "] new value is [" + o + "]");
+
+      }
+    } else {
+      throw new IllegalArgumentException("Expected Name, got " + c
+          + " (probably a class)");
+    }
+  }
+
+  @Override
+  public Injector forkInjector() {
+    try {
+      return forkInjector(new Configuration[0]);
+    } catch (BindException e) {
+      throw new IllegalStateException(e);
+    }
+  }
+
+  @Override
+  public Injector forkInjector(Configuration... configurations)
+      throws BindException {
+    InjectorImpl ret;
+    ret = copy(this, configurations);
+    return ret;
+  }
+
+  @Override
+  public <T> void bindAspect(Aspect a) throws BindException {
+    if (aspect != null) {
+      throw new BindException("Attempt to re-bind aspect! old=" + aspect + " new=" + a);
+    }
+    aspect = a;
+  }
+
+  @Override
+  public Aspect getAspect() {
+    return aspect;
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/JavaConfigurationBuilderImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/JavaConfigurationBuilderImpl.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/JavaConfigurationBuilderImpl.java
new file mode 100644
index 0000000..d13a014
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/JavaConfigurationBuilderImpl.java
@@ -0,0 +1,238 @@
+/**
+ * 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.reef.tang.implementation.java;
+
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.ExternalConstructor;
+import org.apache.reef.tang.JavaClassHierarchy;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.implementation.ConfigurationBuilderImpl;
+import org.apache.reef.tang.implementation.ConfigurationImpl;
+import org.apache.reef.tang.types.ClassNode;
+import org.apache.reef.tang.types.NamedParameterNode;
+import org.apache.reef.tang.types.Node;
+import org.apache.reef.tang.util.ReflectionUtilities;
+
+import java.lang.reflect.Type;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+public class JavaConfigurationBuilderImpl extends ConfigurationBuilderImpl
+    implements JavaConfigurationBuilder {
+
+  public JavaConfigurationBuilderImpl(URL[] jars, Configuration[] confs, Class<? extends ExternalConstructor<?>>[] parsers)
+      throws BindException {
+    super(jars, confs, parsers);
+  }
+
+  JavaConfigurationBuilderImpl() {
+    super();
+  }
+
+  public JavaConfigurationBuilderImpl(URL[] jars) throws BindException {
+    super(jars);
+  }
+
+  JavaConfigurationBuilderImpl(JavaConfigurationBuilderImpl impl) {
+    super(impl);
+  }
+
+  public JavaConfigurationBuilderImpl(Configuration[] confs)
+      throws BindException {
+    super(confs);
+  }
+
+  @Override
+  public ConfigurationImpl build() {
+    return new JavaConfigurationImpl(new JavaConfigurationBuilderImpl(this));
+  }
+
+  private Node getNode(Class<?> c) {
+    return ((JavaClassHierarchy) namespace).getNode(c);
+  }
+
+  @Override
+  public <T> JavaConfigurationBuilder bind(Class<T> c, Class<?> val) throws BindException {
+    super.bind(getNode(c), getNode(val));
+    return this;
+  }
+
+  @Override
+  @SuppressWarnings("unchecked")
+  public <T> JavaConfigurationBuilder bindImplementation(Class<T> c, Class<? extends T> d)
+      throws BindException {
+    final Node cn = getNode(c);
+    final Node dn = getNode(d);
+    if (!(cn instanceof ClassNode)) {
+      throw new BindException(
+          "bindImplementation passed interface that resolved to " + cn
+              + " expected a ClassNode<?>");
+    }
+    if (!(dn instanceof ClassNode)) {
+      throw new BindException(
+          "bindImplementation passed implementation that resolved to " + dn
+              + " expected a ClassNode<?>");
+    }
+    super.bindImplementation((ClassNode<T>) cn, (ClassNode<? extends T>) dn);
+    return this;
+  }
+
+  @Override
+  public JavaConfigurationBuilder bindNamedParameter(final Class<? extends Name<?>> name, final String value)
+      throws BindException {
+    if (value == null) {
+      throw new IllegalStateException("The value null set to the named parameter is illegal: " + name);
+    }
+    final Node np = getNode(name);
+    if (np instanceof NamedParameterNode) {
+      super.bindParameter((NamedParameterNode<?>) np, value);
+      return this;
+    } else {
+      throw new BindException(
+          "Detected type mismatch when setting named parameter " + name
+              + "  Expected NamedParameterNode, but namespace contains a " + np);
+    }
+  }
+
+  @Override
+  public <T> JavaConfigurationBuilder bindNamedParameter(Class<? extends Name<T>> iface,
+                                                         Class<? extends T> impl) throws BindException {
+    Node ifaceN = getNode(iface);
+    Node implN = getNode(impl);
+    if (!(ifaceN instanceof NamedParameterNode)) {
+      throw new BindException("Type mismatch when setting named parameter " + ifaceN
+          + " Expected NamedParameterNode");
+    }
+    bind(ifaceN, implN);
+    return this;
+  }
+
+  @SuppressWarnings({"unchecked"})
+  public <T> JavaConfigurationBuilder bindConstructor(Class<T> c,
+                                                      Class<? extends ExternalConstructor<? extends T>> v) throws BindException {
+    final Node n = getNode(c);
+    final Node m = getNode(v);
+    if (!(n instanceof ClassNode)) {
+      throw new BindException("BindConstructor got class that resolved to " + n + "; expected ClassNode");
+    }
+    if (!(m instanceof ClassNode)) {
+      throw new BindException("BindConstructor got class that resolved to " + m + "; expected ClassNode");
+    }
+    super.bindConstructor((ClassNode<T>) n, (ClassNode<? extends ExternalConstructor<? extends T>>) m);
+    return this;
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public <T> JavaConfigurationBuilder bindSetEntry(Class<? extends Name<Set<T>>> iface, String value) throws BindException {
+    final Node n = getNode(iface);
+
+    if (!(n instanceof NamedParameterNode)) {
+      throw new BindException("BindSetEntry got an interface that resolved to " + n + "; expected a NamedParameter");
+    }
+    final Type setType = ReflectionUtilities.getInterfaceTarget(Name.class, iface);
+    if (!ReflectionUtilities.getRawClass(setType).equals(Set.class)) {
+      throw new BindException("BindSetEntry got a NamedParameter that takes a " + setType + "; expected Set<...>");
+    }
+//    Type valType = ReflectionUtilities.getInterfaceTarget(Set.class, setType);
+    super.bindSetEntry((NamedParameterNode<Set<T>>) n, value);
+    return this;
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public <T> JavaConfigurationBuilder bindSetEntry(Class<? extends Name<Set<T>>> iface, Class<? extends T> impl) throws BindException {
+    final Node n = getNode(iface);
+    final Node m = getNode(impl);
+
+    if (!(n instanceof NamedParameterNode)) {
+      throw new BindException("BindSetEntry got an interface that resolved to " + n + "; expected a NamedParameter");
+    }
+    final Type setType = ReflectionUtilities.getInterfaceTarget(Name.class, iface);
+    if (!ReflectionUtilities.getRawClass(setType).equals(Set.class)) {
+      throw new BindException("BindSetEntry got a NamedParameter that takes a " + setType + "; expected Set<...>");
+    }
+    final Type valType = ReflectionUtilities.getInterfaceTarget(Set.class, setType);
+    if (!ReflectionUtilities.getRawClass(valType).isAssignableFrom(impl)) {
+      throw new BindException("BindSetEntry got implementation " + impl + " that is incompatible with expected type " + valType);
+    }
+
+    super.bindSetEntry((NamedParameterNode<Set<T>>) n, m);
+    return this;
+  }
+
+  /**
+   * Binding list method for JavaConfigurationBuilder. It checks the type of a given named parameter,
+   * and whether all the list's elements can be applied to the named parameter. The elements' type
+   * should be either java Class or String.
+   * <p/>
+   * It does not check whether the list's String values can be parsed to T, like bindSetEntry.
+   *
+   * @param iface    target named parameter to be instantiated
+   * @param implList implementation list used to instantiate the named parameter
+   * @param <T>      type of the list
+   * @return bound JavaConfigurationBuilder object
+   * @throws BindException
+   */
+  @SuppressWarnings("unchecked")
+  @Override
+  public <T> JavaConfigurationBuilder bindList(Class<? extends Name<List<T>>> iface, List implList)
+      throws BindException {
+    final Node n = getNode(iface);
+    List<Object> result = new ArrayList<>();
+
+    if (!(n instanceof NamedParameterNode)) {
+      throw new BindException("BindList got an interface that resolved to " + n + "; expected a NamedParameter");
+    }
+    final Type listType = ReflectionUtilities.getInterfaceTarget(Name.class, iface);
+    if (!ReflectionUtilities.getRawClass(listType).equals(List.class)) {
+      throw new BindException("BindList got a NamedParameter that takes a " + listType + "; expected List<...>");
+    }
+    if (!implList.isEmpty()) {
+      final Type valType = ReflectionUtilities.getInterfaceTarget(List.class, listType);
+      for (Object item : implList) {
+        if (item instanceof Class) {
+          if (!ReflectionUtilities.getRawClass(valType).isAssignableFrom((Class) item)) {
+            throw new BindException("BindList got a list element which is not assignable to the given Type; " +
+                "expected: " + valType);
+          }
+          result.add(getNode((Class) item));
+        } else if (item instanceof String) {
+          result.add(item);
+        } else {
+          throw new BindException("BindList got an list element with unsupported type; expected Class or String " +
+              "object");
+        }
+      }
+    }
+
+    super.bindList((NamedParameterNode<List<T>>) n, result);
+    return this;
+  }
+
+  private class JavaConfigurationImpl extends ConfigurationImpl {
+    JavaConfigurationImpl(JavaConfigurationBuilderImpl builder) {
+      super(builder);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/JavaInstance.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/JavaInstance.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/JavaInstance.java
new file mode 100644
index 0000000..2d1a21c
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/JavaInstance.java
@@ -0,0 +1,75 @@
+/**
+ * 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.reef.tang.implementation.java;
+
+import org.apache.reef.tang.implementation.InjectionPlan;
+import org.apache.reef.tang.types.Node;
+
+final public class JavaInstance<T> extends InjectionPlan<T> {
+  final T instance;
+
+  public JavaInstance(Node name, T instance) {
+    super(name);
+    this.instance = instance;
+  }
+
+  @Override
+  public int getNumAlternatives() {
+    return instance == null ? 0 : 1;
+  }
+
+  @Override
+  public String toString() {
+    return getNode() + " = " + instance;
+  }
+
+  @Override
+  public boolean isAmbiguous() {
+    return false;
+  }
+
+  @Override
+  public boolean isInjectable() {
+    return instance != null;
+  }
+
+  public String getInstanceAsString() {
+    return instance.toString();
+  }
+
+  @Override
+  protected String toAmbiguousInjectString() {
+    throw new IllegalArgumentException("toAmbiguousInjectString called on JavaInstance!" + this.toString());
+  }
+
+  @Override
+  protected String toInfeasibleInjectString() {
+    return getNode() + " is not bound.";
+  }
+
+  @Override
+  protected boolean isInfeasibleLeaf() {
+    return true;
+  }
+
+  @Override
+  public String toShallowString() {
+    return toString();
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/JavaNodeFactory.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/JavaNodeFactory.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/JavaNodeFactory.java
new file mode 100644
index 0000000..f727c89
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/JavaNodeFactory.java
@@ -0,0 +1,333 @@
+/**
+ * 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.reef.tang.implementation.java;
+
+import org.apache.reef.tang.ExternalConstructor;
+import org.apache.reef.tang.InjectionFuture;
+import org.apache.reef.tang.annotations.*;
+import org.apache.reef.tang.exceptions.ClassHierarchyException;
+import org.apache.reef.tang.implementation.types.*;
+import org.apache.reef.tang.types.*;
+import org.apache.reef.tang.util.MonotonicSet;
+import org.apache.reef.tang.util.ReflectionUtilities;
+
+import javax.inject.Inject;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+public class JavaNodeFactory {
+
+  @SuppressWarnings("unchecked")
+  static <T> ClassNodeImpl<T> createClassNode(Node parent, Class<T> clazz) throws ClassHierarchyException {
+    final boolean injectable;
+    final boolean unit = clazz.isAnnotationPresent(Unit.class);
+    final String simpleName = ReflectionUtilities.getSimpleName(clazz);
+    final String fullName = ReflectionUtilities.getFullName(clazz);
+    final boolean isStatic = Modifier.isStatic(clazz.getModifiers());
+    final boolean parentIsUnit = ((parent instanceof ClassNode) && !isStatic) ?
+        ((ClassNode<?>) parent).isUnit() : false;
+
+    if (clazz.isLocalClass() || clazz.isMemberClass()) {
+      if (!isStatic) {
+        if (parent instanceof ClassNode) {
+          injectable = ((ClassNode<?>) parent).isUnit();
+        } else {
+          injectable = false;
+        }
+      } else {
+        injectable = true;
+      }
+    } else {
+      injectable = true;
+    }
+
+    boolean foundNonStaticInnerClass = false;
+    for (Class<?> c : clazz.getDeclaredClasses()) {
+      if (!Modifier.isStatic(c.getModifiers())) {
+        foundNonStaticInnerClass = true;
+      }
+    }
+
+    if (unit && !foundNonStaticInnerClass) {
+      throw new ClassHierarchyException("Class " + ReflectionUtilities.getFullName(clazz) + " has an @Unit annotation, but no non-static inner classes.  Such @Unit annotations would have no effect, and are therefore disallowed.");
+    }
+
+    Constructor<T>[] constructors = (Constructor<T>[]) clazz
+        .getDeclaredConstructors();
+    MonotonicSet<ConstructorDef<T>> injectableConstructors = new MonotonicSet<>();
+    ArrayList<ConstructorDef<T>> allConstructors = new ArrayList<>();
+    for (int k = 0; k < constructors.length; k++) {
+      boolean constructorAnnotatedInjectable = (constructors[k]
+          .getAnnotation(Inject.class) != null);
+      if (constructorAnnotatedInjectable && constructors[k].isSynthetic()) {
+        // Not sure if we *can* unit test this one.
+        throw new ClassHierarchyException(
+            "Synthetic constructor was annotated with @Inject!");
+      }
+      if (parentIsUnit && (constructorAnnotatedInjectable || constructors[k].getParameterTypes().length != 1)) {
+        throw new ClassHierarchyException(
+            "Detected explicit constructor in class enclosed in @Unit " + fullName + "  Such constructors are disallowed.");
+      }
+      boolean constructorInjectable = constructorAnnotatedInjectable || parentIsUnit;
+      // ConstructorDef's constructor checks for duplicate
+      // parameters
+      // The injectableConstructors set checks for ambiguous
+      // boundConstructors.
+      ConstructorDef<T> def = JavaNodeFactory.createConstructorDef(injectable,
+          constructors[k], constructorAnnotatedInjectable);
+      if (constructorInjectable) {
+        if (injectableConstructors.contains(def)) {
+          throw new ClassHierarchyException(
+              "Ambiguous boundConstructors detected in class " + clazz + ": "
+                  + def + " differs from some other" + " constructor only "
+                  + "by parameter order.");
+        } else {
+          injectableConstructors.add(def);
+        }
+      }
+      allConstructors.add(def);
+    }
+    final String defaultImplementation;
+    if (clazz.isAnnotationPresent(DefaultImplementation.class)) {
+      DefaultImplementation defaultImpl
+          = clazz.getAnnotation(DefaultImplementation.class);
+      Class<?> defaultImplementationClazz = defaultImpl.value();
+      if (defaultImplementationClazz.equals(Void.class)) {
+        defaultImplementation = defaultImpl.name();
+        // XXX check isAssignableFrom, other type problems here.
+      } else {
+        if (!clazz.isAssignableFrom(defaultImplementationClazz)) {
+          throw new ClassHierarchyException(clazz
+              + " declares its default implementation to be non-subclass "
+              + defaultImplementationClazz);
+        }
+        defaultImplementation = ReflectionUtilities.getFullName(defaultImplementationClazz);
+      }
+    } else {
+      defaultImplementation = null;
+    }
+
+    return new ClassNodeImpl<T>(parent, simpleName, fullName, unit, injectable,
+        ExternalConstructor.class.isAssignableFrom(clazz),
+        injectableConstructors.toArray(new ConstructorDefImpl[0]),
+        allConstructors.toArray(new ConstructorDefImpl[0]), defaultImplementation);
+  }
+
+  /**
+   * XXX: This method assumes that all generic types have exactly one type parameter.
+   */
+  public static <T> NamedParameterNode<T> createNamedParameterNode(Node parent,
+                                                                   Class<? extends Name<T>> clazz, Type argClass) throws ClassHierarchyException {
+
+    Class<?> argRawClass = ReflectionUtilities.getRawClass(argClass);
+
+    final boolean isSet = argRawClass.equals(Set.class);
+    final boolean isList = argRawClass.equals(List.class);
+
+
+    if (isSet || isList) {
+      argClass = ReflectionUtilities.getInterfaceTarget(Collection.class, argClass);
+      argRawClass = ReflectionUtilities.getRawClass(argClass);
+    }
+
+    final String simpleName = ReflectionUtilities.getSimpleName(clazz);
+    final String fullName = ReflectionUtilities.getFullName(clazz);
+    final String fullArgName = ReflectionUtilities.getFullName(argClass);
+    final String simpleArgName = ReflectionUtilities.getSimpleName(argClass);
+
+
+    final NamedParameter namedParameter = clazz.getAnnotation(NamedParameter.class);
+
+    if (namedParameter == null) {
+      throw new IllegalStateException("Got name without named parameter post-validation!");
+    }
+    final boolean hasStringDefault, hasClassDefault, hasStringSetDefault, hasClassSetDefault;
+
+    int default_count = 0;
+    if (!namedParameter.default_value().isEmpty()) {
+      hasStringDefault = true;
+      default_count++;
+    } else {
+      hasStringDefault = false;
+    }
+    if (namedParameter.default_class() != Void.class) {
+      hasClassDefault = true;
+      default_count++;
+    } else {
+      hasClassDefault = false;
+    }
+    if (namedParameter.default_values() != null && namedParameter.default_values().length > 0) {
+      hasStringSetDefault = true;
+      default_count++;
+    } else {
+      hasStringSetDefault = false;
+    }
+    if (namedParameter.default_classes() != null && namedParameter.default_classes().length > 0) {
+      hasClassSetDefault = true;
+      default_count++;
+    } else {
+      hasClassSetDefault = false;
+    }
+    if (default_count > 1) {
+      throw new ClassHierarchyException("Named parameter " + fullName + " defines more than one of default_value, default_class, default_values and default_classes");
+    }
+
+    final String[] defaultInstanceAsStrings;
+
+    if (default_count == 0) {
+      defaultInstanceAsStrings = new String[]{};
+    } else if (hasClassDefault) {
+      final Class<?> default_class = namedParameter.default_class();
+      assertIsSubclassOf(clazz, default_class, argClass);
+      defaultInstanceAsStrings = new String[]{ReflectionUtilities.getFullName(default_class)};
+    } else if (hasStringDefault) {
+      // Don't know if the string is a class or literal here, so don't bother validating.
+      defaultInstanceAsStrings = new String[]{namedParameter.default_value()};
+    } else if (hasClassSetDefault) {
+      Class<?>[] clzs = namedParameter.default_classes();
+      defaultInstanceAsStrings = new String[clzs.length];
+      for (int i = 0; i < clzs.length; i++) {
+        assertIsSubclassOf(clazz, clzs[i], argClass);
+        defaultInstanceAsStrings[i] = ReflectionUtilities.getFullName(clzs[i]);
+      }
+    } else if (hasStringSetDefault) {
+      defaultInstanceAsStrings = namedParameter.default_values();
+    } else {
+      throw new IllegalStateException();
+    }
+
+    final String documentation = namedParameter.doc();
+
+    final String shortName = namedParameter.short_name().isEmpty()
+        ? null : namedParameter.short_name();
+
+    return new NamedParameterNodeImpl<>(parent, simpleName, fullName,
+        fullArgName, simpleArgName, isSet, isList, documentation, shortName, defaultInstanceAsStrings);
+  }
+
+  private static void assertIsSubclassOf(Class<?> named_parameter, Class<?> default_class,
+                                         Type argClass) {
+    boolean isSubclass = false;
+    boolean isGenericSubclass = false;
+    Class<?> argRawClass = ReflectionUtilities.getRawClass(argClass);
+
+    // Note: We intentionally strip the raw type information here.  The reason is to handle
+    // EventHandler-style patterns and collections.
+
+    /// If we have a Name that takes EventHandler<A>, we want to be able to pass in an EventHandler<Object>.
+
+    for (final Type c : ReflectionUtilities.classAndAncestors(default_class)) {
+      if (ReflectionUtilities.getRawClass(c).equals(argRawClass)) {
+        isSubclass = true;
+        if (argClass instanceof ParameterizedType &&
+            c instanceof ParameterizedType) {
+          ParameterizedType argPt = (ParameterizedType) argClass;
+          ParameterizedType defaultPt = (ParameterizedType) c;
+
+          Class<?> rawDefaultParameter = ReflectionUtilities.getRawClass(defaultPt.getActualTypeArguments()[0]);
+          Class<?> rawArgParameter = ReflectionUtilities.getRawClass(argPt.getActualTypeArguments()[0]);
+
+          for (final Type d : ReflectionUtilities.classAndAncestors(argPt.getActualTypeArguments()[0])) {
+            if (ReflectionUtilities.getRawClass(d).equals(rawDefaultParameter)) {
+              isGenericSubclass = true;
+            }
+          }
+          for (final Type d : ReflectionUtilities.classAndAncestors(defaultPt.getActualTypeArguments()[0])) {
+            if (ReflectionUtilities.getRawClass(d).equals(rawArgParameter)) {
+              isGenericSubclass = true;
+            }
+          }
+        } else {
+          isGenericSubclass = true;
+        }
+      }
+    }
+
+    if (!(isSubclass)) {
+      throw new ClassHierarchyException(named_parameter + " defines a default class "
+          + ReflectionUtilities.getFullName(default_class) + " with a raw type that does not extend of its target's raw type " + argRawClass);
+    }
+    if (!(isGenericSubclass)) {
+      throw new ClassHierarchyException(named_parameter + " defines a default class "
+          + ReflectionUtilities.getFullName(default_class) + " with a type that does not extend its target's type " + argClass);
+    }
+  }
+
+  public static PackageNode createRootPackageNode() {
+    return new PackageNodeImpl();
+  }
+
+  private static <T> ConstructorDef<T> createConstructorDef(
+      boolean isClassInjectionCandidate, Constructor<T> constructor,
+      boolean injectable) throws ClassHierarchyException {
+    // We don't support injection of non-static member classes with @Inject
+    // annotations.
+    if (injectable && !isClassInjectionCandidate) {
+      throw new ClassHierarchyException("Cannot @Inject non-static member class unless the enclosing class an @Unit.  Nested class is:"
+          + ReflectionUtilities.getFullName(constructor.getDeclaringClass()));
+    }
+    // TODO: When we use paramTypes below, we strip generic parameters.  Is that OK?
+    Class<?>[] paramTypes = constructor.getParameterTypes();
+    Type[] genericParamTypes = constructor.getGenericParameterTypes();
+    Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
+    if (paramTypes.length != paramAnnotations.length) {
+      throw new IllegalStateException();
+    }
+    ConstructorArg[] args = new ConstructorArg[genericParamTypes.length];
+    for (int i = 0; i < genericParamTypes.length; i++) {
+      // If this parameter is an injection future, unwrap the target class,
+      // and remember by setting isFuture to true.
+      final Type type;
+      final boolean isFuture;
+      if (InjectionFuture.class.isAssignableFrom(paramTypes[i])) {
+        type = ReflectionUtilities.getInterfaceTarget(InjectionFuture.class, genericParamTypes[i]);
+        isFuture = true;
+      } else {
+        type = paramTypes[i];
+        isFuture = false;
+      }
+      // Make node of the named parameter annotation (if any).
+      Parameter named = null;
+      for (int j = 0; j < paramAnnotations[i].length; j++) {
+        Annotation annotation = paramAnnotations[i][j];
+        if (annotation instanceof Parameter) {
+          if ((!isClassInjectionCandidate) || !injectable) {
+            throw new ClassHierarchyException(constructor + " is not injectable, but it has an @Parameter annotation.");
+          }
+          named = (Parameter) annotation;
+        }
+      }
+      args[i] = new ConstructorArgImpl(
+          ReflectionUtilities.getFullName(type), named == null ? null
+          : ReflectionUtilities.getFullName(named.value()),
+          isFuture);
+    }
+    return new ConstructorDefImpl<T>(
+        ReflectionUtilities.getFullName(constructor.getDeclaringClass()),
+        args, injectable);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/package-info.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/package-info.java
new file mode 100644
index 0000000..cc8cbc0
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/java/package-info.java
@@ -0,0 +1,29 @@
+/**
+ * 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.
+ */
+/**
+ * Private implementation classes that configure and inject code written
+ * in Java.  Tang supports cross-language object injections.  The classes
+ * in org.apache.reef.tang.implementation are agnostic to the application
+ * language.  In contrast, the classes in this package provide convenience
+ * APIs that move type-checking to Java's generic type system, and are also
+ * responsible for actually injecting objects (since, by definition, Java
+ * JVMs inject Java objects).  
+ */
+package org.apache.reef.tang.implementation.java;
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/package-info.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/package-info.java
new file mode 100644
index 0000000..7c68e79
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/package-info.java
@@ -0,0 +1,27 @@
+/**
+ * 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.
+ */
+/**
+ * Tang's implementation.  Ideally, applications should never need to be
+ * aware of anything in this package or its sub-packages.  As of this
+ * writing, some layering violations still exist, and portions of this
+ * package (such as the InjectionPlan APIs) are needed in rare
+ * circumstances. 
+ */
+package org.apache.reef.tang.implementation;
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/protobuf/ProtocolBufferClassHierarchy.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/protobuf/ProtocolBufferClassHierarchy.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/protobuf/ProtocolBufferClassHierarchy.java
new file mode 100644
index 0000000..8053078
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/protobuf/ProtocolBufferClassHierarchy.java
@@ -0,0 +1,396 @@
+/**
+ * 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.reef.tang.implementation.protobuf;
+
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.exceptions.NameResolutionException;
+import org.apache.reef.tang.implementation.types.*;
+import org.apache.reef.tang.proto.ClassHierarchyProto;
+import org.apache.reef.tang.types.*;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
+public class ProtocolBufferClassHierarchy implements ClassHierarchy {
+
+  private static final String regex = "[\\.\\$\\+]";
+  private final PackageNode namespace;
+  private HashMap<String, Node> lookupTable = new HashMap<>();
+
+  // ############## Serialize implementation ############## 
+
+  // protoc doesn't believe in auto-generating constructors, so here are
+  // hand-generated ones. *sigh*
+
+  /**
+   * Deserialize a class hierarchy from a protocol buffer object.  The resulting
+   * object is immutable, and does not make use of reflection to fill in any
+   * missing values.  This allows it to represent non-native classes as well
+   * as snapshots of Java class hierarchies.
+   */
+  public ProtocolBufferClassHierarchy(ClassHierarchyProto.Node root) {
+    namespace = new PackageNodeImpl();
+    if (!root.hasPackageNode()) {
+      throw new IllegalArgumentException("Expected a package node.  Got: "
+          + root);
+    }
+    // Register all the classes.
+    for (ClassHierarchyProto.Node child : root.getChildrenList()) {
+      parseSubHierarchy(namespace, child);
+    }
+    buildLookupTable(namespace);
+    // Now, register the implementations
+    for (ClassHierarchyProto.Node child : root.getChildrenList()) {
+      wireUpInheritanceRelationships(child);
+    }
+  }
+
+  private static ClassHierarchyProto.Node newClassNode(String name,
+                                                       String fullName, boolean isInjectionCandidate,
+                                                       boolean isExternalConstructor, boolean isUnit,
+                                                       List<ClassHierarchyProto.ConstructorDef> injectableConstructors,
+                                                       List<ClassHierarchyProto.ConstructorDef> otherConstructors,
+                                                       List<String> implFullNames, Iterable<ClassHierarchyProto.Node> children) {
+    return ClassHierarchyProto.Node
+        .newBuilder()
+        .setName(name)
+        .setFullName(fullName)
+        .setClassNode(
+            ClassHierarchyProto.ClassNode.newBuilder()
+                .setIsInjectionCandidate(isInjectionCandidate)
+                .setIsExternalConstructor(isExternalConstructor)
+                .setIsUnit(isUnit)
+                .addAllInjectableConstructors(injectableConstructors)
+                .addAllOtherConstructors(otherConstructors)
+                .addAllImplFullNames(implFullNames).build())
+        .addAllChildren(children).build();
+  }
+
+  private static ClassHierarchyProto.Node newNamedParameterNode(String name,
+                                                                String fullName, String simpleArgClassName, String fullArgClassName,
+                                                                boolean isSet,
+                                                                boolean isList,
+                                                                String documentation, // can be null
+                                                                String shortName, // can be null
+                                                                String[] instanceDefault, // can be null
+                                                                Iterable<ClassHierarchyProto.Node> children) {
+    ClassHierarchyProto.NamedParameterNode.Builder namedParameterNodeBuilder
+        = ClassHierarchyProto.NamedParameterNode.newBuilder()
+        .setSimpleArgClassName(simpleArgClassName)
+        .setFullArgClassName(fullArgClassName)
+        .setIsSet(isSet)
+        .setIsList(isList);
+    if (documentation != null) {
+      namedParameterNodeBuilder.setDocumentation(documentation);
+    }
+    if (shortName != null) {
+      namedParameterNodeBuilder.setShortName(shortName);
+    }
+    if (instanceDefault != null) {
+      namedParameterNodeBuilder.addAllInstanceDefault(Arrays.asList(instanceDefault));
+    }
+
+    return ClassHierarchyProto.Node.newBuilder().setName(name)
+        .setFullName(fullName)
+        .setNamedParameterNode(namedParameterNodeBuilder.build())
+        .addAllChildren(children).build();
+  }
+
+  private static ClassHierarchyProto.Node newPackageNode(String name,
+                                                         String fullName, Iterable<ClassHierarchyProto.Node> children) {
+    return ClassHierarchyProto.Node.newBuilder()
+        .setPackageNode(ClassHierarchyProto.PackageNode.newBuilder().build())
+        .setName(name).setFullName(fullName).addAllChildren(children).build();
+  }
+
+  private static ClassHierarchyProto.ConstructorDef newConstructorDef(
+      String fullClassName, List<ClassHierarchyProto.ConstructorArg> args) {
+    return ClassHierarchyProto.ConstructorDef.newBuilder()
+        .setFullClassName(fullClassName).addAllArgs(args).build();
+  }
+
+  // these serialize...() methods copy a pieces of the class hierarchy into
+  // protobufs 
+
+  private static ClassHierarchyProto.ConstructorArg newConstructorArg(
+      String fullArgClassName, String namedParameterName, boolean isFuture) {
+    ClassHierarchyProto.ConstructorArg.Builder builder =
+        ClassHierarchyProto.ConstructorArg.newBuilder()
+            .setFullArgClassName(fullArgClassName)
+            .setIsInjectionFuture(isFuture);
+    if (namedParameterName != null) {
+      builder.setNamedParameterName(namedParameterName).build();
+    }
+    return builder.build();
+  }
+
+  private static ClassHierarchyProto.ConstructorDef serializeConstructorDef(
+      ConstructorDef<?> def) {
+    List<ClassHierarchyProto.ConstructorArg> args = new ArrayList<>();
+    for (ConstructorArg arg : def.getArgs()) {
+      args.add(newConstructorArg(arg.getType(), arg.getNamedParameterName(), arg.isInjectionFuture()));
+    }
+    return newConstructorDef(def.getClassName(), args);
+  }
+
+  private static ClassHierarchyProto.Node serializeNode(Node n) {
+    List<ClassHierarchyProto.Node> children = new ArrayList<>();
+    for (Node child : n.getChildren()) {
+      children.add(serializeNode(child));
+    }
+    if (n instanceof ClassNode) {
+      ClassNode<?> cn = (ClassNode<?>) n;
+      ConstructorDef<?>[] injectable = cn.getInjectableConstructors();
+      ConstructorDef<?>[] all = cn.getAllConstructors();
+      List<ConstructorDef<?>> others = new ArrayList<>(Arrays.asList(all));
+      others.removeAll(Arrays.asList(injectable));
+
+      List<ClassHierarchyProto.ConstructorDef> injectableConstructors = new ArrayList<>();
+      for (ConstructorDef<?> inj : injectable) {
+        injectableConstructors.add(serializeConstructorDef(inj));
+      }
+      List<ClassHierarchyProto.ConstructorDef> otherConstructors = new ArrayList<>();
+      for (ConstructorDef<?> other : others) {
+        otherConstructors.add(serializeConstructorDef(other));
+      }
+      List<String> implFullNames = new ArrayList<>();
+      for (ClassNode<?> impl : cn.getKnownImplementations()) {
+        implFullNames.add(impl.getFullName());
+      }
+      return newClassNode(cn.getName(), cn.getFullName(),
+          cn.isInjectionCandidate(), cn.isExternalConstructor(), cn.isUnit(),
+          injectableConstructors, otherConstructors, implFullNames, children);
+    } else if (n instanceof NamedParameterNode) {
+      NamedParameterNode<?> np = (NamedParameterNode<?>) n;
+      return newNamedParameterNode(np.getName(), np.getFullName(),
+          np.getSimpleArgName(), np.getFullArgName(), np.isSet(), np.isList(), np.getDocumentation(),
+          np.getShortName(), np.getDefaultInstanceAsStrings(), children);
+    } else if (n instanceof PackageNode) {
+      return newPackageNode(n.getName(), n.getFullName(), children);
+    } else {
+      throw new IllegalStateException("Encountered unknown type of Node: " + n);
+    }
+  }
+
+  /**
+   * Serialize a class hierarchy into a protocol buffer object.
+   *
+   * @param classHierarchy
+   * @return
+   */
+  public static ClassHierarchyProto.Node serialize(ClassHierarchy classHierarchy) {
+    return serializeNode(classHierarchy.getNamespace());
+  }
+
+  /**
+   * serialize a class hierarchy into a file
+   *
+   * @param file
+   * @param classHierarchy
+   * @throws IOException
+   */
+  public static void serialize(final File file, final ClassHierarchy classHierarchy) throws IOException {
+    final ClassHierarchyProto.Node node = serializeNode(classHierarchy.getNamespace());
+    try (final FileOutputStream output = new FileOutputStream(file)) {
+      try (final DataOutputStream dos = new DataOutputStream(output)) {
+        node.writeTo(dos);
+      }
+    }
+  }
+
+  /**
+   * Deserialize a class hierarchy from a file. The file can be generated from either Java or C#
+   *
+   * @param file
+   * @return
+   * @throws IOException
+   */
+  public static ClassHierarchy deserialize(final File file) throws IOException {
+    try (final InputStream stream = new FileInputStream(file)) {
+      final ClassHierarchyProto.Node root = ClassHierarchyProto.Node.parseFrom(stream);
+      return new ProtocolBufferClassHierarchy(root);
+    }
+  }
+
+  private static void parseSubHierarchy(Node parent, ClassHierarchyProto.Node n) {
+    final Node parsed;
+    if (n.hasPackageNode()) {
+      parsed = new PackageNodeImpl(parent, n.getName(), n.getFullName());
+    } else if (n.hasNamedParameterNode()) {
+      ClassHierarchyProto.NamedParameterNode np = n.getNamedParameterNode();
+      parsed = new NamedParameterNodeImpl<Object>(parent, n.getName(),
+          n.getFullName(), np.getFullArgClassName(), np.getSimpleArgClassName(),
+          np.getIsSet(), np.getIsList(), np.getDocumentation(), np.getShortName(),
+          np.getInstanceDefaultList().toArray(new String[0]));
+    } else if (n.hasClassNode()) {
+      ClassHierarchyProto.ClassNode cn = n.getClassNode();
+      List<ConstructorDef<?>> injectableConstructors = new ArrayList<>();
+      List<ConstructorDef<?>> allConstructors = new ArrayList<>();
+
+      for (ClassHierarchyProto.ConstructorDef injectable : cn
+          .getInjectableConstructorsList()) {
+        ConstructorDef<?> def = parseConstructorDef(injectable, true);
+        injectableConstructors.add(def);
+        allConstructors.add(def);
+      }
+      for (ClassHierarchyProto.ConstructorDef other : cn
+          .getOtherConstructorsList()) {
+        ConstructorDef<?> def = parseConstructorDef(other, false);
+        allConstructors.add(def);
+
+      }
+      @SuppressWarnings("unchecked")
+      ConstructorDef<Object>[] dummy = new ConstructorDef[0];
+      parsed = new ClassNodeImpl<>(parent, n.getName(), n.getFullName(),
+          cn.getIsUnit(), cn.getIsInjectionCandidate(),
+          cn.getIsExternalConstructor(), injectableConstructors.toArray(dummy),
+          allConstructors.toArray(dummy), cn.getDefaultImplementation());
+    } else {
+      throw new IllegalStateException("Bad protocol buffer: got abstract node"
+          + n);
+    }
+    for (ClassHierarchyProto.Node child : n.getChildrenList()) {
+      parseSubHierarchy(parsed, child);
+    }
+  }
+
+  private static ConstructorDef<?> parseConstructorDef(
+      org.apache.reef.tang.proto.ClassHierarchyProto.ConstructorDef def,
+      boolean isInjectable) {
+    List<ConstructorArg> args = new ArrayList<>();
+    for (ClassHierarchyProto.ConstructorArg arg : def.getArgsList()) {
+      args.add(new ConstructorArgImpl(arg.getFullArgClassName(), arg
+          .getNamedParameterName(), arg.getIsInjectionFuture()));
+    }
+    return new ConstructorDefImpl<>(def.getFullClassName(),
+        args.toArray(new ConstructorArg[0]), isInjectable);
+  }
+
+  private static String getNthPrefix(String str, int n) {
+    n++; // want this function to be zero indexed...
+    for (int i = 0; i < str.length(); i++) {
+      char c = str.charAt(i);
+      if (c == '.' || c == '$' || c == '+') {
+        n--;
+      }
+      if (n == 0) {
+        return str.substring(0, i);
+      }
+    }
+    if (n == 1) {
+      return str;
+    } else {
+      throw new ArrayIndexOutOfBoundsException();
+    }
+  }
+
+  private void buildLookupTable(Node n) {
+    for (Node child : n.getChildren()) {
+      lookupTable.put(child.getFullName(), child);
+      buildLookupTable(child);
+    }
+  }
+
+  @SuppressWarnings({"rawtypes", "unchecked"})
+  private void wireUpInheritanceRelationships(final ClassHierarchyProto.Node n) {
+    if (n.hasClassNode()) {
+      final ClassHierarchyProto.ClassNode cn = n.getClassNode();
+      final ClassNode iface;
+      try {
+        iface = (ClassNode) getNode(n.getFullName());
+      } catch (NameResolutionException e) {
+        throw new IllegalStateException("When reading protocol buffer node "
+            + n.getFullName() + " does not exist.  Full record is " + n, e);
+      }
+      for (String impl : cn.getImplFullNamesList()) {
+        try {
+          iface.putImpl((ClassNode) getNode(impl));
+        } catch (NameResolutionException e) {
+          throw new IllegalStateException("When reading protocol buffer node "
+              + n + " refers to non-existent implementation:" + impl);
+        } catch (ClassCastException e) {
+          try {
+            throw new IllegalStateException(
+                "When reading protocol buffer node " + n
+                    + " found implementation" + getNode(impl)
+                    + " which is not a ClassNode!");
+          } catch (NameResolutionException e2) {
+            throw new IllegalStateException(
+                "Got 'cant happen' exception when producing error message for "
+                    + e);
+          }
+        }
+      }
+    }
+
+    for (ClassHierarchyProto.Node child : n.getChildrenList()) {
+      wireUpInheritanceRelationships(child);
+    }
+  }
+
+  @Override
+  public Node getNode(String fullName) throws NameResolutionException {
+
+    Node ret = lookupTable.get(fullName);
+/*    String[] tok = fullName.split(regex);
+
+    Node ret = namespace.get(fullName);
+    for (int i = 0; i < tok.length; i++) {
+      Node n = namespace.get(getNthPrefix(fullName, i));
+      if (n != null) {
+        for (i++; i < tok.length; i++) {
+          n = n.get(tok[i]);
+          if (n == null) {
+            throw new NameResolutionException(fullName, getNthPrefix(fullName,
+                i - 1));
+          }
+        }
+        return n;
+      }
+    } */
+    if (ret != null) {
+      return ret;
+    } else {
+      throw new NameResolutionException(fullName, "");
+    }
+  }
+
+  @Override
+  public boolean isImplementation(ClassNode<?> inter, ClassNode<?> impl) {
+    return impl.isImplementationOf(inter);
+  }
+
+  @Override
+  public ClassHierarchy merge(ClassHierarchy ch) {
+    if (this == ch) {
+      return this;
+    }
+    throw new UnsupportedOperationException(
+        "Cannot merge ExternalClassHierarchies yet!");
+  }
+
+  @Override
+  public Node getNamespace() {
+    return namespace;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/protobuf/ProtocolBufferInjectionPlan.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/protobuf/ProtocolBufferInjectionPlan.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/protobuf/ProtocolBufferInjectionPlan.java
new file mode 100644
index 0000000..9615d52
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/protobuf/ProtocolBufferInjectionPlan.java
@@ -0,0 +1,148 @@
+/**
+ * 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.reef.tang.implementation.protobuf;
+
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.NameResolutionException;
+import org.apache.reef.tang.implementation.Constructor;
+import org.apache.reef.tang.implementation.InjectionPlan;
+import org.apache.reef.tang.implementation.Subplan;
+import org.apache.reef.tang.implementation.java.JavaInstance;
+import org.apache.reef.tang.proto.InjectionPlanProto;
+import org.apache.reef.tang.types.ClassNode;
+import org.apache.reef.tang.types.ConstructorDef;
+import org.apache.reef.tang.types.Node;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class ProtocolBufferInjectionPlan {
+
+  <T> InjectionPlanProto.InjectionPlan newConstructor(final String fullName,
+                                                      List<InjectionPlanProto.InjectionPlan> plans) {
+    return InjectionPlanProto.InjectionPlan
+        .newBuilder()
+        .setName(fullName)
+        .setConstructor(
+            InjectionPlanProto.Constructor.newBuilder().addAllArgs(plans)
+                .build()).build();
+  }
+
+  <T> InjectionPlanProto.InjectionPlan newSubplan(final String fullName,
+                                                  int selectedPlan, List<InjectionPlanProto.InjectionPlan> plans) {
+    return InjectionPlanProto.InjectionPlan
+        .newBuilder()
+        .setName(fullName)
+        .setSubplan(
+            InjectionPlanProto.Subplan.newBuilder()
+                .setSelectedPlan(selectedPlan).addAllPlans(plans).build())
+        .build();
+  }
+
+  <T> InjectionPlanProto.InjectionPlan newInstance(final String fullName,
+                                                   final String value) {
+    return InjectionPlanProto.InjectionPlan.newBuilder().setName(fullName)
+        .setInstance(InjectionPlanProto.Instance.newBuilder().setValue(value))
+        .build();
+  }
+
+  public <T> InjectionPlanProto.InjectionPlan serialize(InjectionPlan<T> ip) {
+    if (ip instanceof Constructor) {
+      Constructor<T> cons = (Constructor<T>) ip;
+      InjectionPlan<?>[] args = cons.getArgs();
+      InjectionPlanProto.InjectionPlan[] protoArgs = new InjectionPlanProto.InjectionPlan[args.length];
+      for (int i = 0; i < args.length; i++) {
+        protoArgs[i] = serialize(args[i]);
+      }
+      return newConstructor(ip.getNode().getFullName(),
+          Arrays.asList(protoArgs));
+    } else if (ip instanceof Subplan) {
+      Subplan<T> sp = (Subplan<T>) ip;
+      InjectionPlan<?>[] args = sp.getPlans();
+      InjectionPlanProto.InjectionPlan[] subPlans = new InjectionPlanProto.InjectionPlan[args.length];
+      for (int i = 0; i < args.length; i++) {
+        subPlans[i] = serialize(args[i]);
+      }
+      return newSubplan(ip.getNode().getFullName(), sp.getSelectedIndex(),
+          Arrays.asList(subPlans));
+    } else if (ip instanceof JavaInstance) {
+      JavaInstance<T> ji = (JavaInstance<T>) ip;
+      return newInstance(ip.getNode().getFullName(), ji.getInstanceAsString());
+    } else {
+      throw new IllegalStateException(
+          "Encountered unknown type of InjectionPlan: " + ip);
+    }
+  }
+
+  private Object parse(String type, String value) {
+    // XXX this is a placeholder for now.  We need a parser API that will
+    // either produce a live java object or (partially) validate stuff to
+    // see if it looks like the target language will be able to handle this
+    // type + value.
+    return value;
+  }
+
+  @SuppressWarnings("unchecked")
+  public <T> InjectionPlan<T> deserialize(ClassHierarchy ch,
+                                          InjectionPlanProto.InjectionPlan ip) throws NameResolutionException,
+      BindException {
+    final String fullName = ip.getName();
+    if (ip.hasConstructor()) {
+      final InjectionPlanProto.Constructor cons = ip.getConstructor();
+
+      final ClassNode<T> cn = (ClassNode<T>) ch.getNode(fullName);
+
+      final InjectionPlanProto.InjectionPlan protoBufArgs[] = cons
+          .getArgsList().toArray(new InjectionPlanProto.InjectionPlan[0]);
+      final ClassNode<?>[] cnArgs = new ClassNode[protoBufArgs.length];
+
+      for (int i = 0; i < protoBufArgs.length; i++) {
+        cnArgs[i] = (ClassNode<?>) ch.getNode(protoBufArgs[i].getName());
+      }
+
+      final InjectionPlan<?> ipArgs[] = new InjectionPlan[protoBufArgs.length];
+
+      for (int i = 0; i < protoBufArgs.length; i++) {
+        ipArgs[i] = (InjectionPlan<?>) deserialize(ch, protoBufArgs[i]);
+      }
+
+      final ConstructorDef<T> constructor = cn.getConstructorDef(cnArgs);
+      return new Constructor<T>(cn, constructor, ipArgs);
+    } else if (ip.hasInstance()) {
+      InjectionPlanProto.Instance ins = ip.getInstance();
+      T instance = (T) parse(ip.getName(), ins.getValue());
+      return new JavaInstance<T>(ch.getNode(ip.getName()), instance);
+    } else if (ip.hasSubplan()) {
+      final InjectionPlanProto.Subplan subplan = ip.getSubplan();
+      final InjectionPlanProto.InjectionPlan protoBufPlans[] = subplan
+          .getPlansList().toArray(new InjectionPlanProto.InjectionPlan[0]);
+
+      final InjectionPlan<T> subPlans[] = new InjectionPlan[protoBufPlans.length];
+      for (int i = 0; i < protoBufPlans.length; i++) {
+        subPlans[i] = (InjectionPlan<T>) deserialize(ch, protoBufPlans[i]);
+      }
+      Node n = ch.getNode(fullName);
+      return new Subplan<T>(n, subPlans);
+    } else {
+      throw new IllegalStateException(
+          "Encountered unknown type of injection plan: " + ip);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/protobuf/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/protobuf/package-info.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/protobuf/package-info.java
new file mode 100644
index 0000000..da901a2
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/implementation/protobuf/package-info.java
@@ -0,0 +1,25 @@
+/**
+ * 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.
+ */
+/**
+ * Implementation classes that translate between Tang's core API and protocol
+ * buffers.  This enables cross-language injection sessions.
+ */
+
+package org.apache.reef.tang.implementation.protobuf;
+


[11/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/Tint.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/Tint.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/Tint.java
new file mode 100644
index 0000000..3db6afc
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/Tint.java
@@ -0,0 +1,735 @@
+/**
+ * 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.reef.tang.util;
+
+import org.apache.reef.tang.ExternalConstructor;
+import org.apache.reef.tang.JavaClassHierarchy;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.*;
+import org.apache.reef.tang.exceptions.ClassHierarchyException;
+import org.apache.reef.tang.exceptions.NameResolutionException;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.types.*;
+import org.apache.reef.tang.util.walk.AbstractClassHierarchyNodeVisitor;
+import org.apache.reef.tang.util.walk.NodeVisitor;
+import org.apache.reef.tang.util.walk.Walk;
+import org.reflections.Reflections;
+import org.reflections.scanners.MethodAnnotationsScanner;
+import org.reflections.scanners.MethodParameterScanner;
+import org.reflections.scanners.SubTypesScanner;
+import org.reflections.scanners.TypeAnnotationsScanner;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.PrintStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.TreeSet;
+
+public class Tint {
+  final private static String SETTERS = "setters";
+  final private static String USES = "uses";
+  final private static String FULLNAME = "fullName";
+  final JavaClassHierarchy ch;
+  final Map<Field, ConfigurationModule> modules = new MonotonicHashMap<>();
+  final MonotonicMultiMap<String, String> setters = new MonotonicMultiMap<>();
+  // map from thing that was used to user of the thing.
+  final MonotonicMultiMap<String, String> usages = new MonotonicMultiMap<>();
+  final Set<ClassNode<?>> knownClasses = new MonotonicSet<>();
+  final Set<String> divs = new MonotonicSet<>();
+
+  {
+    divs.add("doc");
+    divs.add(USES);
+    divs.add(SETTERS);
+
+  }
+
+  public Tint() {
+    this(new URL[0]);
+  }
+
+  public Tint(URL[] jars) {
+    this(jars, false);
+  }
+
+  @SuppressWarnings("unchecked")
+  public Tint(URL[] jars, boolean checkTang) {
+    Object[] args = new Object[jars.length + 6];
+    for (int i = 0; i < jars.length; i++) {
+      args[i] = jars[i];
+    }
+    args[args.length - 1] = new TypeAnnotationsScanner();
+    args[args.length - 2] = new SubTypesScanner();
+    args[args.length - 3] = new MethodAnnotationsScanner();
+    args[args.length - 4] = new MethodParameterScanner();
+    args[args.length - 5] = "com.microsoft";
+    args[args.length - 6] = "org.apache";
+    Reflections r = new Reflections(args);
+//    Set<Class<?>> classes = new MonotonicSet<>();
+    Set<String> strings = new TreeSet<>();
+    Set<String> moduleBuilders = new MonotonicSet<>();
+
+    // Workaround bug in Reflections by keeping things stringly typed, and using Tang to parse them.
+//  Set<Constructor<?>> injectConstructors = (Set<Constructor<?>>)(Set)r.getMethodsAnnotatedWith(Inject.class);
+//  for(Constructor<?> c : injectConstructors) {
+//    classes.add(c.getDeclaringClass());
+//  }
+    Set<String> injectConstructors = r.getStore().getConstructorsAnnotatedWith(ReflectionUtilities.getFullName(Inject.class));
+    for (String s : injectConstructors) {
+      strings.add(s.replaceAll("\\.<.+$", ""));
+    }
+    Set<String> parameterConstructors = r.getStore().get(MethodParameterScanner.class, ReflectionUtilities.getFullName(Parameter.class));
+    for (String s : parameterConstructors) {
+      strings.add(s.replaceAll("\\.<.+$", ""));
+    }
+//    Set<Class> r.getConstructorsWithAnyParamAnnotated(Parameter.class);
+//    for(Constructor<?> c : parameterConstructors) {
+//      classes.add(c.getDeclaringClass());
+//    }
+    Set<String> defaultStrings = r.getStore().get(TypeAnnotationsScanner.class, ReflectionUtilities.getFullName(DefaultImplementation.class));
+    strings.addAll(defaultStrings);
+    strings.addAll(r.getStore().get(TypeAnnotationsScanner.class, ReflectionUtilities.getFullName(NamedParameter.class)));
+    strings.addAll(r.getStore().get(TypeAnnotationsScanner.class, ReflectionUtilities.getFullName(Unit.class)));
+//    classes.addAll(r.getTypesAnnotatedWith(DefaultImplementation.class));
+//    classes.addAll(r.getTypesAnnotatedWith(NamedParameter.class));
+//    classes.addAll(r.getTypesAnnotatedWith(Unit.class));
+
+    strings.addAll(r.getStore().get(SubTypesScanner.class, ReflectionUtilities.getFullName(Name.class)));
+
+    moduleBuilders.addAll(r.getStore().get(SubTypesScanner.class, ReflectionUtilities.getFullName(ConfigurationModuleBuilder.class)));
+//    classes.addAll(r.getSubTypesOf(Name.class));
+
+    ch = Tang.Factory.getTang().getDefaultClassHierarchy(jars, (Class<? extends ExternalConstructor<?>>[]) new Class[0]);
+//    for(String s : defaultStrings) {
+//      if(classFilter(checkTang, s)) {
+//        try {
+//          ch.getNode(s);
+//        } catch(ClassHierarchyException | NameResolutionException | ClassNotFoundException e) {
+//          System.err.println(e.getMessage());
+//        }
+//      }
+//    }
+
+    for (String s : strings) {
+      if (classFilter(checkTang, s)) {
+        try {
+          ch.getNode(s);
+        } catch (ClassHierarchyException | NameResolutionException e) {
+          System.err.println(e.getMessage());
+        }
+      }
+    }
+    for (String s : moduleBuilders) {
+      if (classFilter(checkTang, s)) {
+        try {
+          ch.getNode(s);
+        } catch (ClassHierarchyException | NameResolutionException e) {
+          e.printStackTrace();
+        }
+      }
+    }
+
+    NodeVisitor<Node> v = new AbstractClassHierarchyNodeVisitor() {
+
+      @Override
+      public boolean visit(NamedParameterNode<?> node) {
+        String node_s = node.getFullName();
+        for (String s : node.getDefaultInstanceAsStrings()) {
+          if (!usages.contains(s, node_s)) {
+            usages.put(s, node_s);
+          }
+        }
+        return true;
+      }
+
+      @Override
+      public boolean visit(PackageNode node) {
+        return true;
+      }
+
+      @Override
+      public boolean visit(ClassNode<?> node) {
+        String node_s = node.getFullName();
+        for (ConstructorDef<?> d : node.getInjectableConstructors()) {
+          for (ConstructorArg a : d.getArgs()) {
+            if (a.getNamedParameterName() != null &&
+                !usages.contains(a.getNamedParameterName(), node_s)) {
+              usages.put(a.getNamedParameterName(), node_s);
+            }
+          }
+        }
+        if (!knownClasses.contains(node)) {
+          knownClasses.add(node);
+        }
+        return true;
+      }
+    };
+    int numClasses;
+    do {
+      numClasses = knownClasses.size();
+
+      Walk.preorder(v, null, ch.getNamespace());
+
+      for (ClassNode<?> cn : knownClasses) {
+        try {
+          String s = cn.getFullName();
+          if (classFilter(checkTang, s)) {
+            Class<?> c = ch.classForName(s);
+            processDefaultAnnotation(c);
+            processConfigurationModules(c);
+          }
+        } catch (ClassNotFoundException e) {
+          e.printStackTrace();
+        }
+      }
+
+      for (Field f : modules.keySet()) {
+        ConfigurationModule m = modules.get(f);
+        String f_s = ReflectionUtilities.getFullName(f);
+        Set<NamedParameterNode<?>> nps = m.getBoundNamedParameters();
+        for (NamedParameterNode<?> np : nps) {
+          String np_s = np.getFullName();
+          if (!setters.contains(np_s, f_s)) {
+            setters.put(np_s, f_s);
+          }
+        }
+      }
+    } while (numClasses != knownClasses.size()); // Note naive fixed point evaluation here.  Semi-naive would be faster.
+
+  }
+
+  public static String stripCommonPrefixes(String s) {
+    return
+        stripPrefixHelper2(
+            stripPrefixHelper2(s, "java.lang"),
+            "java.util");
+  }
+
+  public static String stripPrefixHelper2(String s, String prefix) {
+    String[] pretok = prefix.split("\\.");
+    String[] stok = s.split("\\.");
+    StringBuffer sb = new StringBuffer();
+    int i;
+    for (i = 0; i < pretok.length && i < stok.length; i++) {
+      if (pretok[i].equals(stok[i])) {
+        sb.append(pretok[i].charAt(0) + ".");
+      } else {
+        break;
+      }
+    }
+    for (; i < stok.length - 1; i++) {
+      sb.append(stok[i] + ".");
+    }
+    sb.append(stok[stok.length - 1]);
+    return sb.toString();
+  }
+
+  /*  public static String stripPrefixHelper(String s, String prefix) {
+      if(!"".equals(prefix) && s.startsWith(prefix+".")) {
+        try {
+          String suffix = s.substring(prefix.length()+1);
+          if(suffix.matches("^[A-Z].+")){
+            return suffix;
+          } else {
+            String shorten = prefix.replaceAll("([^.])[^.]+", "$1");
+            return shorten + "." + suffix;
+          }
+        } catch(StringIndexOutOfBoundsException e) {
+          throw new RuntimeException("Couldn't strip " + prefix + " from " + s, e);
+        }
+      } else {
+        return s;
+      }
+    }*/
+  public static String stripPrefix(String s, String prefix) {
+    return stripPrefixHelper2(stripPrefixHelper2(stripPrefixHelper2(
+        stripCommonPrefixes(stripPrefixHelper2(s, prefix)),
+        "org.apache.reef"), "org.apache.reef"), "org.apache.reef.wake");
+  }
+
+  /**
+   * @param args
+   * @throws FileNotFoundException
+   * @throws MalformedURLException
+   */
+  public static void main(String[] args) throws FileNotFoundException, MalformedURLException {
+    int i = 0;
+    String doc = null;
+    String jar = null;
+    boolean tangTests = false;
+    while (i < args.length) {
+      if (args[i].equals("--doc")) {
+        i++;
+        doc = args[i];
+      } else if (args[i].equals("--jar")) {
+        i++;
+        jar = args[i];
+      } else if (args[i].equals("--tang-tests")) {
+        tangTests = true;
+      }
+
+      i++;
+    }
+
+    final Tint t;
+    if (jar != null) {
+      final File f = new File(jar);
+      if (!f.exists()) {
+        throw new FileNotFoundException(jar);
+      }
+      t = new Tint(new URL[]{f.toURI().toURL()}, tangTests);
+    } else {
+      t = new Tint(new URL[0], tangTests);
+    }
+
+    if (doc != null) {
+      try (final PrintStream out = new PrintStream(new FileOutputStream(new File(doc)))) {
+        out.println("<html><head><title>TangDoc</title>");
+
+        out.println("<style>");
+        out.println("body { font-family: 'Segoe UI', 'Comic Sans MS'; font-size:12pt; font-weight: 200; margin: 1em; column-count: 2; }");
+        out.println(".package { font-size:18pt; font-weight: 500; column-span: all; }");
+//      out.println(".class { break-after: never; }");
+//      out.println(".doc { break-before: never; }");
+        out.println(".decl-margin { padding: 8pt; break-inside: avoid; }");
+        out.println(".module-margin { padding: 8pt; column-span: all; break-inside: avoid; }");
+        out.println(".decl { background-color: aliceblue; padding: 6pt;}");
+        out.println(".fullName { font-size: 11pt; font-weight: 400; }");
+        out.println(".simpleName { font-size: 11pt; font-weight: 400; }");
+        out.println(".constructorArg { padding-left: 16pt; }");
+        out.println("." + SETTERS + " { padding-top: 6pt; font-size: 10pt; }");
+        out.println("." + USES + " { padding-top: 6pt; font-size: 10pt; }");
+        out.println("pre { font-size: 10pt; }");
+        out.println("</style>");
+
+        out.println("</head><body>");
+//      out.println("<table border='1'><tr><th>Type</th><th>Name</th><th>Default value</th><th>Documentation</th><th>Used by</th><th>Set by</th></tr>");
+
+        String currentPackage = "";
+//      int numcols = 0;
+        for (final Node n : t.getNamesUsedAndSet()) {
+          String fullName = n.getFullName();
+          String tok[] = fullName.split("\\.");
+          StringBuffer sb = new StringBuffer(tok[0]);
+          for (int j = 1; j < tok.length; j++) {
+            if (tok[j].matches("^[A-Z].*") || j > 4) {
+              break;
+            } else
+              sb.append("." + tok[j]);
+          }
+          String pack = sb.toString();
+          if (!currentPackage.equals(pack)) {
+            currentPackage = pack;
+            out.println(t.endPackage());
+            out.println(t.startPackage(currentPackage));
+//          numcols = 0;
+//          out.println("<div class='row'>");
+          }
+//        numcols++;
+//        if(numcols == NUMCOLS) {
+//          out.println("</div><div class='row'>");
+//        }
+          if (n instanceof NamedParameterNode<?>) {
+            out.println(t.toHtmlString((NamedParameterNode<?>) n, currentPackage));
+          } else if (n instanceof ClassNode<?>) {
+            out.println(t.toHtmlString((ClassNode<?>) n, currentPackage));
+          } else {
+            throw new IllegalStateException();
+          }
+        }
+        out.println("</div>");
+        out.println(t.endPackage());
+//      out.println("</table>");
+        out.println("<div class='package'>Module definitions</div>");
+        for (final Field f : t.modules.keySet()) {
+          String moduleName = ReflectionUtilities.getFullName(f);
+//        String declaringClassName = ReflectionUtilities.getFullName(f.getDeclaringClass());
+          out.println("<div class='module-margin' id='" + moduleName + "'><div class='decl'><span class='fullName'>" + moduleName + "</span>");
+          out.println("<pre>");
+          String conf = t.modules.get(f).toPrettyString();
+          String[] tok = conf.split("\n");
+          for (final String line : tok) {
+            out.println(stripPrefix(line, "no.such.prefix"));//t.modules.get(f).toPrettyString());
+          }
+//        List<Entry<String,String>> lines = t.modules.get(f).toStringPairs();
+//        for(Entry<String,String> line : lines) {
+//          String k = t.stripPrefix(line.getKey(), declaringClassName);
+//          String v = t.stripPrefix(line.getValue(), declaringClassName);
+//          out.println(k+"="+v);
+//        }
+          out.println("</pre>");
+          out.println("</div></div>");
+        }
+
+        out.println("<div class='package'>Interfaces and injectable classes</div>");
+        for (final ClassNode<?> c : t.knownClasses) {
+          if (t.classFilter(tangTests, c.getFullName())) {
+            Class<?> clz = null;
+            try {
+              clz = t.ch.classForName(c.getFullName());
+            } catch (ClassNotFoundException e) {
+              // TODO Auto-generated catch block
+              e.printStackTrace();
+            }
+            String typ = clz.isInterface() ? "interface" : "class";
+            out.println("<div class='module-margin' id='" + c.getFullName() + "'><div class='decl'><span class='fullName'>" + typ + " " + c.getFullName() + "</span>");
+            for (ConstructorDef<?> d : c.getInjectableConstructors()) {
+              out.println("<div class='uses'>" + c.getFullName() + "(");
+              for (ConstructorArg a : d.getArgs()) {
+                if (a.getNamedParameterName() != null) {
+                  out.print("<div class='constructorArg'><a href='#" + a.getType() + "'>" + stripPrefix(a.getType(), "xxx") + "</a> <a href='#" + a.getNamedParameterName() + "'>" + a.getNamedParameterName() + "</a></div>");
+                } else {
+                  out.print("<div class='constructorArg'><a href='#" + a.getType() + "'>" + stripPrefix(a.getType(), "xxx") + "</a></div>");
+                }
+              }
+              out.println(")</div>");
+            }
+            out.println("</div></div>");
+          }
+/*
+      out.println("<h1>Default usage of classes and constants</h1>");
+      for(String s : t.usages.keySet()) {
+        out.println("<h2>" + s + "</h2>");
+        for(Node n : t.usages.getValuesForKey(s)) {
+          out.println("<p>" + n.getFullName() + "</p>");
+        }
+      } */
+        }
+        out.println("</body></html>");
+      }
+    }
+  }
+
+  private final boolean classFilter(boolean checkTang, String s) {
+    return (checkTang || /*s.startsWith("org.apache.reef.tang.examples.timer") ||*/ !s.startsWith("org.apache.reef.tang"));
+  }
+
+  private void processDefaultAnnotation(Class<?> cmb) {
+    DefaultImplementation di = cmb.getAnnotation(DefaultImplementation.class);
+    // XXX hack: move to helper method + unify with rest of Tang!
+    if (di != null) {
+      String diName = di.value() == Void.class ? di.name() : ReflectionUtilities.getFullName(di.value());
+      ClassNode<?> cn = (ClassNode<?>) ch.getNode(cmb);
+      String cn_s = cn.getFullName();
+      if (!usages.contains(diName, cn_s)) {
+        usages.put(diName, cn_s);
+        if (!knownClasses.contains(cn)) {
+          knownClasses.add(cn);
+        }
+      }
+    }
+  }
+
+  private void processConfigurationModules(Class<?> cmb) {
+    for (Field f : cmb.getFields()) {
+      if (ReflectionUtilities.isCoercable(ConfigurationModule.class, f.getType())) {
+        int mod = f.getModifiers();
+        boolean ok = true;
+        if (Modifier.isPrivate(mod)) {
+          System.err.println("Found private ConfigurationModule " + f);
+          ok = false;
+        }
+        if (!Modifier.isFinal(mod)) {
+          System.err.println("Found non-final ConfigurationModule " + f);
+          ok = false;
+        }
+        if (!Modifier.isStatic(f.getModifiers())) {
+          System.err.println("Found non-static ConfigurationModule " + f);
+          ok = false;
+        }
+        if (ok) {
+//          System.err.println("OK: " + f);
+          try {
+            f.setAccessible(true);
+            String f_s = ReflectionUtilities.getFullName(f);
+            if (!modules.containsKey(f)) {
+              modules.put(f, (ConfigurationModule) (f.get(null)));
+              try {
+                modules.get(f).assertStaticClean();
+              } catch (ClassHierarchyException e) {
+                System.err.println(f_s + ": " + e.getMessage());
+              }
+              for (Entry<String, String> e : modules.get(f).toStringPairs()) {
+                //System.err.println("e: " + e.getKey() + "=" + e.getValue());
+                try {
+                  Node n = ch.getNode(e.getKey());
+                  if (!setters.contains(e.getKey(), f_s)) {
+                    setters.put(e.getKey(), f_s);
+                  }
+                  if (n instanceof ClassNode) {
+                    ClassNode<?> cn = (ClassNode<?>) n;
+                    if (!knownClasses.contains(cn)) {
+                      knownClasses.add(cn);
+                    }
+                  }
+                } catch (NameResolutionException ex) {
+
+                }
+                try {
+                  String s = e.getValue();
+                  Node n = ch.getNode(s);
+                  if (!usages.contains(ReflectionUtilities.getFullName(f), s)) {
+                    //  System.err.println("Added usage: " + ReflectionUtilities.getFullName(f) + "=" + s);
+                    usages.put(s, ReflectionUtilities.getFullName(f));
+                  }
+                  if (n instanceof ClassNode) {
+                    ClassNode<?> cn = (ClassNode<?>) n;
+                    if (!knownClasses.contains(cn)) {
+                      System.err.println("Added " + cn + " to known classes");
+                      knownClasses.add(cn);
+                    }
+                  }
+                } catch (NameResolutionException ex) {
+
+                }
+              }
+            }
+          } catch (ExceptionInInitializerError e) {
+            System.err.println("Field " + ReflectionUtilities.getFullName(f) + ": " + e.getCause().getMessage());
+          } catch (IllegalAccessException e) {
+            throw new RuntimeException(e);
+          }
+        }
+      }
+    }
+  }
+
+  public Set<NamedParameterNode<?>> getNames() {
+    final Set<NamedParameterNode<?>> names = new MonotonicSet<>();
+    NodeVisitor<Node> v = new AbstractClassHierarchyNodeVisitor() {
+
+      @Override
+      public boolean visit(NamedParameterNode<?> node) {
+        names.add(node);
+        return true;
+      }
+
+      @Override
+      public boolean visit(PackageNode node) {
+        return true;
+      }
+
+      @Override
+      public boolean visit(ClassNode<?> node) {
+        return true;
+      }
+    };
+    Walk.preorder(v, null, ch.getNamespace());
+    return names;
+  }
+
+  public Set<Node> getNamesUsedAndSet() {
+    final Set<Node> names = new MonotonicSet<>();
+    final Set<String> userKeys = usages.keySet();
+    final Set<String> usedKeys = usages.values();
+    final Set<String> setterKeys = setters.keySet();
+    NodeVisitor<Node> v = new AbstractClassHierarchyNodeVisitor() {
+
+      @Override
+      public boolean visit(NamedParameterNode<?> node) {
+        names.add(node);
+        return true;
+      }
+
+      @Override
+      public boolean visit(PackageNode node) {
+        return true;
+      }
+
+      @Override
+      public boolean visit(ClassNode<?> node) {
+        String node_s = node.getFullName();
+        if (userKeys.contains(node_s)) {
+          names.add(node);
+        }
+        if (setterKeys.contains(node_s)) {
+          names.add(node);
+        }
+        if (usedKeys.contains(node_s)) {
+          if (!names.contains(node)) {
+            names.add(node);
+          }
+        }
+
+        return true;
+      }
+    };
+    Walk.preorder(v, null, ch.getNamespace());
+    return names;
+  }
+
+  public Set<String> getUsesOf(final Node name) {
+
+    return usages.getValuesForKey(name.getFullName());
+  }
+
+  public Set<String> getSettersOf(final Node name) {
+    return setters.getValuesForKey(name.getFullName());
+  }
+
+  public String toString(NamedParameterNode<?> n) {
+    StringBuilder sb = new StringBuilder("Name: " + n.getSimpleArgName() + " " + n.getFullName());
+    String[] instances = n.getDefaultInstanceAsStrings();
+    if (instances.length != 0) {
+      sb.append(" = ");
+      sb.append(join(",", instances));
+    }
+    if (!n.getDocumentation().equals("")) {
+      sb.append(" //" + n.getDocumentation());
+    }
+    return sb.toString();
+  }
+
+  private String join(String sep, String[] s) {
+    if (s.length > 0) {
+      StringBuffer sb = new StringBuffer(s[0]);
+      for (int i = 1; i < s.length; i++) {
+        sb.append(sep);
+        sb.append(s[i]);
+      }
+      return sb.toString();
+    } else {
+      return null;
+    }
+  }
+
+  public String cell(String s, String clazz) {
+    if (clazz.equals(USES) && s.length() > 0) {
+      s = "<em>Used by:</em><br>" + s;
+    }
+    if (clazz.equals(SETTERS) && s.length() > 0) {
+      s = "<em>Set by:</em><br>" + s;
+    }
+    if (clazz.equals(FULLNAME)) {
+      s = "&nbsp;" + s;
+    }
+    if (divs.contains(clazz)) {
+      return "<div class=\"" + clazz + "\">" + s + "</div>";
+    } else {
+      return "<span class=\"" + clazz + "\">" + s + "</span>";
+    }
+  }
+
+  public String cell(StringBuffer sb, String clazz) {
+    return cell(sb.toString(), clazz);
+  }
+
+  public String row(StringBuffer sb) {
+    return sb.toString();
+  }
+
+  public String toHtmlString(NamedParameterNode<?> n, String pack) {
+    String fullName = stripPrefix(n.getFullName(), pack);
+    StringBuffer sb = new StringBuffer();
+
+    sb.append("<div id='" + n.getFullName() + "' class='decl-margin'>");
+    sb.append("<div class='decl'>");
+
+    sb.append(cell(n.getSimpleArgName(), "simpleName") + cell(fullName, FULLNAME));
+    final String instance;
+    final String[] instances = n.getDefaultInstanceAsStrings();
+    if (instances.length != 0) {
+      StringBuffer sb2 = new StringBuffer(" = " + stripPrefix(instances[0], pack));
+      for (int i = 1; i < instances.length; i++) {
+        sb2.append("," + stripPrefix(instances[i], pack));
+      }
+      instance = sb2.toString();
+    } else {
+      instance = "";
+    }
+    sb.append(cell(instance, "instance"));
+    StringBuffer doc = new StringBuffer();
+    if (!n.getDocumentation().equals("")) {
+      doc.append(n.getDocumentation());
+    }
+    sb.append(cell(doc, "doc"));
+    StringBuffer uses = new StringBuffer();
+    for (String u : getUsesOf(n)) {
+      uses.append("<a href='#" + u + "'>" + stripPrefix(u, pack) + "</a> ");
+    }
+    sb.append(cell(uses, USES));
+    StringBuffer setters = new StringBuffer();
+    for (String f : getSettersOf(n)) {
+      setters.append("<a href='#" + f + "'>" + stripPrefix(f, pack) + "</a> ");
+    }
+    sb.append(cell(setters, SETTERS));
+    sb.append("</div>");
+    sb.append("</div>");
+    return row(sb);
+  }
+
+  public String toHtmlString(ClassNode<?> n, String pack) {
+    String fullName = stripPrefix(n.getFullName(), pack);
+
+    final String type;
+    try {
+      if (ch.classForName(n.getFullName()).isInterface()) {
+        type = "interface";
+      } else {
+        type = "class";
+      }
+    } catch (ClassNotFoundException e) {
+      throw new RuntimeException(e);
+    }
+    StringBuffer sb = new StringBuffer();
+
+    sb.append("<div class='decl-margin' id='" + n.getFullName() + "'>");
+    sb.append("<div class='decl'>");
+    sb.append(cell(type, "simpleName") + cell(fullName, FULLNAME));
+    final String instance;
+    if (n.getDefaultImplementation() != null) {
+      instance = " = " + stripPrefix(n.getDefaultImplementation(), pack);
+    } else {
+      instance = "";
+    }
+    sb.append(cell(instance, "simpleName"));
+    sb.append(cell("", "fullName")); // TODO: Documentation string?
+    StringBuffer uses = new StringBuffer();
+    for (String u : getUsesOf(n)) {
+      uses.append("<a href='#" + u + "'>" + stripPrefix(u, pack) + "</a> ");
+    }
+    sb.append(cell(uses, USES));
+    StringBuffer setters = new StringBuffer();
+    for (String f : getSettersOf(n)) {
+      setters.append("<a href='#" + f + "'>" + stripPrefix(f, pack) + "</a> ");
+    }
+    sb.append(cell(setters, SETTERS));
+    sb.append("</div>");
+    sb.append("</div>");
+    return row(sb);
+  }
+
+  public String startPackage(String pack) {
+    return "<div class=\"package\">" + pack + "</div>";
+//    return "<tr><td colspan='6'><br><b>" + pack + "</b></td></tr>";
+  }
+
+  public String endPackage() {
+    return "";
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/TracingMonotonicMap.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/TracingMonotonicMap.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/TracingMonotonicMap.java
new file mode 100644
index 0000000..54e27be
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/TracingMonotonicMap.java
@@ -0,0 +1,25 @@
+/**
+ * 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.reef.tang.util;
+
+import java.util.Map;
+
+public interface TracingMonotonicMap<K, V> extends Map<K, V> {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/TracingMonotonicTreeMap.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/TracingMonotonicTreeMap.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/TracingMonotonicTreeMap.java
new file mode 100644
index 0000000..53c833b
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/TracingMonotonicTreeMap.java
@@ -0,0 +1,146 @@
+/**
+ * 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.reef.tang.util;
+
+import org.apache.reef.tang.BindLocation;
+import org.apache.reef.tang.implementation.StackBindLocation;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+public final class TracingMonotonicTreeMap<K, V> implements TracingMonotonicMap<K, V> {
+  private final MonotonicTreeMap<K, EntryImpl> innerMap = new MonotonicTreeMap<>();
+
+  @Override
+  public void clear() {
+    innerMap.clear();
+  }
+
+  @Override
+  public boolean containsKey(Object key) {
+    return innerMap.containsKey(key);
+  }
+
+  @Override
+  public boolean containsValue(Object value) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public Set<java.util.Map.Entry<K, V>> entrySet() {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public V get(Object key) {
+    EntryImpl ret = innerMap.get(key);
+    return ret != null ? ret.getKey() : null;
+  }
+
+  @Override
+  public boolean isEmpty() {
+    return innerMap.isEmpty();
+  }
+
+  @Override
+  public Set<K> keySet() {
+    return innerMap.keySet();
+  }
+
+  @Override
+  public V put(K key, V value) {
+    EntryImpl ret = innerMap.put(key, new EntryImpl(value, new StackBindLocation()));
+    return ret != null ? ret.getKey() : null;
+  }
+
+  @Override
+  public void putAll(Map<? extends K, ? extends V> m) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public V remove(Object key) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public int size() {
+    return innerMap.size();
+  }
+
+  @Override
+  public Collection<V> values() {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) {
+      return true;
+    }
+    if (o == null || getClass() != o.getClass()) {
+      return false;
+    }
+
+    final TracingMonotonicTreeMap that = (TracingMonotonicTreeMap) o;
+
+    if (innerMap != null ? !innerMap.equals(that.innerMap) : that.innerMap != null) {
+      return false;
+    }
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return innerMap != null ? innerMap.hashCode() : 0;
+  }
+
+  private class EntryImpl implements Map.Entry<V, BindLocation> {
+    private final V key;
+    private final BindLocation value;
+
+    EntryImpl(V key, BindLocation value) {
+      this.key = key;
+      this.value = value;
+    }
+
+    @Override
+    public V getKey() {
+      return key;
+    }
+
+    @Override
+    public BindLocation getValue() {
+      return value;
+    }
+
+    @Override
+    public BindLocation setValue(BindLocation value) {
+      throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public String toString() {
+      return "[" + key + "] set by " + value;
+    }
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/ValidateConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/ValidateConfiguration.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/ValidateConfiguration.java
new file mode 100644
index 0000000..a990bad
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/ValidateConfiguration.java
@@ -0,0 +1,150 @@
+/**
+ * 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.reef.tang.util;
+
+import org.apache.reef.tang.*;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.CommandLine;
+import org.apache.reef.tang.formats.ConfigurationFile;
+import org.apache.reef.tang.implementation.InjectionPlan;
+import org.apache.reef.tang.implementation.protobuf.ProtocolBufferClassHierarchy;
+import org.apache.reef.tang.proto.ClassHierarchyProto;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+public class ValidateConfiguration {
+  private final String target;
+  private final File ch;
+  private final File inConfig;
+  private final File outConfig;
+//  @NamedParameter(short_name="ip")
+//  public class InjectionPlanOut implements Name<File> { }
+
+  @Inject
+  public ValidateConfiguration(
+      @Parameter(ClassHierarchyIn.class) File ch,
+      @Parameter(ConfigurationIn.class) File inConfig,
+      @Parameter(ConfigurationOut.class) File outConfig) {
+    this.target = null;
+    this.ch = ch;
+    this.inConfig = inConfig;
+    this.outConfig = outConfig;
+//    this.injectionPlan = injectionPlan;
+  }
+
+  @Inject
+  public ValidateConfiguration(
+      @Parameter(Target.class) String injectedClass,
+      @Parameter(ClassHierarchyIn.class) File ch,
+      @Parameter(ConfigurationIn.class) File inConfig,
+      @Parameter(ConfigurationOut.class) File outConfig) {
+    this.target = injectedClass;
+    this.ch = ch;
+    this.inConfig = inConfig;
+    this.outConfig = outConfig;
+  }
+
+  public static void main(String[] argv) throws IOException, BindException, InjectionException {
+    @SuppressWarnings("unchecked")
+    JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder((Class<? extends ExternalConstructor<?>>[]) new Class[]{FileParser.class});
+    CommandLine cl = new CommandLine(cb);
+    cl.processCommandLine(argv,
+        Target.class,
+        ClassHierarchyIn.class,
+        ConfigurationIn.class,
+        ConfigurationOut.class);
+    ValidateConfiguration bip = Tang.Factory.getTang().newInjector(cb.build()).getInstance(ValidateConfiguration.class);
+    bip.validatePlan();
+  }
+
+  public void validatePlan() throws IOException, BindException, InjectionException {
+
+    final Tang t = Tang.Factory.getTang();
+
+    final ClassHierarchyProto.Node root;
+    try (final InputStream chin = new FileInputStream(this.ch)) {
+      root = ClassHierarchyProto.Node.parseFrom(chin);
+    }
+
+    final ClassHierarchy ch = new ProtocolBufferClassHierarchy(root);
+    final ConfigurationBuilder cb = t.newConfigurationBuilder(ch);
+
+    if (!inConfig.canRead()) {
+      throw new IOException("Cannot read input config file: " + inConfig);
+    }
+
+    ConfigurationFile.addConfiguration(cb, inConfig);
+
+    if (target != null) {
+      final Injector i = t.newInjector(cb.build());
+      final InjectionPlan<?> ip = i.getInjectionPlan(target);
+      if (!ip.isInjectable()) {
+        throw new InjectionException(target + " is not injectable: " + ip.toCantInjectString());
+      }
+    }
+
+    ConfigurationFile.writeConfigurationFile(cb.build(), outConfig);
+
+//    Injector i = t.newInjector(cb.build());
+//    InjectionPlan<?> ip = i.getInjectionPlan(target);
+//    try (final OutputStream ipout = new FileOutputStream(injectionPlan)) {
+//      new ProtocolBufferInjectionPlan().serialize(ip).writeTo(ipout);
+//    }
+  }
+
+  public static class FileParser implements ExternalConstructor<File> {
+    private final File f;
+
+    @Inject
+    FileParser(String name) {
+      f = new File(name);
+    }
+
+    @Override
+    public File newInstance() {
+      return f;
+    }
+
+  }
+//  private final File injectionPlan;
+
+  @NamedParameter(short_name = "class")
+  public class Target implements Name<String> {
+  }
+
+  @NamedParameter(short_name = "ch")
+  public class ClassHierarchyIn implements Name<File> {
+  }
+
+  @NamedParameter(short_name = "in")
+  public class ConfigurationIn implements Name<File> {
+  }
+
+  @NamedParameter(short_name = "out")
+  public class ConfigurationOut implements Name<File> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/package-info.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/package-info.java
new file mode 100644
index 0000000..9e5cb43
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/package-info.java
@@ -0,0 +1,24 @@
+/**
+ * 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.
+ */
+/**
+ * Miscellaneous utilities, including command line static analysis (Tint), data structures and reflection stuff.
+ */
+
+package org.apache.reef.tang.util;
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/AbstractClassHierarchyNodeVisitor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/AbstractClassHierarchyNodeVisitor.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/AbstractClassHierarchyNodeVisitor.java
new file mode 100644
index 0000000..5083a3d
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/AbstractClassHierarchyNodeVisitor.java
@@ -0,0 +1,79 @@
+/**
+ * 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.reef.tang.util.walk;
+
+import org.apache.reef.tang.types.ClassNode;
+import org.apache.reef.tang.types.NamedParameterNode;
+import org.apache.reef.tang.types.Node;
+import org.apache.reef.tang.types.PackageNode;
+
+/**
+ * Generic interface to traverse nodes of the class hierarchy.
+ * Dispatches between ClassNode, PackageNode, and NamedParameterNode types.
+ * It is used e.g. in Walk.preorder()
+ */
+public abstract class AbstractClassHierarchyNodeVisitor implements NodeVisitor<Node> {
+
+  /**
+   * Manually dispatch between different types of Nodes and call a proper visit() method.
+   * Currently dispatches between ClassNode, PackageNode, and NamedParameterNode types.
+   *
+   * @param node TANG configuration node.
+   * @return true to proceed with the next node, false to cancel.
+   * @throws ClassCastException if Node is not one of ClassNode, PackageNode,
+   *                            or NamedParameterNode.
+   */
+  @Override
+  public boolean visit(final Node node) {
+    if (node instanceof ClassNode) {
+      return visit((ClassNode<?>) node);
+    } else if (node instanceof PackageNode) {
+      return visit((PackageNode) node);
+    } else if (node instanceof NamedParameterNode) {
+      return visit((NamedParameterNode<?>) node);
+    }
+    throw new ClassCastException(
+        "Node " + node.getClass() + " cannot be casted to one of the known subclasses."
+            + " Override this method to handle the case.");
+  }
+
+  /**
+   * Process current configuration node of ClassNode type.
+   *
+   * @param node Current configuration node.
+   * @return true to proceed with the next node, false to cancel.
+   */
+  public abstract boolean visit(ClassNode<?> node);
+
+  /**
+   * Process current configuration node of PackageNode type.
+   *
+   * @param node Current configuration node.
+   * @return true to proceed with the next node, false to cancel.
+   */
+  public abstract boolean visit(PackageNode node);
+
+  /**
+   * Process current configuration node of NamedParameterNode type.
+   *
+   * @param node Current configuration node.
+   * @return true to proceed with the next node, false to cancel.
+   */
+  public abstract boolean visit(NamedParameterNode<?> node);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/AbstractInjectionPlanNodeVisitor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/AbstractInjectionPlanNodeVisitor.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/AbstractInjectionPlanNodeVisitor.java
new file mode 100644
index 0000000..6cf7131
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/AbstractInjectionPlanNodeVisitor.java
@@ -0,0 +1,80 @@
+/**
+ * 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.reef.tang.util.walk;
+
+import org.apache.reef.tang.implementation.Constructor;
+import org.apache.reef.tang.implementation.InjectionPlan;
+import org.apache.reef.tang.implementation.Subplan;
+import org.apache.reef.tang.implementation.java.JavaInstance;
+
+/**
+ * Generic interface to traverse nodes of the injection plan.
+ * Dispatches between Constructor, Subplan, RequiredSingleton, and JavaInstance types.
+ * It is used e.g. in Walk.preorder()
+ */
+public abstract class AbstractInjectionPlanNodeVisitor implements NodeVisitor<InjectionPlan<?>> {
+
+  /**
+   * Manually dispatch between different types of injection plan objects and call proper
+   * visit() method. Currently dispatches between Constructor, Subplan, RequiredSingleton,
+   * and JavaInstance types.
+   *
+   * @param node TANG injection plan node.
+   * @return true to proceed with the next node, false to cancel.
+   * @throws ClassCastException if argument is not one of Constructor, Subplan,
+   *                            RequiredSingleton, or JavaInstance.
+   */
+  @Override
+  public boolean visit(final InjectionPlan<?> node) {
+    if (node instanceof Constructor<?>) {
+      return visit((Constructor<?>) node);
+    } else if (node instanceof Subplan<?>) {
+      return visit((Subplan<?>) node);
+    } else if (node instanceof JavaInstance<?>) {
+      return visit((JavaInstance<?>) node);
+    }
+    throw new ClassCastException(
+        "Node " + node.getClass() + " cannot be casted to one of the known subclasses."
+            + " Override this method to handle the case.");
+  }
+
+  /**
+   * Process current injection plan node of Constructor type.
+   *
+   * @param node Current injection plan node.
+   * @return true to proceed with the next node, false to cancel.
+   */
+  public abstract boolean visit(Constructor<?> node);
+
+  /**
+   * Process current injection plan node of JavaInstance type.
+   *
+   * @param node Current injection plan node.
+   * @return true to proceed with the next node, false to cancel.
+   */
+  public abstract boolean visit(JavaInstance<?> node);
+
+  /**
+   * Process current injection plan node of Subplan type.
+   *
+   * @param node Current injection plan node.
+   * @return true to proceed with the next node, false to cancel.
+   */
+  public abstract boolean visit(Subplan<?> node);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/EdgeVisitor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/EdgeVisitor.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/EdgeVisitor.java
new file mode 100644
index 0000000..bc159a8
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/EdgeVisitor.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.tang.util.walk;
+
+/**
+ * Generic interface to traverse edges of the configuration graph.
+ * It is used e.g. in Walk.preorder()
+ */
+public interface EdgeVisitor<T> {
+
+  /**
+   * Process current edge of the configuration graph.
+   *
+   * @param nodeFrom Current configuration node.
+   * @param nodeTo   Destination configuration node.
+   * @return true to proceed with the next node, false to cancel.
+   */
+  boolean visit(T nodeFrom, T nodeTo);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/NodeVisitor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/NodeVisitor.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/NodeVisitor.java
new file mode 100644
index 0000000..cfe4f01
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/NodeVisitor.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.tang.util.walk;
+
+
+/**
+ * Generic interface to traverse nodes of the configuration graph.
+ * It is used e.g. in Walk.preorder()
+ */
+public interface NodeVisitor<T> {
+
+  /**
+   * Process current configuration node.
+   *
+   * @param node Current configuration node.
+   * @return true to proceed with the next node, false to cancel.
+   */
+  boolean visit(T node);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/Walk.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/Walk.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/Walk.java
new file mode 100644
index 0000000..7b761ec
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/Walk.java
@@ -0,0 +1,66 @@
+/**
+ * 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.reef.tang.util.walk;
+
+import org.apache.reef.tang.types.Traversable;
+
+/**
+ * Generic graph traversal.
+ */
+public final class Walk {
+
+  /**
+   * This is a utility class that has only static methods - do not instantiate.
+   *
+   * @throws IllegalAccessException always.
+   */
+  private Walk() throws IllegalAccessException {
+    throw new IllegalAccessException("Do not instantiate this class.");
+  }
+
+  /**
+   * Traverse the configuration (sub)tree in preorder, starting from the given node.
+   * FIXME: handle loopy graphs correctly!
+   *
+   * @param nodeVisitor node visitor. Can be null.
+   * @param edgeVisitor edge visitor. Can be null.
+   * @param node        current node of the configuration tree.
+   * @return true if all nodes has been walked, false if visitor stopped early.
+   */
+  public static <T extends Traversable<T>> boolean preorder(
+      final NodeVisitor<T> nodeVisitor, final EdgeVisitor<T> edgeVisitor, final T node) {
+    if (nodeVisitor != null && nodeVisitor.visit(node)) {
+      if (edgeVisitor != null) {
+        for (final T child : node.getChildren()) {
+          if (!(edgeVisitor.visit(node, child)
+              && preorder(nodeVisitor, edgeVisitor, child))) {
+            return false;
+          }
+        }
+      } else {
+        for (final T child : node.getChildren()) {
+          if (!preorder(nodeVisitor, edgeVisitor, child)) {
+            return false;
+          }
+        }
+      }
+    }
+    return true;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/graphviz/GraphvizConfigVisitor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/graphviz/GraphvizConfigVisitor.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/graphviz/GraphvizConfigVisitor.java
new file mode 100644
index 0000000..cecd04f
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/graphviz/GraphvizConfigVisitor.java
@@ -0,0 +1,244 @@
+/**
+ * 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.reef.tang.util.walk.graphviz;
+
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.types.ClassNode;
+import org.apache.reef.tang.types.NamedParameterNode;
+import org.apache.reef.tang.types.Node;
+import org.apache.reef.tang.types.PackageNode;
+import org.apache.reef.tang.util.walk.AbstractClassHierarchyNodeVisitor;
+import org.apache.reef.tang.util.walk.EdgeVisitor;
+import org.apache.reef.tang.util.walk.Walk;
+
+/**
+ * Build a Graphviz representation of the configuration graph.
+ */
+public final class GraphvizConfigVisitor
+    extends AbstractClassHierarchyNodeVisitor implements EdgeVisitor<Node> {
+
+  /**
+   * Legend for the configuration graph in Graphviz format
+   */
+  private static final String LEGEND =
+      "  subgraph cluster_legend {\n"
+          + "    label=\"Legend\";\n"
+          + "    shape=box;\n"
+          + "    subgraph cluster_1 {\n"
+          + "      style=invis; label=\"\";\n"
+          + "      ex1l [shape=point, label=\"\"]; ex1r [shape=point, label=\"\"];\n"
+          + "      ex2l [shape=point, label=\"\"]; ex2r [shape=point, label=\"\"];\n"
+          + "      ex3l [shape=point, label=\"\"]; ex3r [shape=point, label=\"\"];\n"
+          + "      ex4l [shape=point, label=\"\"]; ex4r [shape=point, label=\"\"];\n"
+          + "      ex1l -> ex1r [style=solid, dir=back, arrowtail=diamond, label=\"contains\"];\n"
+          + "      ex2l -> ex2r [style=dashed, dir=back, arrowtail=empty, label=\"implements\"];\n"
+          + "      ex3l -> ex3r [style=\"dashed,bold\", dir=back, arrowtail=empty, label=\"external\"];\n"
+          + "      ex4l -> ex4r [style=solid, dir=back, arrowtail=normal, label=\"binds\"];\n"
+          + "    }\n"
+          + "    subgraph cluster_2 {\n"
+          + "      style=invis; label=\"\";\n"
+          + "      PackageNode [shape=folder];\n"
+          + "      ClassNode [shape=box];\n"
+          + "      Singleton [shape=box, style=filled];\n"
+          + "      NamedParameterNode [shape=oval];\n"
+          + "    }\n"
+          + "  }\n";
+
+  /**
+   * Accumulate string representation of the graph here.
+   */
+  private final transient StringBuilder graphStr = new StringBuilder(
+      "digraph ConfigMain {\n"
+          + "  rankdir=LR;\n");
+
+  /**
+   * Entire TANG configuration object.
+   */
+  private final transient Configuration config;
+
+  /**
+   * If true, plot IS-A edges for know implementations.
+   */
+  private final transient boolean showImpl;
+
+  /**
+   * Create a new TANG configuration visitor.
+   *
+   * @param aConfig     Entire TANG configuration object.
+   * @param aShowImpl   If true, plot IS-A edges for know implementations.
+   * @param aShowLegend If true, add legend to the plot.
+   */
+  public GraphvizConfigVisitor(final Configuration config,
+                               final boolean showImpl, final boolean showLegend) {
+    super();
+    this.config = config;
+    this.showImpl = showImpl;
+    if (showLegend) {
+      this.graphStr.append(LEGEND);
+    }
+  }
+
+  /**
+   * Produce a Graphviz DOT string for a given TANG configuration.
+   *
+   * @param config     TANG configuration object.
+   * @param showImpl   If true, plot IS-A edges for know implementations.
+   * @param showLegend If true, add legend to the plot.
+   * @return configuration graph represented as a string in Graphviz DOT format.
+   */
+  public static String getGraphvizString(final Configuration config,
+                                         final boolean showImpl, final boolean showLegend) {
+    final GraphvizConfigVisitor visitor = new GraphvizConfigVisitor(config, showImpl, showLegend);
+    final Node root = config.getClassHierarchy().getNamespace();
+    Walk.preorder(visitor, visitor, root);
+    return visitor.toString();
+  }
+
+  /**
+   * @return TANG configuration represented as a Graphviz DOT string.
+   */
+  @Override
+  public String toString() {
+    return this.graphStr.toString() + "}\n";
+  }
+
+  /**
+   * Process current class configuration node.
+   *
+   * @param node Current configuration node.
+   * @return true to proceed with the next node, false to cancel.
+   */
+  @Override
+  public boolean visit(final ClassNode<?> node) {
+
+    this.graphStr
+        .append("  ")
+        .append(node.getName())
+        .append(" [label=\"")
+        .append(node.getName())
+        .append("\", shape=box")
+//            .append(config.isSingleton(node) ? ", style=filled" : "")
+        .append("];\n");
+
+    final ClassNode<?> boundImplNode = config.getBoundImplementation(node);
+    if (boundImplNode != null) {
+      this.graphStr
+          .append("  ")
+          .append(node.getName())
+          .append(" -> ")
+          .append(boundImplNode.getName())
+          .append(" [style=solid, dir=back, arrowtail=normal];\n");
+    }
+
+    for (final Object implNodeObj : node.getKnownImplementations()) {
+      final ClassNode<?> implNode = (ClassNode<?>) implNodeObj;
+      if (implNode != boundImplNode && implNode != node
+          && (implNode.isExternalConstructor() || this.showImpl)) {
+        this.graphStr
+            .append("  ")
+            .append(node.getName())
+            .append(" -> ")
+            .append(implNode.getName())
+            .append(" [style=\"dashed")
+            .append(implNode.isExternalConstructor() ? ",bold" : "")
+            .append("\", dir=back, arrowtail=empty];\n");
+      }
+    }
+
+    return true;
+  }
+
+  /**
+   * Process current package configuration node.
+   *
+   * @param node Current configuration node.
+   * @return true to proceed with the next node, false to cancel.
+   */
+  @Override
+  public boolean visit(final PackageNode node) {
+    if (!node.getName().isEmpty()) {
+      this.graphStr
+          .append("  ")
+          .append(node.getName())
+          .append(" [label=\"")
+          .append(node.getFullName())
+          .append("\", shape=folder];\n");
+    }
+    return true;
+  }
+
+  /**
+   * Process current configuration node for the named parameter.
+   *
+   * @param node Current configuration node.
+   * @return true to proceed with the next node, false to cancel.
+   */
+  @Override
+  public boolean visit(final NamedParameterNode<?> node) {
+    this.graphStr
+        .append("  ")
+        .append(node.getName())
+        .append(" [label=\"")
+        .append(node.getSimpleArgName())           // parameter type, e.g. "Integer"
+        .append("\\n")
+        .append(node.getName())                    // short name, e.g. "NumberOfThreads"
+        .append(" = ")
+        .append(config.getNamedParameter(node))   // bound value, e.g. "16"
+        .append("\\n(default = ")
+        .append(instancesToString(node.getDefaultInstanceAsStrings())) // default value, e.g. "4"
+        .append(")\", shape=oval];\n");
+    return true;
+  }
+
+  private String instancesToString(String[] s) {
+    if (s.length == 0) {
+      return "null";
+    } else if (s.length == 1) {
+      return s[0];
+    } else {
+      StringBuffer sb = new StringBuffer("[" + s[0]);
+      for (int i = 1; i < s.length; i++) {
+        sb.append(",");
+        sb.append(s[i]);
+      }
+      sb.append("]");
+      return sb.toString();
+    }
+  }
+
+  /**
+   * Process current edge of the configuration graph.
+   *
+   * @param nodeFrom Current configuration node.
+   * @param nodeTo   Destination configuration node.
+   * @return true to proceed with the next node, false to cancel.
+   */
+  @Override
+  public boolean visit(final Node nodeFrom, final Node nodeTo) {
+    if (!nodeFrom.getName().isEmpty()) {
+      this.graphStr
+          .append("  ")
+          .append(nodeFrom.getName())
+          .append(" -> ")
+          .append(nodeTo.getName())
+          .append(" [style=solid, dir=back, arrowtail=diamond];\n");
+    }
+    return true;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/graphviz/GraphvizInjectionPlanVisitor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/graphviz/GraphvizInjectionPlanVisitor.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/graphviz/GraphvizInjectionPlanVisitor.java
new file mode 100644
index 0000000..2c5f785
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/graphviz/GraphvizInjectionPlanVisitor.java
@@ -0,0 +1,168 @@
+/**
+ * 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.reef.tang.util.walk.graphviz;
+
+import org.apache.reef.tang.implementation.Constructor;
+import org.apache.reef.tang.implementation.InjectionPlan;
+import org.apache.reef.tang.implementation.Subplan;
+import org.apache.reef.tang.implementation.java.JavaInstance;
+import org.apache.reef.tang.util.walk.AbstractInjectionPlanNodeVisitor;
+import org.apache.reef.tang.util.walk.EdgeVisitor;
+import org.apache.reef.tang.util.walk.Walk;
+
+/**
+ * Build a Graphviz representation of the injection plan graph.
+ */
+public final class GraphvizInjectionPlanVisitor
+    extends AbstractInjectionPlanNodeVisitor implements EdgeVisitor<InjectionPlan<?>> {
+  /**
+   * Legend for the configuration graph in Graphviz format
+   */
+  private static final String LEGEND =
+      "  subgraph cluster_legend {\n"
+          + "    shape=box;\n"
+          + "    label=\"Legend\";\n"
+          + "    Constructor [shape=box];\n"
+          + "    JavaInstance [shape=box, style=bold];\n"
+          + "    Subplan [shape=oval, style=dashed];\n"
+          + "    RequiredSingleton [shape=box, style=filled];\n"
+          + "    Subplan -> Constructor -> RequiredSingleton -> JavaInstance [style=invis];\n"
+          + "  }\n";
+
+  /**
+   * Accumulate string representation of the graph here.
+   */
+  private final transient StringBuilder graphStr =
+      new StringBuilder("digraph InjectionPlanMain {\n");
+
+  /**
+   * Create a new visitor to build a graphviz string for the injection plan.
+   *
+   * @param aShowLegend if true, show legend on the graph.
+   */
+  public GraphvizInjectionPlanVisitor(final boolean showLegend) {
+    if (showLegend) {
+      this.graphStr.append(LEGEND);
+    }
+    this.graphStr.append("subgraph cluster_main {\n  style=invis;\n");
+  }
+
+  /**
+   * Produce a Graphviz DOT string for a given TANG injection plan.
+   *
+   * @param injectionPlan TANG injection plan.
+   * @param showLegend    if true, show legend on the graph.
+   * @return Injection plan represented as a string in Graphviz DOT format.
+   */
+  public static String getGraphvizString(
+      final InjectionPlan<?> injectionPlan, final boolean showLegend) {
+    final GraphvizInjectionPlanVisitor visitor = new GraphvizInjectionPlanVisitor(showLegend);
+    Walk.preorder(visitor, visitor, injectionPlan);
+    return visitor.toString();
+  }
+
+  /**
+   * Process current injection plan node of Constructor type.
+   *
+   * @param node Current injection plan node.
+   * @return true to proceed with the next node, false to cancel.
+   */
+  @Override
+  public boolean visit(final Constructor<?> node) {
+    this.graphStr
+        .append("  \"")
+        .append(node.getClass())
+        .append('_')
+        .append(node.getNode().getName())
+        .append("\" [label=\"")
+        .append(node.getNode().getName())
+        .append("\", shape=box];\n");
+    return true;
+  }
+
+  /**
+   * Process current injection plan node of JavaInstance type.
+   *
+   * @param node Current injection plan node.
+   * @return true to proceed with the next node, false to cancel.
+   */
+  @Override
+  public boolean visit(final JavaInstance<?> node) {
+    this.graphStr
+        .append("  \"")
+        .append(node.getClass())
+        .append('_')
+        .append(node.getNode().getName())
+        .append("\" [label=\"")
+        .append(node.getNode().getName())
+        .append(" = ")
+        .append(node.getInstanceAsString())
+        .append("\", shape=box, style=bold];\n");
+    return true;
+  }
+
+  /**
+   * Process current injection plan node of Subplan type.
+   *
+   * @param node Current injection plan node.
+   * @return true to proceed with the next node, false to cancel.
+   */
+  @Override
+  public boolean visit(final Subplan<?> node) {
+    this.graphStr
+        .append("  \"")
+        .append(node.getClass())
+        .append('_')
+        .append(node.getNode().getName())
+        .append("\" [label=\"")
+        .append(node.getNode().getName())
+        .append("\", shape=oval, style=dashed];\n");
+    return true;
+  }
+
+  /**
+   * Process current edge of the injection plan.
+   *
+   * @param nodeFrom Current injection plan node.
+   * @param nodeTo   Destination injection plan node.
+   * @return true to proceed with the next node, false to cancel.
+   */
+  @Override
+  public boolean visit(final InjectionPlan<?> nodeFrom, final InjectionPlan<?> nodeTo) {
+    this.graphStr
+        .append("  \"")
+        .append(nodeFrom.getClass())
+        .append('_')
+        .append(nodeFrom.getNode().getName())
+        .append("\" -> \"")
+        .append(nodeTo.getClass())
+        .append('_')
+        .append(nodeTo.getNode().getName())
+        .append("\" [style=solid];\n");
+    return true;
+  }
+
+  /**
+   * @return TANG injection plan represented as a Graphviz DOT string.
+   */
+  @Override
+  public String toString() {
+    return this.graphStr.toString() + "}}\n";
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/graphviz/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/graphviz/package-info.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/graphviz/package-info.java
new file mode 100644
index 0000000..f0cadb6
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/graphviz/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * produce Graphviz representation of TANG configuration graph and injection plan.
+ */
+package org.apache.reef.tang.util.walk.graphviz;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/package-info.java b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/package-info.java
new file mode 100644
index 0000000..9478e74
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/java/org/apache/reef/tang/util/walk/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Utility classes for configuration graph and injection plan traversal.
+ */
+package org.apache.reef.tang.util.walk;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/proto/.gitignore
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/proto/.gitignore b/lang/java/reef-tang/tang/src/main/proto/.gitignore
new file mode 100644
index 0000000..8143e15
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/proto/.gitignore
@@ -0,0 +1 @@
+*.cs

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/proto/class_hierarchy.proto
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/proto/class_hierarchy.proto b/lang/java/reef-tang/tang/src/main/proto/class_hierarchy.proto
new file mode 100644
index 0000000..d304b62
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/proto/class_hierarchy.proto
@@ -0,0 +1,167 @@
+// 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.
+option java_package = "org.apache.reef.tang.proto";
+option java_outer_classname = "ClassHierarchyProto";
+//option java_generic_services = true;
+//option java_generate_equals_and_hash = true;
+
+/*
+  Node is the abstract base type for all the data encoded in a class hierarchy.
+  It is represented as an (un)tagged union, so only one of the three optional
+  fields can be non-null. 
+ */
+message Node {
+  /*
+    The short name of this node (e.g., a class name without the enclosing
+    package, or a package name without the name of the enclosing package.
+   */
+  required string name = 1;
+  /*
+    For some languages it can be difficult to map from a list of nodes to
+    the correct short name, so for now, the full name is (redundantly)
+    encoded here.  In Java, the full name is a bunch of short names that
+    have been concatenated with "." and/or "$".
+   */
+  required string full_name = 2;
+  /*
+     Exactly one of the next three fields must be defined.  See below for
+     their documentation.
+   */
+  optional ClassNode class_node = 3;
+  optional NamedParameterNode named_parameter_node = 4;
+  optional PackageNode package_node = 5;
+  /*
+     Class hierarchy nodes are arranged in a tree that mirrors the language
+     namespaces / packages that contain class names (e.g., Java packages,
+     C++ namespaces).
+     
+     A NamedParameterNode cannot have any children.  A ClassNode can not have
+     any package nodes as children.  PackageNodes cannot have PackageNodes as
+     children.
+   */
+  repeated Node children = 6;
+}
+
+message ClassNode {
+  /*
+     Some classes cannot be injected for language-specific reasons.  For
+     example, Java's non-static inner classes need a reference to the outer
+     class in order to be instantiated.  Set this boolean to false if there
+     is some reason why Tang cannot possibly inject this class.
+   */
+  required bool is_injection_candidate = 1;
+  /*
+     This field will be set to true if this class is a Tang
+     ExternalConstructor implementation.
+     
+     If this is set to true, then some other class *must* contain this 
+     ClassNode's name in its impl_full_names field.
+   */
+  required bool is_external_constructor = 2;
+  /*
+     This field will be set to true if this class is annotated as a Tang
+     Unit.
+   */
+  required bool is_unit = 3;
+  /*
+     A list of all the constructors that are defined by this class and 
+     annotated to be injectable.
+   */
+  repeated ConstructorDef InjectableConstructors = 4;
+  /*
+     A list of all the other constructors (so that they can be registered
+     as legacy constructors if the configuration tells us to treat them
+     as though they were annotated with an Inject).
+   */
+  repeated ConstructorDef OtherConstructors = 5;
+  /*
+     A list of all the ClassNodes that implement this class, including
+     legacy constructors. 
+   */
+  repeated string impl_full_names = 6;
+  optional string default_implementation = 7;
+}
+
+message NamedParameterNode {
+  /*
+     The short name (Node.name) of the type of argument this node names.
+   */
+  required string simple_arg_class_name = 1;
+  /*
+     The full name (Node.full_name) of the type of argument that this node
+     names.
+   */
+  required string full_arg_class_name = 2;
+  required bool is_set = 3;
+  required bool is_list = 4;
+  /*
+     An optional human readable documentation string describing the purpose
+     of this NamedParameter.
+   */
+  optional string documentation = 5;
+  /*
+     A shorter name for this parameter.  This is used for command line
+     processing. (So utilities that see --short_name=xxx will set this
+     NamedParameter to "xxx", for example).  
+   */
+  optional string short_name = 6;
+  /*
+     Optional named parameters must specify default values.  This must be
+     a string encoding of that value.  In order for this to be valid, Tang
+     must be able to parse the default value.  This is achieved by looking
+     for a parser for the ClassNode associated with full_arg_class_name.
+     
+     By default, Tang knows how to parse Strings (it simply copies them
+     unchanged), class names for the language environment Tang is running
+     inside of, and primitive types, such as int and float.
+     
+     Parsers of other types must be explicitly registered by the code that
+     bootstraps Tang.
+   */
+  // calling this "default_instance" breaks protoc.
+  repeated string instance_default = 7;
+}
+
+message PackageNode {
+  /*
+     Intentionally left blank.  Packages don't have any interesting
+     attributes except their names and children.
+   */
+}
+
+message ConstructorDef {
+  /*
+     The full name of the class this constructor returns.
+   */
+  required string full_class_name = 1;
+  /*
+     A (potentially empty) list of arguments required by this constructor.
+   */
+  repeated ConstructorArg args = 2;
+}
+message ConstructorArg {
+  /*
+     The full name of the class that should be passed into this
+     constructor argument.
+   */
+  required string full_arg_class_name = 1;
+  /*
+     The named parameter (if any) that this argument is annotated with.
+   */
+  optional string named_parameter_name = 2;
+  required bool is_injection_future = 3;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/main/proto/injection_plan.proto
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/main/proto/injection_plan.proto b/lang/java/reef-tang/tang/src/main/proto/injection_plan.proto
new file mode 100644
index 0000000..9ca1a3d
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/main/proto/injection_plan.proto
@@ -0,0 +1,38 @@
+// 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.
+option java_package = "org.apache.reef.tang.proto";
+option java_outer_classname = "InjectionPlanProto";
+//option java_generic_services = true;
+//option java_generate_equals_and_hash = true;
+
+message InjectionPlan {
+  required string name = 1;
+  optional Constructor constructor = 2;
+  optional Instance instance = 3;
+  optional Subplan subplan = 4;
+}
+
+message Subplan {
+  optional sint32 selected_plan = 1;
+  repeated InjectionPlan plans = 2;
+}
+message Constructor {
+  repeated InjectionPlan args = 1;
+}
+message Instance {
+  required string value = 1;
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/ClassHierarchyDeserializationTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/ClassHierarchyDeserializationTest.java b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/ClassHierarchyDeserializationTest.java
new file mode 100644
index 0000000..1091ae4
--- /dev/null
+++ b/lang/java/reef-tang/tang/src/test/java/org/apache/reef/tang/ClassHierarchyDeserializationTest.java
@@ -0,0 +1,112 @@
+/**
+ * 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.reef.tang;
+
+import org.apache.reef.tang.exceptions.NameResolutionException;
+import org.apache.reef.tang.formats.AvroConfigurationSerializer;
+import org.apache.reef.tang.formats.ConfigurationSerializer;
+import org.apache.reef.tang.implementation.protobuf.ProtocolBufferClassHierarchy;
+import org.apache.reef.tang.proto.ClassHierarchyProto;
+import org.apache.reef.tang.types.NamedParameterNode;
+import org.apache.reef.tang.types.Node;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Set;
+
+/**
+ * Test case for class hierarchy deserialization.
+ */
+public class ClassHierarchyDeserializationTest {
+
+  @Test
+  public void testDeserializationForTasks() {
+    try (final InputStream chin = Thread.currentThread().getContextClassLoader()
+        .getResourceAsStream("Task.bin")) {
+      final ClassHierarchyProto.Node root = ClassHierarchyProto.Node.parseFrom(chin); // A
+      final ClassHierarchy ch = new ProtocolBufferClassHierarchy(root);
+      Node n1 = ch.getNode("Microsoft.Reef.Tasks.StreamTask1, Microsoft.Reef.Tasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
+      Assert.assertTrue(n1.getFullName().equals("Microsoft.Reef.Tasks.StreamTask1, Microsoft.Reef.Tasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"));
+
+      Node n2 = ch.getNode("Microsoft.Reef.Tasks.HelloTask, Microsoft.Reef.Tasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
+      Assert.assertTrue(n2.getFullName().equals("Microsoft.Reef.Tasks.HelloTask, Microsoft.Reef.Tasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"));
+
+      final ConfigurationBuilder taskConfigurationBuilder1 = Tang.Factory.getTang()
+          .newConfigurationBuilder(ch);
+
+      final ConfigurationBuilder taskConfigurationBuilder2 = Tang.Factory.getTang()
+          .newConfigurationBuilder(ch);
+    } catch (final IOException e) {
+      final String message = "Unable to load class hierarchy.";
+      throw new RuntimeException(message, e);
+    } catch (final NameResolutionException e) {
+      final String message = "Unable to get node from class hierarchy.";
+      throw new RuntimeException(message, e);
+    }
+  }
+
+  @Test
+  public void testDeserializationForEvent() {
+    try (final InputStream chin = Thread.currentThread().getContextClassLoader()
+        .getResourceAsStream("Event.bin")) {
+      final ClassHierarchyProto.Node root = ClassHierarchyProto.Node.parseFrom(chin);
+      final ClassHierarchy ch = new ProtocolBufferClassHierarchy(root);
+      final ConfigurationBuilder taskConfigurationBuilder = Tang.Factory.getTang()
+          .newConfigurationBuilder(ch);
+    } catch (final Exception e) {
+      final String message = "Unable to load class hierarchy.";
+      throw new RuntimeException(message, e);
+    }
+  }
+
+  @Test
+  //Test bindSetEntry(NamedParameterNode<Set<T>> iface, String impl) in ConfigurationBuilderImpl with deserialized class hierarchy
+  public void testBindSetEntryWithSetOfT() throws IOException {
+    final ClassHierarchy ns1 = Tang.Factory.getTang().getDefaultClassHierarchy();
+    ns1.getNode(SetOfClasses.class.getName());
+    final ClassHierarchy ns2 = new ProtocolBufferClassHierarchy(ProtocolBufferClassHierarchy.serialize(ns1));
+    final ConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder(ns2);
+
+    final NamedParameterNode<Set<Number>> n2 = (NamedParameterNode<Set<Number>>) ns1.getNode(SetOfClasses.class.getName());
+    final Node fn = ns1.getNode(Float.class.getName());
+    cb.bindSetEntry(n2, fn);
+
+    final ConfigurationSerializer serializer = new AvroConfigurationSerializer();
+    final Configuration c = serializer.fromString(serializer.toString(cb.build()), ns2);
+  }
+
+  @Test
+  //Test public <T> void bindParameter(NamedParameterNode<T> name, String value) in ConfigurationBuilderImpl with deserialized class hierarchy
+  public void testBindSetEntryWithSetOfString() throws IOException {
+    final ClassHierarchy ns1 = Tang.Factory.getTang().getDefaultClassHierarchy();
+    ns1.getNode(SetOfStrings.class.getName());
+    final ClassHierarchy ns2 = new ProtocolBufferClassHierarchy(ProtocolBufferClassHierarchy.serialize(ns1));
+    final ConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder(ns2);
+    cb.bindSetEntry(SetOfStrings.class.getName(), "four");
+    cb.bindSetEntry(SetOfStrings.class.getName(), "five");
+
+    final NamedParameterNode<Set<String>> n2 = (NamedParameterNode<Set<String>>) ns1.getNode(SetOfStrings.class.getName());
+    cb.bindSetEntry(n2, "six");
+
+    final ConfigurationSerializer serializer = new AvroConfigurationSerializer();
+    final Configuration c = serializer.fromString(serializer.toString(cb.build()), ns2);
+  }
+}


[50/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/pom.xml b/lang/java/pom.xml
new file mode 100644
index 0000000..cdbc73e
--- /dev/null
+++ b/lang/java/pom.xml
@@ -0,0 +1,656 @@
+<?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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+         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>
+    <groupId>org.apache.reef</groupId>
+    <version>0.11.0-incubating-SNAPSHOT</version>
+    <packaging>pom</packaging>
+    <name>REEF</name>
+    <artifactId>reef-project</artifactId>
+    <description>Retainable Evaluator Execution Framework</description>
+    <url>http://reef.incubator.apache.org</url>
+
+    <parent>
+        <groupId>org.apache</groupId>
+        <artifactId>apache</artifactId>
+        <version>16</version>
+    </parent>
+
+    <licenses>
+        <license>
+            <name>The Apache Software License, Version 2.0</name>
+            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+            <distribution>repo</distribution>
+        </license>
+    </licenses>
+
+    <properties>
+        <reef.conf.dir>${project.build.directory}/conf</reef.conf.dir>
+        <reef.log.dir>${project.build.directory}/log</reef.log.dir>
+        <bundle.snappy>false</bundle.snappy>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <hadoop.version>2.4.0</hadoop.version>
+        <avro.version>1.7.7</avro.version>
+        <jetty.version>6.1.26</jetty.version>
+        <jackson.version>1.9.13</jackson.version>
+    </properties>
+
+    <scm>
+        <connection>scm:git:git@github.com:apache/incubator-reef.git</connection>
+        <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/incubator-reef.git</developerConnection>
+        <url>scm:git:git@github.com:apache/incubator-reef.git</url>
+        <tag>HEAD</tag>
+    </scm>
+
+    <developers>
+    </developers>
+
+    <issueManagement>
+        <system>JIRA</system>
+        <url>https://issues.apache.org/jira/browse/REEF</url>
+    </issueManagement>
+
+    <mailingLists>
+        <mailingList>
+            <name>Dev Mailing List</name>
+            <post>dev@reef.incubator.apache.org</post>
+            <subscribe>dev-subscribe@reef.incubator.apache.org</subscribe>
+            <unsubscribe>dev-unsubscribe@reef.incubator.apache.org</unsubscribe>
+            <archive>http://mail-archives.apache.org/mod_mbox/incubator-reef-dev/</archive>
+        </mailingList>
+    </mailingLists>
+
+    <prerequisites>
+        <maven>3.0</maven>
+    </prerequisites>
+
+    <build>
+        <pluginManagement>
+            <plugins>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-compiler-plugin</artifactId>
+                    <version>3.1</version>
+                    <configuration>
+                        <source>1.7</source>
+                        <target>1.7</target>
+                        <showDeprecation>true</showDeprecation>
+                        <encoding>${project.build.sourceEncoding}</encoding>
+                    </configuration>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-surefire-plugin</artifactId>
+                    <version>2.17</version>
+                    <configuration>
+                        <systemProperties>
+                            <property>
+                                <name>org.apache.reef.runtime.local.folder</name>
+                                <value>${project.build.directory}</value>
+                            </property>
+                        </systemProperties>
+                    </configuration>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-site-plugin</artifactId>
+                    <version>3.4</version>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-deploy-plugin</artifactId>
+                    <version>2.8.2</version>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-install-plugin</artifactId>
+                    <version>2.5.2</version>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-clean-plugin</artifactId>
+                    <version>2.5</version>
+                </plugin>
+                <plugin>
+                    <artifactId>maven-antrun-plugin</artifactId>
+                    <version>1.7</version>
+                </plugin>
+                <plugin>
+                    <groupId>org.codehaus.mojo</groupId>
+                    <artifactId>build-helper-maven-plugin</artifactId>
+                    <version>1.9.1</version>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-resources-plugin</artifactId>
+                    <version>2.6</version>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-javadoc-plugin</artifactId>
+                    <version>2.10.1</version>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-assembly-plugin</artifactId>
+                    <version>2.4.1</version>
+                </plugin>
+                <plugin>
+                    <!-- Create the property $buildNumber holding the current Git revision -->
+                    <groupId>org.codehaus.mojo</groupId>
+                    <artifactId>buildnumber-maven-plugin</artifactId>
+                    <version>1.3</version>
+                    <executions>
+                        <execution>
+                            <phase>validate</phase>
+                            <goals>
+                                <goal>create</goal>
+                            </goals>
+                        </execution>
+                    </executions>
+                    <configuration>
+                        <doCheck>false</doCheck>
+                        <doUpdate>false</doUpdate>
+                    </configuration>
+                </plugin>
+                <plugin>
+                    <groupId>org.codehaus.mojo</groupId>
+                    <artifactId>exec-maven-plugin</artifactId>
+                    <version>1.3.2</version>
+                </plugin>
+                <plugin>
+                    <!-- Add the default metadata to any JAR created -->
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-jar-plugin</artifactId>
+                    <version>2.5</version>
+                    <configuration>
+                        <archive>
+                            <manifest>
+                                <!--<Implementation-Title>${project.name}</Implementation-Title>-->
+                                <!--<Implementation-Version>${project.version} ${buildNumber}</Implementation-Version>-->
+                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+                                <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
+
+                            </manifest>
+                        </archive>
+                    </configuration>
+                </plugin>
+                <plugin>
+                    <groupId>com.mycila.maven-license-plugin</groupId>
+                    <artifactId>maven-license-plugin</artifactId>
+                    <version>1.9.0</version>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-shade-plugin</artifactId>
+                    <version>2.3</version>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.avro</groupId>
+                    <artifactId>avro-maven-plugin</artifactId>
+                    <version>${avro.version}</version>
+                    <executions>
+                        <execution>
+                            <phase>generate-sources</phase>
+                            <goals>
+                                <goal>schema</goal>
+                            </goals>
+                            <configuration>
+                                <sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory>
+                                <outputDirectory>${project.basedir}/target/generated-sources/avro/</outputDirectory>
+                            </configuration>
+                        </execution>
+                    </executions>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-dependency-plugin</artifactId>
+                    <version>2.9</version>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.rat</groupId>
+                    <artifactId>apache-rat-plugin</artifactId>
+                    <version>0.11</version>
+                    <configuration>
+                        <excludes>
+                            <exclude>.gitattributes</exclude>
+                            <exclude>.gitignore</exclude>
+                            <exclude>.git/**</exclude>
+                            <exclude>.idea/**</exclude>
+                            <exclude>target/**</exclude>
+                            <exclude>README.*</exclude>
+                            <!-- The below are sometimes created during tests -->
+                            <exclude>REEF_LOCAL_RUNTIME/**</exclude>
+                        </excludes>
+                    </configuration>
+                </plugin>
+            </plugins>
+        </pluginManagement>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.7</source>
+                    <target>1.7</target>
+                    <showDeprecation>true</showDeprecation>
+                    <encoding>${project.build.sourceEncoding}</encoding>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>com.mycila.maven-license-plugin</groupId>
+                <artifactId>maven-license-plugin</artifactId>
+                <configuration>
+                    <header>LICENSE_HEADER.txt</header>
+                    <strictCheck>true</strictCheck>
+                    <excludes>
+                        <exclude>LICENSE.txt</exclude>
+                        <exclude>NOTICES.txt</exclude>
+                        <exclude>README.*</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-resources-plugin</artifactId>
+                <configuration>
+                    <encoding>${project.build.sourceEncoding}</encoding>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-javadoc-plugin</artifactId>
+                <configuration>
+                    <show>public</show>
+                    <linksource>true</linksource>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.rat</groupId>
+                <artifactId>apache-rat-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencyManagement>
+        <dependencies>
+            <!-- Tang and Wake -->
+            <dependency>
+                <groupId>${project.groupId}</groupId>
+                <artifactId>tang</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>${project.groupId}</groupId>
+                <artifactId>wake</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+
+            <!-- Testing -->
+            <dependency>
+                <groupId>${project.groupId}</groupId>
+                <artifactId>test-jar</artifactId>
+                <version>${project.version}</version>
+                <classifier>tests</classifier>
+            </dependency>
+            <dependency>
+                <groupId>junit</groupId>
+                <artifactId>junit</artifactId>
+                <version>4.11</version>
+                <scope>test</scope>
+            </dependency>
+            <dependency>
+                <groupId>org.mockito</groupId>
+                <artifactId>mockito-core</artifactId>
+                <version>1.9.5</version>
+                <scope>test</scope>
+            </dependency>
+            <dependency>
+                <groupId>org.mockito</groupId>
+                <artifactId>mockito-all</artifactId>
+                <version>1.9.5</version>
+            </dependency>
+
+            <!-- Protocol Buffers -->
+            <dependency>
+                <groupId>com.google.protobuf</groupId>
+                <artifactId>protobuf-java</artifactId>
+                <version>2.5.0</version>
+            </dependency>
+            <!-- End of Protocol Buffers -->
+
+            <!-- HADOOP -->
+            <dependency>
+                <groupId>org.apache.hadoop</groupId>
+                <artifactId>hadoop-common</artifactId>
+                <version>${hadoop.version}</version>
+                <scope>provided</scope>
+                <exclusions>
+                    <exclusion>
+                        <groupId>org.slf4j</groupId>
+                        <artifactId>slf4j-jcl</artifactId>
+                    </exclusion>
+                    <exclusion>
+                        <groupId>org.slf4j</groupId>
+                        <artifactId>slf4j-log4j12</artifactId>
+                    </exclusion>
+                </exclusions>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.hadoop</groupId>
+                <artifactId>hadoop-client</artifactId>
+                <version>${hadoop.version}</version>
+                <scope>provided</scope>
+                <exclusions>
+                    <exclusion>
+                        <groupId>org.slf4j</groupId>
+                        <artifactId>slf4j-jcl</artifactId>
+                    </exclusion>
+                    <exclusion>
+                        <groupId>org.slf4j</groupId>
+                        <artifactId>slf4j-log4j12</artifactId>
+                    </exclusion>
+                </exclusions>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.hadoop</groupId>
+                <artifactId>hadoop-yarn-common</artifactId>
+                <version>${hadoop.version}</version>
+                <scope>provided</scope>
+                <exclusions>
+                    <exclusion>
+                        <groupId>org.slf4j</groupId>
+                        <artifactId>slf4j-jcl</artifactId>
+                    </exclusion>
+                    <exclusion>
+                        <groupId>org.slf4j</groupId>
+                        <artifactId>slf4j-log4j12</artifactId>
+                    </exclusion>
+                </exclusions>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.hadoop</groupId>
+                <artifactId>hadoop-yarn</artifactId>
+                <version>${hadoop.version}</version>
+                <type>pom</type>
+                <scope>provided</scope>
+                <exclusions>
+                    <exclusion>
+                        <groupId>org.slf4j</groupId>
+                        <artifactId>slf4j-jcl</artifactId>
+                    </exclusion>
+                    <exclusion>
+                        <groupId>org.slf4j</groupId>
+                        <artifactId>slf4j-log4j12</artifactId>
+                    </exclusion>
+                </exclusions>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.hadoop</groupId>
+                <artifactId>hadoop-hdfs</artifactId>
+                <version>${hadoop.version}</version>
+                <scope>provided</scope>
+                <exclusions>
+                    <exclusion>
+                        <groupId>org.slf4j</groupId>
+                        <artifactId>slf4j-jcl</artifactId>
+                    </exclusion>
+                    <exclusion>
+                        <groupId>org.slf4j</groupId>
+                        <artifactId>slf4j-log4j12</artifactId>
+                    </exclusion>
+                </exclusions>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.hadoop</groupId>
+                <artifactId>hadoop-yarn-client</artifactId>
+                <version>${hadoop.version}</version>
+                <scope>provided</scope>
+                <exclusions>
+                    <exclusion>
+                        <groupId>org.slf4j</groupId>
+                        <artifactId>slf4j-jcl</artifactId>
+                    </exclusion>
+                    <exclusion>
+                        <groupId>org.slf4j</groupId>
+                        <artifactId>slf4j-log4j12</artifactId>
+                    </exclusion>
+                </exclusions>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.hadoop</groupId>
+                <artifactId>hadoop-minicluster</artifactId>
+                <version>${hadoop.version}</version>
+                <scope>provided</scope>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.hadoop</groupId>
+                <artifactId>hadoop-yarn-api</artifactId>
+                <version>${hadoop.version}</version>
+                <scope>provided</scope>
+                <exclusions>
+                    <exclusion>
+                        <groupId>org.slf4j</groupId>
+                        <artifactId>slf4j-jcl</artifactId>
+                    </exclusion>
+                    <exclusion>
+                        <groupId>org.slf4j</groupId>
+                        <artifactId>slf4j-log4j12</artifactId>
+                    </exclusion>
+                </exclusions>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.hadoop</groupId>
+                <artifactId>hadoop-mapreduce-client-core</artifactId>
+                <version>${hadoop.version}</version>
+                <scope>provided</scope>
+                <exclusions>
+                    <exclusion>
+                        <groupId>org.slf4j</groupId>
+                        <artifactId>slf4j-jcl</artifactId>
+                    </exclusion>
+                    <exclusion>
+                        <groupId>org.slf4j</groupId>
+                        <artifactId>slf4j-log4j12</artifactId>
+                    </exclusion>
+                </exclusions>
+            </dependency>
+            <!-- END OF HADOOP -->
+
+            <!-- Apache Commons -->
+            <dependency>
+                <groupId>commons-cli</groupId>
+                <artifactId>commons-cli</artifactId>
+                <version>1.2</version>
+            </dependency>
+            <dependency>
+                <groupId>commons-configuration</groupId>
+                <artifactId>commons-configuration</artifactId>
+                <version>1.10</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.commons</groupId>
+                <artifactId>commons-math3</artifactId>
+                <version>3.3</version>
+            </dependency>
+            <dependency>
+                <groupId>org.apache.commons</groupId>
+                <artifactId>commons-lang3</artifactId>
+                <version>3.3.2</version>
+            </dependency>
+            <!-- End of Apache Commons -->
+
+            <!-- AVRO -->
+            <dependency>
+                <groupId>org.apache.avro</groupId>
+                <artifactId>avro</artifactId>
+                <version>${avro.version}</version>
+            </dependency>
+            <!-- End of AVRO -->
+
+            <!-- JETTY -->
+            <dependency>
+                <groupId>org.mortbay.jetty</groupId>
+                <artifactId>jetty</artifactId>
+                <version>${jetty.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.mortbay.jetty</groupId>
+                <artifactId>jetty-util</artifactId>
+                <version>${jetty.version}</version>
+            </dependency>
+            <!-- End of JETTY -->
+            <dependency>
+                <groupId>net.jcip</groupId>
+                <artifactId>jcip-annotations</artifactId>
+                <version>1.0</version>
+            </dependency>
+
+            <!-- SLF4J -->
+            <dependency>
+                <groupId>org.slf4j</groupId>
+                <artifactId>slf4j-jdk14</artifactId>
+                <version>1.7.7</version>
+            </dependency>
+            <!-- End of SLF4J -->
+
+
+            <dependency>
+                <groupId>io.netty</groupId>
+                <artifactId>netty-all</artifactId>
+                <version>4.0.21.Final</version>
+            </dependency>
+
+            <dependency>
+                <groupId>cglib</groupId>
+                <artifactId>cglib</artifactId>
+                <version>3.1</version>
+            </dependency>
+
+            <dependency>
+                <groupId>javax.inject</groupId>
+                <artifactId>javax.inject</artifactId>
+                <version>1</version>
+            </dependency>
+
+            <dependency>
+                <groupId>org.reflections</groupId>
+                <artifactId>reflections</artifactId>
+                <version>0.9.9-RC1</version>
+            </dependency>
+
+            <!-- Microsoft Azure libraries -->
+            <dependency>
+                <groupId>com.microsoft.windowsazure.storage</groupId>
+                <artifactId>microsoft-windowsazure-storage-sdk</artifactId>
+                <version>0.5.0</version>
+            </dependency>
+            <!-- End of Microsoft Azure libraries -->
+
+            <!-- Apache HTTP components -->
+            <dependency>
+                <groupId>org.apache.httpcomponents</groupId>
+                <artifactId>httpclient</artifactId>
+                <version>4.3.4</version>
+            </dependency>
+            <!-- End of Apache HTTP components -->
+
+
+            <!-- Jackson -->
+            <dependency>
+                <groupId>org.codehaus.jackson</groupId>
+                <artifactId>jackson-mapper-asl</artifactId>
+                <version>${jackson.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.codehaus.jackson</groupId>
+                <artifactId>jackson-core-asl</artifactId>
+                <version>${jackson.version}</version>
+            </dependency>
+            <!-- End of Jackson -->
+
+            <dependency>
+                <groupId>org.apache.mesos</groupId>
+                <artifactId>mesos</artifactId>
+                <version>0.21.0</version>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <modules>
+        <module>reef-annotations</module>
+        <module>reef-bridge-project</module>
+        <module>reef-checkpoint</module>
+        <module>reef-common</module>
+        <module>reef-examples</module>
+        <module>reef-examples-clr</module>
+        <module>reef-examples-hdinsight</module>
+        <module>reef-io</module>
+        <module>reef-poison</module>
+        <module>reef-runtime-hdinsight</module>
+        <module>reef-runtime-local</module>
+        <module>reef-runtime-yarn</module>
+        <module>reef-runtime-mesos</module>
+        <module>reef-tang</module>
+        <module>reef-tests</module>
+        <module>reef-wake</module>
+        <module>reef-webserver</module>
+        <module>reef-utils-hadoop</module>
+        <module>reef-utils</module>
+    </modules>
+
+    <profiles>
+        <profile>
+            <id>log</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <configuration>
+                            <forkMode>pertest</forkMode>
+                            <systemProperties>
+                                <property>
+                                    <name>java.util.logging.config.class</name>
+                                    <value>org.apache.reef.util.logging.Config</value>
+                                </property>
+                            </systemProperties>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+        <profile>
+            <id>reef-bridge</id>
+            <activation>
+                <os>
+                    <name>Windows</name>
+                    <family>Windows</family>
+                </os>
+            </activation>
+            <modules>
+                <module>reef-bridge-project</module>
+            </modules>
+
+        </profile>
+    </profiles>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-annotations/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-annotations/pom.xml b/lang/java/reef-annotations/pom.xml
new file mode 100644
index 0000000..387312b
--- /dev/null
+++ b/lang/java/reef-annotations/pom.xml
@@ -0,0 +1,31 @@
+<?xml version="1.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.
+-->
+<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.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>reef-annotations</artifactId>
+    <name>REEF Annotations</name>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/Optional.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/Optional.java b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/Optional.java
new file mode 100644
index 0000000..e0f6329
--- /dev/null
+++ b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/Optional.java
@@ -0,0 +1,26 @@
+/**
+ * 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.reef.annotations;
+
+/**
+ * Indicates an optional interface: It doesn't have to be implemented or bound
+ * using TANG.
+ */
+public @interface Optional {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/Provided.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/Provided.java b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/Provided.java
new file mode 100644
index 0000000..f57d926
--- /dev/null
+++ b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/Provided.java
@@ -0,0 +1,26 @@
+/**
+ * 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.reef.annotations;
+
+/**
+ * Indicates that an implementation of the annotated class / interface will be
+ * provided by REEF at resourcemanager.
+ */
+public @interface Provided {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/Unstable.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/Unstable.java b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/Unstable.java
new file mode 100644
index 0000000..6374379
--- /dev/null
+++ b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/Unstable.java
@@ -0,0 +1,25 @@
+/**
+ * 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.reef.annotations;
+
+/**
+ * Indicates that the code annotated this way is unstable, both in terms of its APIs and its functionality.
+ */
+public @interface Unstable {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/ClientSide.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/ClientSide.java b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/ClientSide.java
new file mode 100644
index 0000000..afbf2ca
--- /dev/null
+++ b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/ClientSide.java
@@ -0,0 +1,26 @@
+/**
+ * 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.reef.annotations.audience;
+
+/**
+ * Annotates interface meant to be used by REEF clients.
+ */
+public @interface ClientSide {
+  // Intentionally empty
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/DriverSide.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/DriverSide.java b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/DriverSide.java
new file mode 100644
index 0000000..4036dd4
--- /dev/null
+++ b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/DriverSide.java
@@ -0,0 +1,26 @@
+/**
+ * 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.reef.annotations.audience;
+
+/**
+ * Annotates interfaces that are meant to be used in the Job Driver.
+ */
+public @interface DriverSide {
+  // Intentionally empty
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/EvaluatorSide.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/EvaluatorSide.java b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/EvaluatorSide.java
new file mode 100644
index 0000000..5ace0df
--- /dev/null
+++ b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/EvaluatorSide.java
@@ -0,0 +1,25 @@
+/**
+ * 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.reef.annotations.audience;
+
+/**
+ * Annotates interfaces meant to be used by Evaluators.
+ */
+public @interface EvaluatorSide {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/Private.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/Private.java b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/Private.java
new file mode 100644
index 0000000..a9e6d38
--- /dev/null
+++ b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/Private.java
@@ -0,0 +1,26 @@
+/**
+ * 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.reef.annotations.audience;
+
+/**
+ * Annotates code that is meant to be private to the project it is in.
+ */
+public @interface Private {
+  // Intentionally empty
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/Public.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/Public.java b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/Public.java
new file mode 100644
index 0000000..1ab8192
--- /dev/null
+++ b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/Public.java
@@ -0,0 +1,26 @@
+/**
+ * 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.reef.annotations.audience;
+
+/**
+ * Annotates code for public consumption.
+ */
+public @interface Public {
+  // Intentionally empty
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/RuntimeAuthor.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/RuntimeAuthor.java b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/RuntimeAuthor.java
new file mode 100644
index 0000000..c3e8143
--- /dev/null
+++ b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/RuntimeAuthor.java
@@ -0,0 +1,26 @@
+/**
+ * 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.reef.annotations.audience;
+
+/**
+ * Indicates that an interface or API to be consumed or used by authors of
+ * additional REEF runtimes, not authors of REEF jobs.
+ */
+public @interface RuntimeAuthor {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/TaskSide.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/TaskSide.java b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/TaskSide.java
new file mode 100644
index 0000000..792024a
--- /dev/null
+++ b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/TaskSide.java
@@ -0,0 +1,26 @@
+/**
+ * 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.reef.annotations.audience;
+
+/**
+ * Annotates interfaces meant to be used by Tasks.
+ */
+public @interface TaskSide {
+  // Intentionally empty
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/package-info.java b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/package-info.java
new file mode 100644
index 0000000..7a88388
--- /dev/null
+++ b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/audience/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Annotations for interface audience
+ */
+package org.apache.reef.annotations.audience;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/package-info.java b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/package-info.java
new file mode 100644
index 0000000..cbc0940
--- /dev/null
+++ b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Annotations used to identify interface stability and audience.
+ */
+package org.apache.reef.annotations;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/semantics/Idempotent.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/semantics/Idempotent.java b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/semantics/Idempotent.java
new file mode 100644
index 0000000..fa71b95
--- /dev/null
+++ b/lang/java/reef-annotations/src/main/java/org/apache/reef/annotations/semantics/Idempotent.java
@@ -0,0 +1,25 @@
+/**
+ * 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.reef.annotations.semantics;
+
+/**
+ * Methods annotated with this are idempotent: Calling them multiple times has the same effect as calling them once.
+ */
+public @interface Idempotent {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/.gitignore
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/.gitignore b/lang/java/reef-bridge-project/.gitignore
new file mode 100644
index 0000000..dd32f71
--- /dev/null
+++ b/lang/java/reef-bridge-project/.gitignore
@@ -0,0 +1,34 @@
+ml-data
+tmp
+tang.conf
+.DS_Store
+target
+generated
+build
+.settings
+.classpath
+.project
+*.sw[op]
+.externalToolBuilders
+nbactions*.xml
+nb-configuration.xml
+*~
+\#*
+*.iml
+.idea
+atlassian-ide-plugin.xml
+REEF_LOCAL_RUNTIME
+profile-*.json
+.obj
+.dll
+.class
+.tlog
+dotnetHello
+lib
+x64
+*.sdf
+*.suo
+*.opensdf
+obj
+*.cache
+*.log

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/pom.xml b/lang/java/reef-bridge-project/pom.xml
new file mode 100644
index 0000000..3e8dde5
--- /dev/null
+++ b/lang/java/reef-bridge-project/pom.xml
@@ -0,0 +1,101 @@
+<?xml version="1.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.
+-->
+<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>
+    <artifactId>reef-bridge-project</artifactId>
+    <name>REEF Bridge Project</name>
+    <description>Bridge between JVM and CLR.</description>
+    <packaging>pom</packaging>
+
+
+    <parent>
+        <groupId>org.apache.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-local</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-yarn</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-io</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-checkpoint</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+    <modules>
+        <module>reef-bridge-java</module>
+        <module>reef-bridge-clr</module>
+        <module>reef-bridge</module>
+    </modules>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-shade-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>shade</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <outputFile>
+                        ${project.build.directory}/${project.artifactId}-${project.version}-shaded.jar
+                    </outputFile>
+                    <filters>
+                        <filter>
+                            <artifact>*:*</artifact>
+                            <excludes>
+                                <exclude>yarn-default.xml</exclude>
+                                <exclude>yarn-version-info.properties</exclude>
+                                <exclude>core-default.xml</exclude>
+                                <exclude>LICENSE</exclude>
+                                <exclude>META-INF/*</exclude>
+                            </excludes>
+                        </filter>
+                    </filters>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/pom.xml b/lang/java/reef-bridge-project/reef-bridge-clr/pom.xml
new file mode 100644
index 0000000..4d15a4b
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/pom.xml
@@ -0,0 +1,162 @@
+<?xml version="1.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.
+-->
+<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>
+    <artifactId>reef-bridge-clr</artifactId>
+    <name>REEF Bridge CLR</name>
+    <description>Bridge between JVM and CLR.</description>
+
+
+    <parent>
+        <groupId>org.apache.reef</groupId>
+        <artifactId>reef-bridge-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-local</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-runtime-yarn</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-io</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-checkpoint</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-bridge-java</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.avro</groupId>
+            <artifactId>avro</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.rat</groupId>
+                <artifactId>apache-rat-plugin</artifactId>
+                <configuration>
+                    <excludes>
+                        <!-- Build files are frequently overwritten by Visual Studio -->
+                        <exclude>src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.sln</exclude>
+                        <exclude>src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.vcxproj</exclude>
+                        <exclude>src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.vcxproj.filters</exclude>
+                        <exclude>src/main/CSharp/CSharp/ClrHandler/ClrHandler.csproj</exclude>
+                        <!--End of Visual Studio build files-->
+                    </excludes>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <profiles>
+        <profile>
+            <id>Bridge</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <configuration>
+                            <executable>msbuild.exe</executable>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <id>clean</id>
+                                <phase>clean</phase>
+                                <configuration>
+                                    <arguments>
+                                        <argument>
+                                            ${project.basedir}/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.sln
+                                        </argument>
+                                        <argument>/p:Configuration="Release"</argument>
+                                        <argument>/p:Platform="x64"</argument>
+                                        <argument>/t:Clean</argument>
+                                    </arguments>
+                                </configuration>
+                                <goals>
+                                    <goal>exec</goal>
+                                </goals>
+                            </execution>
+                            <execution>
+                                <id>build</id>
+                                <phase>compile</phase>
+                                <configuration>
+                                    <arguments>
+                                        <argument>
+                                            ${project.basedir}/src/main/Cpp/CppBridge/JavaClrBridge/JavaClrBridge.sln
+                                        </argument>
+                                        <argument>/p:Configuration="Release"</argument>
+                                        <argument>/p:Platform="x64"</argument>
+                                    </arguments>
+                                </configuration>
+                                <goals>
+                                    <goal>exec</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <artifactId>maven-resources-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <id>copy-external-dlls</id>
+                                <phase>process-resources</phase>
+                                <goals>
+                                    <goal>copy-resources</goal>
+                                </goals>
+                                <configuration>
+                                    <overwrite>true</overwrite>
+                                    <outputDirectory>${basedir}/target/classes</outputDirectory>
+                                    <resources>
+                                        <resource>
+                                            <directory>src/main/CSharp/CSharp/ClrHandler/externals</directory>
+                                        </resource>
+                                    </resources>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/ClrHandler.csproj
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/ClrHandler.csproj b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/ClrHandler.csproj
new file mode 100644
index 0000000..952dd0d
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/ClrHandler.csproj
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{443A7B61-5C91-4F67-9FCD-81BC6FABFDBD}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>ClrHandler</RootNamespace>
+    <AssemblyName>ClrHandler</AssemblyName>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>..\..\..\..\..\target\classes\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>..\..\..\..\..\target\classes\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup>
+    <SignAssembly>false</SignAssembly>
+  </PropertyGroup>
+  <PropertyGroup>
+    <AssemblyOriginatorKeyFile>
+    </AssemblyOriginatorKeyFile>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="Microsoft.Reef.Driver">
+      <HintPath>externals\Microsoft.Reef.Driver.dll</HintPath>
+      <Private>true</Private>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Runtime.Serialization" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="interface\ILogger.cs" />
+    <Compile Include="interface\IInteropReturnInfo.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/Properties/AssemblyInfo.cs
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/Properties/AssemblyInfo.cs b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..5812e03
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/Properties/AssemblyInfo.cs
@@ -0,0 +1,49 @@
+/**
+ * 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.Reflection;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("ClrHandler")]
+[assembly: AssemblyDescription("The interface dll between CPP and CLR code")]
+[assembly: AssemblyProduct("ClrHandler")]
+[assembly: AssemblyCopyright("Copyright ©  2014")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("3efe4d3c-087b-4076-b331-8f3e36c10016")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/externals/Microsoft.Reef.Driver.dll
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/externals/Microsoft.Reef.Driver.dll b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/externals/Microsoft.Reef.Driver.dll
new file mode 100644
index 0000000..d95a8c7
Binary files /dev/null and b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/externals/Microsoft.Reef.Driver.dll differ

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/externals/msvcr110.dll
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/externals/msvcr110.dll b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/externals/msvcr110.dll
new file mode 100644
index 0000000..dd484a5
Binary files /dev/null and b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/externals/msvcr110.dll differ

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/interface/IInteropReturnInfo.cs
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/interface/IInteropReturnInfo.cs b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/interface/IInteropReturnInfo.cs
new file mode 100644
index 0000000..b3b930a
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/interface/IInteropReturnInfo.cs
@@ -0,0 +1,30 @@
+/**
+ * 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;
+
+namespace Microsoft.Reef.Interop
+{
+    public interface IInteropReturnInfo
+    {
+        void AddExceptionString(String exceptionString);       
+        Boolean HasExceptions();
+        void SetReturnCode(int rc);
+        int GetReturnCode();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/interface/ILogger.cs
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/interface/ILogger.cs b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/interface/ILogger.cs
new file mode 100644
index 0000000..4a7f9b2
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/CSharp/CSharp/ClrHandler/interface/ILogger.cs
@@ -0,0 +1,37 @@
+/**
+ * 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;
+
+namespace Microsoft.Reef.Interop
+{
+    public enum TraceLevel : int
+    {
+        NoTrace = Int32.MaxValue,
+
+        Error = 1000,
+        Warning = 900,
+        Info = 800,
+        Verbose = 300, 
+    }
+
+    public interface ILogger
+    {
+        void Log(TraceLevel traceLevel, String message);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ActiveContextClr2Java.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ActiveContextClr2Java.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ActiveContextClr2Java.cpp
new file mode 100644
index 0000000..fc04b06
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/ActiveContextClr2Java.cpp
@@ -0,0 +1,106 @@
+/**
+ * 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.
+ */
+#include "Clr2JavaImpl.h"
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Driver {
+      namespace Bridge {
+        private ref class ManagedLog {
+          internal:
+            static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>");
+        };
+
+        ActiveContextClr2Java::ActiveContextClr2Java(JNIEnv *env, jobject jobjectActiveContext) {
+          ManagedLog::LOGGER->LogStart("ActiveContextClr2Java::ActiveContextClr2Java");
+          pin_ptr<JavaVM*> pJavaVm = &_jvm;
+          if (env->GetJavaVM(pJavaVm) != 0) {
+            ManagedLog::LOGGER->LogError("Failed to get JavaVM", nullptr);
+          }
+
+          _jobjectActiveContext = reinterpret_cast<jobject>(env->NewGlobalRef(jobjectActiveContext));
+
+          jclass jclassActiveContext = env->GetObjectClass(_jobjectActiveContext);
+
+          jfieldID jidContextId = env->GetFieldID(jclassActiveContext, "contextId", "Ljava/lang/String;");
+          _jstringId = reinterpret_cast<jstring>(env->NewGlobalRef(env->GetObjectField(_jobjectActiveContext, jidContextId)));
+
+          jfieldID jidEvaluatorId = env->GetFieldID(jclassActiveContext, "evaluatorId", "Ljava/lang/String;");
+          _jstringEvaluatorId = (jstring)env->GetObjectField(_jobjectActiveContext, jidEvaluatorId);
+          _jstringEvaluatorId = reinterpret_cast<jstring>(env->NewGlobalRef(_jstringEvaluatorId));
+
+          ManagedLog::LOGGER->LogStop("ActiveContextClr2Java::ActiveContextClr2Java");
+        }
+
+        void ActiveContextClr2Java::SubmitTask(String^ taskConfigStr) {
+          ManagedLog::LOGGER->LogStart("ActiveContextClr2Java::SubmitTask");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          jclass jclassActiveContext = env->GetObjectClass (_jobjectActiveContext);
+          jmethodID jmidSubmitTask = env->GetMethodID(jclassActiveContext, "submitTaskString", "(Ljava/lang/String;)V");
+
+          if (jmidSubmitTask == NULL) {
+            ManagedLog::LOGGER->Log("jmidSubmitTask is NULL");
+            return;
+          }
+          env -> CallObjectMethod(
+            _jobjectActiveContext,
+            jmidSubmitTask,
+            JavaStringFromManagedString(env, taskConfigStr));
+          ManagedLog::LOGGER->LogStop("ActiveContextClr2Java::SubmitTask");
+        }
+
+        void ActiveContextClr2Java::OnError(String^ message) {
+          JNIEnv *env = RetrieveEnv(_jvm);
+          HandleClr2JavaError(env, message, _jobjectActiveContext);
+        }
+
+        void ActiveContextClr2Java::Close() {
+          ManagedLog::LOGGER->LogStart("ActiveContextClr2Java::Close");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          jclass jclassActiveContext = env->GetObjectClass (_jobjectActiveContext);
+          jmethodID jmidClose = env->GetMethodID(jclassActiveContext, "close", "()V");
+
+          if (jmidClose == NULL) {
+            ManagedLog::LOGGER->Log("jmidClose is NULL");
+            return;
+          }
+          env -> CallObjectMethod(
+            _jobjectActiveContext,
+            jmidClose);
+          ManagedLog::LOGGER->LogStop("ActiveContextClr2Java::Close");
+        }
+
+        String^ ActiveContextClr2Java::GetId() {
+          JNIEnv *env = RetrieveEnv(_jvm);
+          return ManagedStringFromJavaString(env, _jstringId);
+        }
+
+        String^ ActiveContextClr2Java::GetEvaluatorId() {
+          JNIEnv *env = RetrieveEnv(_jvm);
+          return ManagedStringFromJavaString(env, _jstringEvaluatorId);
+        }
+
+        IEvaluatorDescriptor^ ActiveContextClr2Java::GetEvaluatorDescriptor() {
+          ManagedLog::LOGGER->LogStart("ActiveContextClr2Java::GetEvaluatorDescriptor");
+          return CommonUtilities::RetrieveEvaluatorDescriptor(_jobjectActiveContext, _jvm);
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/AllocatedEvaluatorClr2Java.cpp
----------------------------------------------------------------------
diff --git a/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/AllocatedEvaluatorClr2Java.cpp b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/AllocatedEvaluatorClr2Java.cpp
new file mode 100644
index 0000000..11e8a80
--- /dev/null
+++ b/lang/java/reef-bridge-project/reef-bridge-clr/src/main/Cpp/CppBridge/JavaClrBridge/AllocatedEvaluatorClr2Java.cpp
@@ -0,0 +1,164 @@
+/**
+ * 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.
+ */
+#include "Clr2JavaImpl.h"
+
+using namespace JavaClrBridge;
+
+namespace Microsoft {
+  namespace Reef {
+    namespace Driver {
+      namespace Bridge {
+        ref class ManagedLog {
+          internal:
+            static BridgeLogger^ LOGGER = BridgeLogger::GetLogger("<C++>");
+        };
+
+        AllocatedEvaluatorClr2Java::AllocatedEvaluatorClr2Java(JNIEnv *env, jobject jallocatedEvaluator) {
+
+          ManagedLog::LOGGER->LogStart("AllocatedEvaluatorClr2Java::AllocatedEvaluatorClr2Java");
+
+          pin_ptr<JavaVM*> pJavaVm = &_jvm;
+          if (env->GetJavaVM(pJavaVm) != 0) {
+            ManagedLog::LOGGER->LogError("Failed to get JavaVM", nullptr);
+          }
+          _jobjectAllocatedEvaluator = reinterpret_cast<jobject>(env->NewGlobalRef(jallocatedEvaluator));
+
+          jclass jclassAllocatedEvaluator = env->GetObjectClass (_jobjectAllocatedEvaluator);
+          jfieldID jidEvaluatorId = env->GetFieldID(jclassAllocatedEvaluator, "evaluatorId", "Ljava/lang/String;");
+          _jstringId = reinterpret_cast<jstring>(env->NewGlobalRef(env->GetObjectField(_jobjectAllocatedEvaluator, jidEvaluatorId)));
+
+          jfieldID jidNameServerInfo = env->GetFieldID(jclassAllocatedEvaluator, "nameServerInfo", "Ljava/lang/String;");
+          _jstringNameServerInfo = reinterpret_cast<jstring>(env->NewGlobalRef(env->GetObjectField(_jobjectAllocatedEvaluator, jidNameServerInfo)));
+
+          ManagedLog::LOGGER->LogStop("AllocatedEvaluatorClr2Java::AllocatedEvaluatorClr2Java");
+        }
+
+        void AllocatedEvaluatorClr2Java::SubmitContext(String^ contextConfigStr) {
+          ManagedLog::LOGGER->LogStart("AllocatedEvaluatorClr2Java::SubmitContext");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          jclass jclassAllocatedEvaluator = env->GetObjectClass (_jobjectAllocatedEvaluator);
+          jmethodID jmidSubmitContext = env->GetMethodID(jclassAllocatedEvaluator, "submitContextString", "(Ljava/lang/String;)V");
+
+          if (jmidSubmitContext == NULL) {
+            ManagedLog::LOGGER->Log("jmidSubmitContext is NULL");
+            return;
+          }
+          env -> CallObjectMethod(
+            _jobjectAllocatedEvaluator,
+            jmidSubmitContext,
+            JavaStringFromManagedString(env, contextConfigStr));
+          ManagedLog::LOGGER->LogStop("AllocatedEvaluatorClr2Java::SubmitContext");
+        }
+
+        void AllocatedEvaluatorClr2Java::SubmitContextAndTask(String^ contextConfigStr, String^ taskConfigStr) {
+          ManagedLog::LOGGER->LogStart("AllocatedEvaluatorClr2Java::SubmitContextAndTask");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          jclass jclassAllocatedEvaluator = env->GetObjectClass (_jobjectAllocatedEvaluator);
+          jmethodID jmidSubmitContextAndTask = env->GetMethodID(jclassAllocatedEvaluator, "submitContextAndTaskString", "(Ljava/lang/String;Ljava/lang/String;)V");
+
+          if (jmidSubmitContextAndTask == NULL) {
+            ManagedLog::LOGGER->Log("jmidSubmitContextAndTask is NULL");
+            return;
+          }
+          env -> CallObjectMethod(
+            _jobjectAllocatedEvaluator,
+            jmidSubmitContextAndTask,
+            JavaStringFromManagedString(env, contextConfigStr),
+            JavaStringFromManagedString(env, taskConfigStr));
+          ManagedLog::LOGGER->LogStop("AllocatedEvaluatorClr2Java::SubmitContextAndTask");
+        }
+
+        void AllocatedEvaluatorClr2Java::SubmitContextAndService(String^ contextConfigStr, String^ serviceConfigStr) {
+          ManagedLog::LOGGER->LogStart("AllocatedEvaluatorClr2Java::SubmitContextAndService");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          jclass jclassAllocatedEvaluator = env->GetObjectClass (_jobjectAllocatedEvaluator);
+          jmethodID jmidSubmitContextAndService = env->GetMethodID(jclassAllocatedEvaluator, "submitContextAndServiceString", "(Ljava/lang/String;Ljava/lang/String;)V");
+
+          if (jmidSubmitContextAndService == NULL) {
+            ManagedLog::LOGGER->Log("jmidSubmitContextAndService is NULL");
+            return;
+          }
+          env -> CallObjectMethod(
+            _jobjectAllocatedEvaluator,
+            jmidSubmitContextAndService,
+            JavaStringFromManagedString(env, contextConfigStr),
+            JavaStringFromManagedString(env, serviceConfigStr));
+          ManagedLog::LOGGER->LogStop("AllocatedEvaluatorClr2Java::SubmitContextAndService");
+        }
+
+        void AllocatedEvaluatorClr2Java::SubmitContextAndServiceAndTask(String^ contextConfigStr, String^ serviceConfigStr, String^ taskConfigStr) {
+          ManagedLog::LOGGER->LogStart("AllocatedEvaluatorClr2Java::SubmitContextAndServiceAndTask");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          jclass jclassAllocatedEvaluator = env->GetObjectClass (_jobjectAllocatedEvaluator);
+          jmethodID jmidSubmitContextAndServiceAndTask = env->GetMethodID(jclassAllocatedEvaluator, "submitContextAndServiceAndTaskString", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
+
+          if (jmidSubmitContextAndServiceAndTask == NULL) {
+            ManagedLog::LOGGER->Log("jmidSubmitContextAndServiceAndTask is NULL");
+            return;
+          }
+          env -> CallObjectMethod(
+            _jobjectAllocatedEvaluator,
+            jmidSubmitContextAndServiceAndTask,
+            JavaStringFromManagedString(env, contextConfigStr),
+            JavaStringFromManagedString(env, serviceConfigStr),
+            JavaStringFromManagedString(env, taskConfigStr));
+          ManagedLog::LOGGER->LogStop("AllocatedEvaluatorClr2Java::SubmitContextAndServiceAndTask");
+        }
+
+        void AllocatedEvaluatorClr2Java::OnError(String^ message) {
+          JNIEnv *env = RetrieveEnv(_jvm);
+          HandleClr2JavaError(env, message, _jobjectAllocatedEvaluator);
+        }
+
+        void AllocatedEvaluatorClr2Java::Close() {
+          ManagedLog::LOGGER->LogStart("AllocatedEvaluatorClr2Java::Close");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          jclass jclassAllocatedEvaluator = env->GetObjectClass (_jobjectAllocatedEvaluator);
+          jmethodID jmidClose = env->GetMethodID(jclassAllocatedEvaluator, "close", "()V");
+
+          if (jmidClose == NULL) {
+            ManagedLog::LOGGER->Log("jmidClose is NULL");
+            return;
+          }
+          env -> CallObjectMethod(
+            _jobjectAllocatedEvaluator,
+            jmidClose);
+          ManagedLog::LOGGER->LogStop("AllocatedEvaluatorClr2Java::Close");
+        }
+
+        String^ AllocatedEvaluatorClr2Java::GetId() {
+          ManagedLog::LOGGER->Log("AllocatedEvaluatorClr2Java::GetId");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          return ManagedStringFromJavaString(env, _jstringId);
+        }
+
+        String^ AllocatedEvaluatorClr2Java::GetNameServerInfo() {
+          ManagedLog::LOGGER->Log("AllocatedEvaluatorClr2Java::GetNameServerInfo");
+          JNIEnv *env = RetrieveEnv(_jvm);
+          return ManagedStringFromJavaString(env, _jstringNameServerInfo);
+        }
+
+        IEvaluatorDescriptor^ AllocatedEvaluatorClr2Java::GetEvaluatorDescriptor() {
+          ManagedLog::LOGGER->LogStart("AllocatedEvaluatorClr2Java::GetEvaluatorDescriptor");
+          return CommonUtilities::RetrieveEvaluatorDescriptor(_jobjectAllocatedEvaluator, _jvm);
+        }
+      }
+    }
+  }
+}
\ No newline at end of file


[37/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/FailedEvaluatorImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/FailedEvaluatorImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/FailedEvaluatorImpl.java
new file mode 100644
index 0000000..450e8e5
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/FailedEvaluatorImpl.java
@@ -0,0 +1,73 @@
+/**
+ * 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.reef.runtime.common.driver.evaluator;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.driver.evaluator.FailedEvaluator;
+import org.apache.reef.driver.task.FailedTask;
+import org.apache.reef.exception.EvaluatorException;
+import org.apache.reef.util.Optional;
+
+import java.util.List;
+
+@DriverSide
+@Private
+final class FailedEvaluatorImpl implements FailedEvaluator {
+
+  final String id;
+  private final EvaluatorException ex;
+  private final List<FailedContext> ctx;
+  private final Optional<FailedTask> task;
+
+  public FailedEvaluatorImpl(final EvaluatorException ex, final List<FailedContext> ctx, final Optional<FailedTask> task, final String id) {
+    this.ex = ex;
+    this.ctx = ctx;
+    this.task = task;
+    this.id = id;
+  }
+
+  @Override
+  public EvaluatorException getEvaluatorException() {
+    return this.ex;
+  }
+
+  @Override
+  public List<FailedContext> getFailedContextList() {
+    return this.ctx;
+  }
+
+  @Override
+  public Optional<FailedTask> getFailedTask() {
+    return this.task;
+  }
+
+  @Override
+  public String getId() {
+    return this.id;
+  }
+
+  @Override
+  public String toString() {
+    return "FailedEvaluator{" +
+        "id='" + id + '\'' +
+        '}';
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/package-info.java
new file mode 100644
index 0000000..7d6deee
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/evaluator/package-info.java
@@ -0,0 +1,26 @@
+/**
+ * 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.
+ */
+/**
+ * Driver-Side representations of Evaluators.
+ */
+@DriverSide
+@Private package org.apache.reef.runtime.common.driver.evaluator;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/ClockIdlenessSource.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/ClockIdlenessSource.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/ClockIdlenessSource.java
new file mode 100644
index 0000000..460f5a4
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/ClockIdlenessSource.java
@@ -0,0 +1,60 @@
+/**
+ * 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.reef.runtime.common.driver.idle;
+
+import org.apache.reef.tang.InjectionFuture;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.runtime.event.IdleClock;
+
+import javax.inject.Inject;
+
+/**
+ * Informs the DriverIdleManager of clock idleness.
+ */
+public final class ClockIdlenessSource implements DriverIdlenessSource, EventHandler<IdleClock> {
+  private static final String COMPONENT_NAME = "Clock";
+  private static final String IDLE_REASON = "The clock reported idle.";
+  private static final IdleMessage IDLE_MESSAGE = new IdleMessage(COMPONENT_NAME, IDLE_REASON, true);
+  private static final String NOT_IDLE_REASON = "The clock reported not idle.";
+  private static final IdleMessage NOT_IDLE_MESSAGE = new IdleMessage(COMPONENT_NAME, NOT_IDLE_REASON, false);
+
+  private final InjectionFuture<DriverIdleManager> driverIdleManager;
+  private final Clock clock;
+
+  @Inject
+  ClockIdlenessSource(final InjectionFuture<DriverIdleManager> driverIdleManager, final Clock clock) {
+    this.driverIdleManager = driverIdleManager;
+    this.clock = clock;
+  }
+
+  @Override
+  public synchronized IdleMessage getIdleStatus() {
+    if (this.clock.isIdle()) {
+      return IDLE_MESSAGE;
+    } else {
+      return NOT_IDLE_MESSAGE;
+    }
+  }
+
+  @Override
+  public synchronized void onNext(final IdleClock idleClock) {
+    this.driverIdleManager.get().onPotentiallyIdle(IDLE_MESSAGE);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/DriverIdleManager.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/DriverIdleManager.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/DriverIdleManager.java
new file mode 100644
index 0000000..79d4d8c
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/DriverIdleManager.java
@@ -0,0 +1,73 @@
+/**
+ * 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.reef.runtime.common.driver.idle;
+
+import org.apache.reef.driver.parameters.DriverIdleSources;
+import org.apache.reef.runtime.common.driver.DriverStatusManager;
+import org.apache.reef.tang.InjectionFuture;
+import org.apache.reef.tang.annotations.Parameter;
+
+import javax.inject.Inject;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Handles the various sources for driver idleness and forwards decisions to DriverStatusManager.
+ */
+public final class DriverIdleManager {
+  private static final Logger LOG = Logger.getLogger(DriverIdleManager.class.getName());
+  private static final Level IDLE_REASONS_LEVEL = Level.FINEST;
+  private final Set<DriverIdlenessSource> idlenessSources;
+  private final InjectionFuture<DriverStatusManager> driverStatusManager;
+
+  @Inject
+  DriverIdleManager(final @Parameter(DriverIdleSources.class) Set<DriverIdlenessSource> idlenessSources,
+                    final InjectionFuture<DriverStatusManager> driverStatusManager) {
+    this.idlenessSources = idlenessSources;
+    this.driverStatusManager = driverStatusManager;
+  }
+
+  public synchronized void onPotentiallyIdle(final IdleMessage reason) {
+    synchronized (driverStatusManager.get()) {
+      if (this.driverStatusManager.get().isShuttingDownOrFailing()) {
+        LOG.log(IDLE_REASONS_LEVEL, "Ignoring idle call from [{0}] for reason [{1}]",
+            new Object[]{reason.getComponentName(), reason.getReason()});
+      } else {
+        boolean isIdle = true;
+        LOG.log(IDLE_REASONS_LEVEL, "Checking for idle because {0} reported idleness for reason [{1}]",
+            new Object[]{reason.getComponentName(), reason.getReason()});
+
+
+        for (final DriverIdlenessSource idlenessSource : this.idlenessSources) {
+          final IdleMessage idleMessage = idlenessSource.getIdleStatus();
+          LOG.log(IDLE_REASONS_LEVEL, "[{0}] is reporting {1} because [{2}]."
+              , new Object[]{idleMessage.getComponentName(), idleMessage.isIdle() ? "idle" : "not idle", idleMessage.getReason()}
+          );
+          isIdle &= idleMessage.isIdle();
+        }
+
+        if (isIdle) {
+          LOG.log(Level.INFO, "All components indicated idle. Initiating Driver shutdown.");
+          this.driverStatusManager.get().onComplete();
+        }
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/DriverIdlenessSource.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/DriverIdlenessSource.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/DriverIdlenessSource.java
new file mode 100644
index 0000000..11f6ad1
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/DriverIdlenessSource.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.runtime.common.driver.idle;
+
+/**
+ * Implementations of this interface are used to determine driver idleness.
+ */
+public interface DriverIdlenessSource {
+
+  /**
+   * @return the idle status of the component.
+   */
+  IdleMessage getIdleStatus();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/EventHandlerIdlenessSource.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/EventHandlerIdlenessSource.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/EventHandlerIdlenessSource.java
new file mode 100644
index 0000000..a8a87c5
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/EventHandlerIdlenessSource.java
@@ -0,0 +1,59 @@
+/**
+ * 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.reef.runtime.common.driver.idle;
+
+import org.apache.reef.runtime.common.driver.evaluator.Evaluators;
+import org.apache.reef.tang.InjectionFuture;
+
+import javax.inject.Inject;
+
+/**
+ * Checks for idleness of the Event handlers.
+ */
+public final class EventHandlerIdlenessSource implements DriverIdlenessSource {
+
+  private static final IdleMessage IDLE_MESSAGE = new IdleMessage("EventHandlers", "All events have been processed.", true);
+  private static final IdleMessage NOT_IDLE_MESSAGE = new IdleMessage("EventHandlers", "Some events are still in flight.", true);
+
+  private final InjectionFuture<Evaluators> evaluators;
+  private final InjectionFuture<DriverIdleManager> driverIdleManager;
+
+  @Inject
+  EventHandlerIdlenessSource(final InjectionFuture<Evaluators> evaluators,
+                             final InjectionFuture<DriverIdleManager> driverIdleManager) {
+    this.evaluators = evaluators;
+    this.driverIdleManager = driverIdleManager;
+  }
+
+
+  @Override
+  public IdleMessage getIdleStatus() {
+    if (this.evaluators.get().allEvaluatorsAreClosed()) {
+      return IDLE_MESSAGE;
+    } else {
+      return NOT_IDLE_MESSAGE;
+    }
+  }
+
+  public void check() {
+    if (this.evaluators.get().allEvaluatorsAreClosed()) {
+      this.driverIdleManager.get().onPotentiallyIdle(IDLE_MESSAGE);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/IdleMessage.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/IdleMessage.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/IdleMessage.java
new file mode 100644
index 0000000..6210458
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/IdleMessage.java
@@ -0,0 +1,61 @@
+/**
+ * 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.reef.runtime.common.driver.idle;
+
+/**
+ * A message to be used to indicate that the driver is potentially idle.
+ */
+public final class IdleMessage {
+
+  private final String componentName;
+  private final String reason;
+  private final boolean isIdle;
+
+  /**
+   * @param componentName the name of the component that is indicating (not) idle, e.g. "Clock"
+   * @param reason        the human-readable reason the component indicates (not) idle, "No more alarms scheduled."
+   * @param isIdle        whether or not the component is idle.
+   */
+  public IdleMessage(final String componentName, final String reason, final boolean isIdle) {
+    this.componentName = componentName;
+    this.reason = reason;
+    this.isIdle = isIdle;
+  }
+
+  /**
+   * @return the name of the component that indicated (not) idle.
+   */
+  public String getComponentName() {
+    return this.componentName;
+  }
+
+  /**
+   * @return the reason for (no) idleness
+   */
+  public String getReason() {
+    return this.reason;
+  }
+
+  /**
+   * @return true if this message indicates idle.
+   */
+  public boolean isIdle() {
+    return this.isIdle;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/package-info.java
new file mode 100644
index 0000000..35dffa2
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/idle/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Contains the Driver idle handling and extension APIs
+ */
+package org.apache.reef.runtime.common.driver.idle;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/package-info.java
new file mode 100644
index 0000000..520cfa1
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Implementation of the Driver-side REEF APIs.
+ */
+package org.apache.reef.runtime.common.driver;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/NodeDescriptorHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/NodeDescriptorHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/NodeDescriptorHandler.java
new file mode 100644
index 0000000..e5fa95e
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/NodeDescriptorHandler.java
@@ -0,0 +1,46 @@
+/**
+ * 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.reef.runtime.common.driver.resourcemanager;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.catalog.ResourceCatalogImpl;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+
+/**
+ * Updates the ResourceCatalog with a new Node.
+ */
+@Private
+@DriverSide
+public final class NodeDescriptorHandler implements EventHandler<DriverRuntimeProtocol.NodeDescriptorProto> {
+  private final ResourceCatalogImpl resourceCatalog;
+
+  @Inject
+  public NodeDescriptorHandler(ResourceCatalogImpl resourceCatalog) {
+    this.resourceCatalog = resourceCatalog;
+  }
+
+  @Override
+  public void onNext(final DriverRuntimeProtocol.NodeDescriptorProto value) {
+    this.resourceCatalog.handle(value);
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceAllocationHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceAllocationHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceAllocationHandler.java
new file mode 100644
index 0000000..7d0e1e8
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceAllocationHandler.java
@@ -0,0 +1,63 @@
+/**
+ * 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.reef.runtime.common.driver.resourcemanager;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.evaluator.EvaluatorManagerFactory;
+import org.apache.reef.runtime.common.driver.evaluator.Evaluators;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+
+/**
+ * Handles new resource allocations by adding a new EvaluatorManager.
+ */
+@Private
+@DriverSide
+public final class ResourceAllocationHandler
+    implements EventHandler<DriverRuntimeProtocol.ResourceAllocationProto> {
+
+  /**
+   * Helper class to make new EvaluatorManager instances,
+   * given a Node they have been allocated on.
+   */
+  private final EvaluatorManagerFactory evaluatorManagerFactory;
+
+  /**
+   * The Evaluators known to the Driver.
+   */
+  private final Evaluators evaluators;
+
+  @Inject
+  ResourceAllocationHandler(
+      final EvaluatorManagerFactory evaluatorManagerFactory, final Evaluators evaluators) {
+    this.evaluatorManagerFactory = evaluatorManagerFactory;
+    this.evaluators = evaluators;
+  }
+
+  @Override
+  public void onNext(final DriverRuntimeProtocol.ResourceAllocationProto value) {
+    // FIXME: Using this put() method is a temporary fix for the race condition
+    // described in issues #828 and #839. Use Evaluators.put(EvaluatorManager) instead
+    // when the bug is fixed.
+    this.evaluators.put(this.evaluatorManagerFactory, value);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceManagerErrorHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceManagerErrorHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceManagerErrorHandler.java
new file mode 100644
index 0000000..7f13de8
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceManagerErrorHandler.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.runtime.common.driver.resourcemanager;
+
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.driver.DriverStatusManager;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+
+/**
+ * Informs the client and then shuts down the driver forcefully in case of Resource Manager errors.
+ */
+public final class ResourceManagerErrorHandler implements EventHandler<ReefServiceProtos.RuntimeErrorProto> {
+
+
+  private final DriverStatusManager driverStatusManager;
+
+  @Inject
+  ResourceManagerErrorHandler(final DriverStatusManager driverStatusManager) {
+    this.driverStatusManager = driverStatusManager;
+  }
+
+  @Override
+  public synchronized void onNext(final ReefServiceProtos.RuntimeErrorProto runtimeErrorProto) {
+    this.driverStatusManager.onError(new Exception("Resource Manager failure"));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceManagerStatus.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceManagerStatus.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceManagerStatus.java
new file mode 100644
index 0000000..c0db65d
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceManagerStatus.java
@@ -0,0 +1,156 @@
+/**
+ * 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.reef.runtime.common.driver.resourcemanager;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.driver.DriverStatusManager;
+import org.apache.reef.runtime.common.driver.idle.DriverIdleManager;
+import org.apache.reef.runtime.common.driver.idle.DriverIdlenessSource;
+import org.apache.reef.runtime.common.driver.idle.IdleMessage;
+import org.apache.reef.tang.InjectionFuture;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Manages the status of the Resource Manager.
+ */
+@DriverSide
+@Private
+public final class ResourceManagerStatus implements EventHandler<DriverRuntimeProtocol.RuntimeStatusProto>,
+    DriverIdlenessSource {
+  private static final Logger LOG = Logger.getLogger(ResourceManagerStatus.class.getName());
+
+  private static final String COMPONENT_NAME = "ResourceManager";
+  private static final IdleMessage IDLE_MESSAGE = new IdleMessage(COMPONENT_NAME, "No outstanding requests or allocations", true);
+
+  private final ResourceManagerErrorHandler resourceManagerErrorHandler;
+  private final DriverStatusManager driverStatusManager;
+  private final InjectionFuture<DriverIdleManager> driverIdleManager;
+
+  // Mutable state.
+  private ReefServiceProtos.State state = ReefServiceProtos.State.INIT;
+  private int outstandingContainerRequests = 0;
+  private int containerAllocationCount = 0;
+
+  @Inject
+  ResourceManagerStatus(final ResourceManagerErrorHandler resourceManagerErrorHandler,
+                        final DriverStatusManager driverStatusManager,
+                        final InjectionFuture<DriverIdleManager> driverIdleManager) {
+    this.resourceManagerErrorHandler = resourceManagerErrorHandler;
+    this.driverStatusManager = driverStatusManager;
+    this.driverIdleManager = driverIdleManager;
+  }
+
+  @Override
+  public synchronized void onNext(final DriverRuntimeProtocol.RuntimeStatusProto runtimeStatusProto) {
+    final ReefServiceProtos.State newState = runtimeStatusProto.getState();
+    LOG.log(Level.FINEST, "Runtime status " + runtimeStatusProto);
+    this.outstandingContainerRequests = runtimeStatusProto.getOutstandingContainerRequests();
+    this.containerAllocationCount = runtimeStatusProto.getContainerAllocationCount();
+    this.setState(runtimeStatusProto.getState());
+
+    switch (newState) {
+      case FAILED:
+        this.onRMFailure(runtimeStatusProto);
+        break;
+      case DONE:
+        this.onRMDone(runtimeStatusProto);
+        break;
+      case RUNNING:
+        this.onRMRunning(runtimeStatusProto);
+        break;
+    }
+  }
+
+  /**
+   * Change the state of the Resource Manager to be RUNNING.
+   */
+  public synchronized void setRunning() {
+    this.setState(ReefServiceProtos.State.RUNNING);
+  }
+
+  /**
+   * @return idle, if there are no outstanding requests or allocations. Not idle else.
+   */
+  @Override
+  public synchronized IdleMessage getIdleStatus() {
+    if (this.isIdle()) {
+      return IDLE_MESSAGE;
+    } else {
+      final String message = new StringBuilder("There are ")
+          .append(this.outstandingContainerRequests)
+          .append(" outstanding container requests and ")
+          .append(this.containerAllocationCount)
+          .append(" allocated containers")
+          .toString();
+      return new IdleMessage(COMPONENT_NAME, message, false);
+    }
+  }
+
+
+  private synchronized void onRMFailure(final DriverRuntimeProtocol.RuntimeStatusProto runtimeStatusProto) {
+    assert (runtimeStatusProto.getState() == ReefServiceProtos.State.FAILED);
+    this.resourceManagerErrorHandler.onNext(runtimeStatusProto.getError());
+  }
+
+  private synchronized void onRMDone(final DriverRuntimeProtocol.RuntimeStatusProto runtimeStatusProto) {
+    assert (runtimeStatusProto.getState() == ReefServiceProtos.State.DONE);
+    LOG.log(Level.INFO, "Resource Manager shutdown happened. Triggering Driver shutdown.");
+    this.driverStatusManager.onComplete();
+  }
+
+  private synchronized void onRMRunning(final DriverRuntimeProtocol.RuntimeStatusProto runtimeStatusProto) {
+    assert (runtimeStatusProto.getState() == ReefServiceProtos.State.RUNNING);
+    if (this.isIdle()) {
+      this.driverIdleManager.get().onPotentiallyIdle(IDLE_MESSAGE);
+    }
+  }
+
+
+  private synchronized boolean isIdle() {
+    return this.hasNoOutstandingRequests()
+        && this.hasNoContainersAllocated();
+  }
+
+  private synchronized boolean isRunning() {
+    return ReefServiceProtos.State.RUNNING.equals(this.state);
+  }
+
+
+  private synchronized void setState(ReefServiceProtos.State state) {
+    // TODO: Add state transition check
+    this.state = state;
+  }
+
+
+  private synchronized boolean hasNoOutstandingRequests() {
+    return this.outstandingContainerRequests == 0;
+  }
+
+  private synchronized boolean hasNoContainersAllocated() {
+    return this.containerAllocationCount == 0;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceStatusHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceStatusHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceStatusHandler.java
new file mode 100644
index 0000000..9abafbd
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/ResourceStatusHandler.java
@@ -0,0 +1,71 @@
+/**
+ * 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.reef.runtime.common.driver.resourcemanager;
+
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.evaluator.EvaluatorManager;
+import org.apache.reef.runtime.common.driver.evaluator.EvaluatorManagerFactory;
+import org.apache.reef.runtime.common.driver.evaluator.Evaluators;
+import org.apache.reef.util.Optional;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+
+/**
+ * A ResourceStatusProto message comes from the ResourceManager layer to indicate what it thinks
+ * about the current state of a given resource. Ideally, we should think the same thing.
+ */
+@Private
+public final class ResourceStatusHandler implements EventHandler<DriverRuntimeProtocol.ResourceStatusProto> {
+
+  private final Evaluators evaluators;
+  private final EvaluatorManagerFactory evaluatorManagerFactory;
+
+  @Inject
+  ResourceStatusHandler(final Evaluators evaluators, final EvaluatorManagerFactory evaluatorManagerFactory) {
+    this.evaluators = evaluators;
+    this.evaluatorManagerFactory = evaluatorManagerFactory;
+  }
+
+  /**
+   * This resource status message comes from the ResourceManager layer; telling me what it thinks
+   * about the state of the resource executing an Evaluator; This method simply passes the message
+   * off to the referenced EvaluatorManager
+   *
+   * @param resourceStatusProto resource status message from the ResourceManager
+   */
+  @Override
+  public void onNext(final DriverRuntimeProtocol.ResourceStatusProto resourceStatusProto) {
+    final Optional<EvaluatorManager> evaluatorManager = this.evaluators.get(resourceStatusProto.getIdentifier());
+    if (evaluatorManager.isPresent()) {
+      evaluatorManager.get().onResourceStatusMessage(resourceStatusProto);
+    } else {
+      if (resourceStatusProto.getIsFromPreviousDriver()) {
+        EvaluatorManager previousEvaluatorManager = this.evaluatorManagerFactory.createForEvaluatorFailedDuringDriverRestart(resourceStatusProto);
+        previousEvaluatorManager.onResourceStatusMessage(resourceStatusProto);
+      } else {
+        throw new RuntimeException(
+            "Unknown resource status from evaluator " + resourceStatusProto.getIdentifier() +
+                " with state " + resourceStatusProto.getState()
+        );
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/package-info.java
new file mode 100644
index 0000000..9ffc87d
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/resourcemanager/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Classes that interface with the resourcemanager (Local, YARN, ...) in the Driver.
+ */
+package org.apache.reef.runtime.common.driver.resourcemanager;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/CompletedTaskImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/CompletedTaskImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/CompletedTaskImpl.java
new file mode 100644
index 0000000..5d1b0d0
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/CompletedTaskImpl.java
@@ -0,0 +1,60 @@
+/**
+ * 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.reef.runtime.common.driver.task;
+
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.task.CompletedTask;
+
+@Private
+@DriverSide
+public final class CompletedTaskImpl implements CompletedTask {
+
+  private final ActiveContext context;
+  private final byte[] message;
+  private final String id;
+
+  public CompletedTaskImpl(final ActiveContext context, final byte[] message, final String id) {
+    this.context = context;
+    this.message = message;
+    this.id = id;
+  }
+
+  @Override
+  public ActiveContext getActiveContext() {
+    return this.context;
+  }
+
+  @Override
+  public byte[] get() {
+    return this.message;
+  }
+
+  @Override
+  public String getId() {
+    return this.id;
+  }
+
+  @Override
+  public String toString() {
+    return "CompletedTask{ID='" + getId() + "'}";
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/RunningTaskImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/RunningTaskImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/RunningTaskImpl.java
new file mode 100644
index 0000000..4aa3092
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/RunningTaskImpl.java
@@ -0,0 +1,138 @@
+/**
+ * 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.reef.runtime.common.driver.task;
+
+import com.google.protobuf.ByteString;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.task.RunningTask;
+import org.apache.reef.proto.EvaluatorRuntimeProtocol.ContextControlProto;
+import org.apache.reef.proto.EvaluatorRuntimeProtocol.StopTaskProto;
+import org.apache.reef.proto.EvaluatorRuntimeProtocol.SuspendTaskProto;
+import org.apache.reef.runtime.common.driver.context.EvaluatorContext;
+import org.apache.reef.runtime.common.driver.evaluator.EvaluatorManager;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Implements the RunningTask client interface. It is mainly a helper class
+ * that will package up various client method calls into protocol buffers and
+ * pass them to its respective EvaluatorManager to deliver to the EvaluatorRuntime.
+ */
+@Private
+@DriverSide
+public final class RunningTaskImpl implements RunningTask {
+
+  private final static Logger LOG = Logger.getLogger(RunningTask.class.getName());
+
+  private final EvaluatorManager evaluatorManager;
+  private final EvaluatorContext evaluatorContext;
+  private final String taskId;
+  private final TaskRepresenter taskRepresenter;
+
+  public RunningTaskImpl(final EvaluatorManager evaluatorManager,
+                         final String taskId,
+                         final EvaluatorContext evaluatorContext,
+                         final TaskRepresenter taskRepresenter) {
+    LOG.log(Level.FINEST, "INIT: TaskRuntime id[" + taskId + "] on evaluator id[" + evaluatorManager.getId() + "]");
+
+    this.evaluatorManager = evaluatorManager;
+    this.evaluatorContext = evaluatorContext;
+    this.taskId = taskId;
+    this.taskRepresenter = taskRepresenter;
+  }
+
+
+  @Override
+  public ActiveContext getActiveContext() {
+    return this.evaluatorContext;
+  }
+
+  @Override
+  public String getId() {
+    return this.taskId;
+  }
+
+  @Override
+  public void send(final byte[] message) {
+    LOG.log(Level.FINEST, "MESSAGE: Task id[" + taskId + "] on evaluator id[" + evaluatorManager.getId() + "]");
+
+    final ContextControlProto contextControlProto = ContextControlProto.newBuilder()
+        .setTaskMessage(ByteString.copyFrom(message))
+        .build();
+
+    this.evaluatorManager.sendContextControlMessage(contextControlProto);
+  }
+
+  @Override
+  public void close() {
+    LOG.log(Level.FINEST, "CLOSE: TaskRuntime id[" + taskId + "] on evaluator id[" + evaluatorManager.getId() + "]");
+
+    if (this.taskRepresenter.isNotRunning()) {
+      LOG.log(Level.FINE, "Ignoring call to .close() because the task is no longer RUNNING.");
+    } else {
+      final ContextControlProto contextControlProto = ContextControlProto.newBuilder()
+          .setStopTask(StopTaskProto.newBuilder().build())
+          .build();
+      this.evaluatorManager.sendContextControlMessage(contextControlProto);
+    }
+  }
+
+  @Override
+  public void close(final byte[] message) {
+    LOG.log(Level.FINEST, "CLOSE: TaskRuntime id[" + taskId + "] on evaluator id[" + evaluatorManager.getId() + "] with message.");
+    if (this.taskRepresenter.isNotRunning()) {
+      throw new RuntimeException("Trying to send a message to a Task that is no longer RUNNING.");
+    }
+
+    final ContextControlProto contextControlProto = ContextControlProto.newBuilder()
+        .setStopTask(StopTaskProto.newBuilder().build())
+        .setTaskMessage(ByteString.copyFrom(message))
+        .build();
+    this.evaluatorManager.sendContextControlMessage(contextControlProto);
+  }
+
+  @Override
+  public void suspend(final byte[] message) {
+    LOG.log(Level.FINEST, "SUSPEND: TaskRuntime id[" + taskId + "] on evaluator id[" + evaluatorManager.getId() + "] with message.");
+
+    final ContextControlProto contextControlProto = ContextControlProto.newBuilder()
+        .setSuspendTask(SuspendTaskProto.newBuilder().build())
+        .setTaskMessage(ByteString.copyFrom(message))
+        .build();
+    this.evaluatorManager.sendContextControlMessage(contextControlProto);
+  }
+
+  @Override
+  public void suspend() {
+    LOG.log(Level.FINEST, "SUSPEND: TaskRuntime id[" + taskId + "] on evaluator id[" + evaluatorManager.getId() + "]");
+
+    final ContextControlProto contextControlProto = ContextControlProto.newBuilder()
+        .setSuspendTask(SuspendTaskProto.newBuilder().build())
+        .build();
+    this.evaluatorManager.sendContextControlMessage(contextControlProto);
+  }
+
+  @Override
+  public String toString() {
+    return "RunningTask{taskId='" + taskId + "'}";
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/SuspendedTaskImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/SuspendedTaskImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/SuspendedTaskImpl.java
new file mode 100644
index 0000000..e750954
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/SuspendedTaskImpl.java
@@ -0,0 +1,58 @@
+/**
+ * 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.reef.runtime.common.driver.task;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.task.SuspendedTask;
+
+@Private
+@DriverSide
+public final class SuspendedTaskImpl implements SuspendedTask {
+  private final ActiveContext context;
+  private final byte[] message;
+  private final String id;
+
+  public SuspendedTaskImpl(final ActiveContext context, final byte[] message, final String id) {
+    this.context = context;
+    this.message = message;
+    this.id = id;
+  }
+
+  @Override
+  public ActiveContext getActiveContext() {
+    return this.context;
+  }
+
+  @Override
+  public byte[] get() {
+    return this.message;
+  }
+
+  @Override
+  public String getId() {
+    return this.id;
+  }
+
+  @Override
+  public String toString() {
+    return "SuspendedTask{ID='" + getId() + "'}";
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/TaskMessageImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/TaskMessageImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/TaskMessageImpl.java
new file mode 100644
index 0000000..5a29b47
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/TaskMessageImpl.java
@@ -0,0 +1,61 @@
+/**
+ * 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.reef.runtime.common.driver.task;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.task.TaskMessage;
+
+@Private
+@DriverSide
+public final class TaskMessageImpl implements TaskMessage {
+
+  private final byte[] theMessage;
+  private final String taskId;
+  private final String contextId;
+  private final String theMessageSourceId;
+
+  public TaskMessageImpl(final byte[] theMessage, final String taskId,
+                         final String contextId, final String theMessageSourceId) {
+    this.theMessage = theMessage;
+    this.taskId = taskId;
+    this.contextId = contextId;
+    this.theMessageSourceId = theMessageSourceId;
+  }
+
+  @Override
+  public byte[] get() {
+    return this.theMessage;
+  }
+
+  @Override
+  public String getId() {
+    return this.taskId;
+  }
+
+  @Override
+  public String getContextId() {
+    return this.contextId;
+  }
+
+  @Override
+  public final String getMessageSourceID() {
+    return this.theMessageSourceId;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/TaskRepresenter.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/TaskRepresenter.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/TaskRepresenter.java
new file mode 100644
index 0000000..1c65197
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/TaskRepresenter.java
@@ -0,0 +1,202 @@
+/**
+ * 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.reef.runtime.common.driver.task;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.task.FailedTask;
+import org.apache.reef.driver.task.RunningTask;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.driver.context.EvaluatorContext;
+import org.apache.reef.runtime.common.driver.evaluator.EvaluatorManager;
+import org.apache.reef.runtime.common.driver.evaluator.EvaluatorMessageDispatcher;
+import org.apache.reef.runtime.common.utils.ExceptionCodec;
+import org.apache.reef.util.Optional;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Represents a Task on the Driver.
+ */
+@DriverSide
+@Private
+public final class TaskRepresenter {
+
+  private static final Logger LOG = Logger.getLogger(TaskRepresenter.class.getName());
+
+  private final EvaluatorContext context;
+  private final EvaluatorMessageDispatcher messageDispatcher;
+  private final EvaluatorManager evaluatorManager;
+  private final ExceptionCodec exceptionCodec;
+  private final String taskId;
+
+  // Mutable state
+  private ReefServiceProtos.State state = ReefServiceProtos.State.INIT;
+
+  public TaskRepresenter(final String taskId,
+                         final EvaluatorContext context,
+                         final EvaluatorMessageDispatcher messageDispatcher,
+                         final EvaluatorManager evaluatorManager,
+                         final ExceptionCodec exceptionCodec) {
+    this.taskId = taskId;
+    this.context = context;
+    this.messageDispatcher = messageDispatcher;
+    this.evaluatorManager = evaluatorManager;
+    this.exceptionCodec = exceptionCodec;
+  }
+
+  private static byte[] getResult(final ReefServiceProtos.TaskStatusProto taskStatusProto) {
+    return taskStatusProto.hasResult() ? taskStatusProto.getResult().toByteArray() : null;
+  }
+
+  public void onTaskStatusMessage(final ReefServiceProtos.TaskStatusProto taskStatusProto) {
+
+    LOG.log(Level.FINE, "Received task {0} status {1}",
+        new Object[]{taskStatusProto.getTaskId(), taskStatusProto.getState()});
+
+    // Make sure that the message is indeed for us.
+    if (!taskStatusProto.getContextId().equals(this.context.getId())) {
+      throw new RuntimeException(
+          "Received a message for a task running on Context " + taskStatusProto.getContextId() +
+              " while the Driver believes this Task to be run on Context " + this.context.getId());
+    }
+
+    if (!taskStatusProto.getTaskId().equals(this.taskId)) {
+      throw new RuntimeException("Received a message for task " + taskStatusProto.getTaskId() +
+          " in the TaskRepresenter for Task " + this.taskId);
+    }
+    if (taskStatusProto.getRecovery()) {
+      // when a recovered heartbeat is received, we will take its word for it
+      LOG.log(Level.INFO, "Received task status {0} for RECOVERED task {1}.",
+          new Object[]{taskStatusProto.getState(), this.taskId});
+      this.setState(taskStatusProto.getState());
+    }
+    // Dispatch the message to the right method.
+    switch (taskStatusProto.getState()) {
+      case INIT:
+        this.onTaskInit(taskStatusProto);
+        break;
+      case RUNNING:
+        this.onTaskRunning(taskStatusProto);
+        break;
+      case SUSPEND:
+        this.onTaskSuspend(taskStatusProto);
+        break;
+      case DONE:
+        this.onTaskDone(taskStatusProto);
+        break;
+      case FAILED:
+        this.onTaskFailed(taskStatusProto);
+        break;
+      default:
+        throw new IllegalStateException("Unknown task state: " + taskStatusProto.getState());
+    }
+  }
+
+  private void onTaskInit(final ReefServiceProtos.TaskStatusProto taskStatusProto) {
+    assert ((ReefServiceProtos.State.INIT == taskStatusProto.getState()));
+    if (this.isKnown()) {
+      LOG.log(Level.WARNING, "Received a INIT message for task with id {0}" +
+          " which we have seen before. Ignoring the second message", this.taskId);
+    } else {
+      final RunningTask runningTask = new RunningTaskImpl(
+          this.evaluatorManager, this.taskId, this.context, this);
+      this.messageDispatcher.onTaskRunning(runningTask);
+      this.setState(ReefServiceProtos.State.RUNNING);
+    }
+  }
+
+  private void onTaskRunning(final ReefServiceProtos.TaskStatusProto taskStatusProto) {
+
+    assert (taskStatusProto.getState() == ReefServiceProtos.State.RUNNING);
+
+    if (this.isNotRunning()) {
+      throw new IllegalStateException("Received a task status message from task " + this.taskId +
+          " that is believed to be RUNNING on the Evaluator, but the Driver thinks it is in state " + this.state);
+    }
+
+    // fire driver restart task running handler if this is a recovery heartbeat
+    if (taskStatusProto.getRecovery()) {
+      final RunningTask runningTask = new RunningTaskImpl(
+          this.evaluatorManager, this.taskId, this.context, this);
+      this.messageDispatcher.onDriverRestartTaskRunning(runningTask);
+    }
+
+    for (final ReefServiceProtos.TaskStatusProto.TaskMessageProto taskMessageProto : taskStatusProto.getTaskMessageList()) {
+      this.messageDispatcher.onTaskMessage(
+          new TaskMessageImpl(taskMessageProto.getMessage().toByteArray(),
+              this.taskId, this.context.getId(), taskMessageProto.getSourceId()));
+    }
+  }
+
+  private void onTaskSuspend(final ReefServiceProtos.TaskStatusProto taskStatusProto) {
+    assert (ReefServiceProtos.State.SUSPEND == taskStatusProto.getState());
+    assert (this.isKnown());
+    this.messageDispatcher.onTaskSuspended(
+        new SuspendedTaskImpl(this.context, getResult(taskStatusProto), this.taskId));
+    this.setState(ReefServiceProtos.State.SUSPEND);
+  }
+
+  private void onTaskDone(final ReefServiceProtos.TaskStatusProto taskStatusProto) {
+    assert (ReefServiceProtos.State.DONE == taskStatusProto.getState());
+    assert (this.isKnown());
+    this.messageDispatcher.onTaskCompleted(
+        new CompletedTaskImpl(this.context, getResult(taskStatusProto), this.taskId));
+    this.setState(ReefServiceProtos.State.DONE);
+  }
+
+  private void onTaskFailed(final ReefServiceProtos.TaskStatusProto taskStatusProto) {
+    assert (ReefServiceProtos.State.FAILED == taskStatusProto.getState());
+    final Optional<ActiveContext> evaluatorContext = Optional.<ActiveContext>of(this.context);
+    final Optional<byte[]> bytes = Optional.ofNullable(getResult(taskStatusProto));
+    final Optional<Throwable> exception = this.exceptionCodec.fromBytes(bytes);
+    final String message = exception.isPresent() ? exception.get().getMessage() : "No message given";
+    final Optional<String> description = Optional.empty();
+    final FailedTask failedTask = new FailedTask(
+        this.taskId, message, description, exception, bytes, evaluatorContext);
+    this.messageDispatcher.onTaskFailed(failedTask);
+    this.setState(ReefServiceProtos.State.FAILED);
+  }
+
+  public String getId() {
+    return this.taskId;
+  }
+
+  /**
+   * @return true, if we had at least one message from the task.
+   */
+  private boolean isKnown() {
+    return this.state != ReefServiceProtos.State.INIT;
+  }
+
+  /**
+   * @return true, if this task is in any other state but RUNNING.
+   */
+  public boolean isNotRunning() {
+    return this.state != ReefServiceProtos.State.RUNNING;
+  }
+
+  private void setState(final ReefServiceProtos.State newState) {
+    LOG.log(Level.FINE, "Task [{0}] state transition from [{1}] to [{2}]",
+        new Object[]{this.taskId, this.state, newState});
+    this.state = newState;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/package-info.java
new file mode 100644
index 0000000..ea55cca
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/driver/task/package-info.java
@@ -0,0 +1,26 @@
+/**
+ * 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.
+ */
+/**
+ * Driver-Side representations of tasks.
+ */
+@Private
+@DriverSide package org.apache.reef.runtime.common.driver.task;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/DefaultDriverConnection.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/DefaultDriverConnection.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/DefaultDriverConnection.java
new file mode 100644
index 0000000..61ca305
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/DefaultDriverConnection.java
@@ -0,0 +1,48 @@
+/**
+ * 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.reef.runtime.common.evaluator;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Default implementation for re-establishing connection to driver after driver restart.
+ * In this default implementation, information about re-started driver will be obtained
+ * by querying Http server.
+ */
+public final class DefaultDriverConnection implements DriverConnection {
+
+  private static final Logger LOG = Logger.getLogger(DefaultDriverConnection.class.getName());
+
+  @Inject
+  public DefaultDriverConnection() {
+  }
+
+  @Override
+  public String getDriverRemoteIdentifier() {
+    LOG.log(Level.FINE, "Trying to get driver remote identifier by querying Http server.");
+    // TODO: implement a proper mechanism to obtain driver remote identifier.
+    throw new UnsupportedOperationException("Not implemented");
+  }
+
+  @Override
+  public void close() {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/DriverConnection.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/DriverConnection.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/DriverConnection.java
new file mode 100644
index 0000000..a3ce3f3
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/DriverConnection.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.runtime.common.evaluator;
+
+/**
+ * Interface used for reconnecting to driver after driver restart
+ */
+public interface DriverConnection extends AutoCloseable {
+
+  /**
+   * @return driver remove identifier to facilitate reconnection to the (restarted) driver
+   */
+  String getDriverRemoteIdentifier();
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/EvaluatorConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/EvaluatorConfiguration.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/EvaluatorConfiguration.java
new file mode 100644
index 0000000..43d7469
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/EvaluatorConfiguration.java
@@ -0,0 +1,68 @@
+/**
+ * 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.reef.runtime.common.evaluator;
+
+import org.apache.reef.runtime.common.evaluator.parameters.*;
+import org.apache.reef.tang.ExternalConstructor;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.OptionalParameter;
+import org.apache.reef.tang.formats.RequiredParameter;
+import org.apache.reef.wake.time.Clock;
+
+import javax.inject.Inject;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * The runtime configuration of an evaluator.
+ */
+public final class EvaluatorConfiguration extends ConfigurationModuleBuilder {
+  public static final RequiredParameter<String> DRIVER_REMOTE_IDENTIFIER = new RequiredParameter<>();
+  public static final RequiredParameter<String> EVALUATOR_IDENTIFIER = new RequiredParameter<>();
+  public static final RequiredParameter<String> ROOT_CONTEXT_CONFIGURATION = new RequiredParameter<>();
+  public static final OptionalParameter<String> ROOT_SERVICE_CONFIGURATION = new OptionalParameter<>();
+  public static final OptionalParameter<String> TASK_CONFIGURATION = new OptionalParameter<>();
+  public static final OptionalParameter<Integer> HEARTBEAT_PERIOD = new OptionalParameter<>();
+  public static final OptionalParameter<String> APPLICATION_IDENTIFIER = new OptionalParameter<>();
+  public static final ConfigurationModule CONF = new EvaluatorConfiguration()
+      .bindSetEntry(Clock.RuntimeStartHandler.class, EvaluatorRuntime.RuntimeStartHandler.class)
+      .bindSetEntry(Clock.RuntimeStopHandler.class, EvaluatorRuntime.RuntimeStopHandler.class)
+      .bindConstructor(ExecutorService.class, ExecutorServiceConstructor.class)
+      .bindNamedParameter(DriverRemoteIdentifier.class, DRIVER_REMOTE_IDENTIFIER)
+      .bindNamedParameter(EvaluatorIdentifier.class, EVALUATOR_IDENTIFIER)
+      .bindNamedParameter(HeartbeatPeriod.class, HEARTBEAT_PERIOD)
+      .bindNamedParameter(RootContextConfiguration.class, ROOT_CONTEXT_CONFIGURATION)
+      .bindNamedParameter(InitialTaskConfiguration.class, TASK_CONFIGURATION)
+      .bindNamedParameter(RootServiceConfiguration.class, ROOT_SERVICE_CONFIGURATION)
+      .bindNamedParameter(ApplicationIdentifier.class, APPLICATION_IDENTIFIER)
+      .build();
+
+  private final static class ExecutorServiceConstructor implements ExternalConstructor<ExecutorService> {
+
+    @Inject
+    ExecutorServiceConstructor() {
+    }
+
+    @Override
+    public ExecutorService newInstance() {
+      return Executors.newCachedThreadPool();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/EvaluatorRuntime.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/EvaluatorRuntime.java b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/EvaluatorRuntime.java
new file mode 100644
index 0000000..b239ee8
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/runtime/common/evaluator/EvaluatorRuntime.java
@@ -0,0 +1,207 @@
+/**
+ * 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.reef.runtime.common.evaluator;
+
+import com.google.protobuf.ByteString;
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.proto.EvaluatorRuntimeProtocol.EvaluatorControlProto;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.proto.ReefServiceProtos.EvaluatorStatusProto;
+import org.apache.reef.runtime.common.evaluator.context.ContextManager;
+import org.apache.reef.runtime.common.evaluator.parameters.DriverRemoteIdentifier;
+import org.apache.reef.runtime.common.evaluator.parameters.EvaluatorIdentifier;
+import org.apache.reef.runtime.common.evaluator.parameters.HeartbeatPeriod;
+import org.apache.reef.runtime.common.utils.ExceptionCodec;
+import org.apache.reef.runtime.common.utils.RemoteManager;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.runtime.event.RuntimeStart;
+import org.apache.reef.wake.time.runtime.event.RuntimeStop;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+@Unit
+@EvaluatorSide
+final class EvaluatorRuntime implements EventHandler<EvaluatorControlProto> {
+
+  private final static Logger LOG = Logger.getLogger(EvaluatorRuntime.class.getName());
+
+  private final HeartBeatManager heartBeatManager;
+  private final ContextManager contextManager;
+  private final Clock clock;
+
+  private final String evaluatorIdentifier;
+  private final ExceptionCodec exceptionCodec;
+  private final AutoCloseable evaluatorControlChannel;
+
+  private ReefServiceProtos.State state = ReefServiceProtos.State.INIT;
+
+  @Inject
+  private EvaluatorRuntime(
+      final @Parameter(HeartbeatPeriod.class) int heartbeatPeriod,
+      final @Parameter(EvaluatorIdentifier.class) String evaluatorIdentifier,
+      final @Parameter(DriverRemoteIdentifier.class) String driverRID,
+      final HeartBeatManager.HeartbeatAlarmHandler heartbeatAlarmHandler,
+      final HeartBeatManager heartBeatManager,
+      final Clock clock,
+      final ContextManager contextManagerFuture,
+      final RemoteManager remoteManager,
+      final ExceptionCodec exceptionCodec) {
+
+    this.heartBeatManager = heartBeatManager;
+    this.contextManager = contextManagerFuture;
+    this.clock = clock;
+
+    this.evaluatorIdentifier = evaluatorIdentifier;
+    this.exceptionCodec = exceptionCodec;
+    this.evaluatorControlChannel =
+        remoteManager.registerHandler(driverRID, EvaluatorControlProto.class, this);
+
+    // start the heartbeats
+    clock.scheduleAlarm(heartbeatPeriod, heartbeatAlarmHandler);
+  }
+
+  private void onEvaluatorControlMessage(final EvaluatorControlProto message) {
+
+    synchronized (this.heartBeatManager) {
+
+      LOG.log(Level.FINEST, "Evaluator control message");
+
+      if (!message.getIdentifier().equals(this.evaluatorIdentifier)) {
+        this.onException(new RuntimeException(
+            "Identifier mismatch: message for evaluator id[" + message.getIdentifier()
+                + "] sent to evaluator id[" + this.evaluatorIdentifier + "]"
+        ));
+      } else if (ReefServiceProtos.State.RUNNING != this.state) {
+        this.onException(new RuntimeException(
+            "Evaluator sent a control message but its state is not "
+                + ReefServiceProtos.State.RUNNING + " but rather " + this.state
+        ));
+      } else {
+
+        if (message.hasContextControl()) {
+
+          LOG.log(Level.FINEST, "Send task control message to ContextManager");
+
+          try {
+            this.contextManager.handleContextControlProtocol(message.getContextControl());
+            if (this.contextManager.contextStackIsEmpty() && this.state == ReefServiceProtos.State.RUNNING) {
+              this.state = ReefServiceProtos.State.DONE;
+              this.heartBeatManager.sendEvaluatorStatus(this.getEvaluatorStatus());
+              this.clock.close();
+            }
+          } catch (final Throwable e) {
+            this.onException(e);
+            throw new RuntimeException(e);
+          }
+        }
+
+        if (message.hasKillEvaluator()) {
+          LOG.log(Level.SEVERE, "Evaluator {0} has been killed by the driver.", this.evaluatorIdentifier);
+          this.state = ReefServiceProtos.State.KILLED;
+          this.clock.close();
+        }
+      }
+    }
+  }
+
+  private final void onException(final Throwable exception) {
+    synchronized (this.heartBeatManager) {
+      this.state = ReefServiceProtos.State.FAILED;
+
+      final EvaluatorStatusProto evaluatorStatusProto = EvaluatorStatusProto.newBuilder()
+          .setEvaluatorId(this.evaluatorIdentifier)
+          .setError(ByteString.copyFrom(this.exceptionCodec.toBytes(exception)))
+          .setState(this.state)
+          .build();
+      this.heartBeatManager.sendEvaluatorStatus(evaluatorStatusProto);
+      this.contextManager.close();
+    }
+  }
+
+  public EvaluatorStatusProto getEvaluatorStatus() {
+    synchronized (this.heartBeatManager) {
+      LOG.log(Level.FINEST, "Evaluator heartbeat: state = {0}", this.state);
+      final EvaluatorStatusProto.Builder evaluatorStatus =
+          EvaluatorStatusProto.newBuilder()
+              .setEvaluatorId(this.evaluatorIdentifier)
+              .setState(this.state);
+      return evaluatorStatus.build();
+    }
+  }
+
+  final ReefServiceProtos.State getState() {
+    return this.state;
+  }
+
+  boolean isRunning() {
+    return this.state == ReefServiceProtos.State.RUNNING;
+  }
+
+  @Override
+  public void onNext(EvaluatorControlProto evaluatorControlProto) {
+    this.onEvaluatorControlMessage(evaluatorControlProto);
+  }
+
+  final class RuntimeStartHandler implements EventHandler<RuntimeStart> {
+
+    @Override
+    public final void onNext(final RuntimeStart runtimeStart) {
+      synchronized (EvaluatorRuntime.this.heartBeatManager) {
+        try {
+          LOG.log(Level.FINEST, "runtime start");
+          assert (ReefServiceProtos.State.INIT == EvaluatorRuntime.this.state);
+          EvaluatorRuntime.this.state = ReefServiceProtos.State.RUNNING;
+          EvaluatorRuntime.this.contextManager.start();
+          EvaluatorRuntime.this.heartBeatManager.sendHeartbeat();
+        } catch (final Throwable e) {
+          EvaluatorRuntime.this.onException(e);
+        }
+      }
+    }
+  }
+
+  final class RuntimeStopHandler implements EventHandler<RuntimeStop> {
+
+    @Override
+    public final void onNext(final RuntimeStop runtimeStop) {
+      synchronized (EvaluatorRuntime.this.heartBeatManager) {
+        LOG.log(Level.FINEST, "EvaluatorRuntime shutdown invoked for Evaluator {0} in state {1}",
+            new Object[]{evaluatorIdentifier, state});
+
+        if (EvaluatorRuntime.this.isRunning()) {
+          EvaluatorRuntime.this.onException(new RuntimeException(
+              "RuntimeStopHandler invoked in state RUNNING.", runtimeStop.getException()));
+        } else {
+          EvaluatorRuntime.this.contextManager.close();
+          try {
+            EvaluatorRuntime.this.evaluatorControlChannel.close();
+          } catch (final Exception e) {
+            LOG.log(Level.SEVERE, "Exception during shutdown of evaluatorControlChannel.", e);
+          }
+          LOG.log(Level.FINEST, "EvaluatorRuntime shutdown complete");
+        }
+      }
+    }
+  }
+}


[27/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NSMessageCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NSMessageCodec.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NSMessageCodec.java
new file mode 100644
index 0000000..f22f970
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NSMessageCodec.java
@@ -0,0 +1,134 @@
+/**
+ * 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.reef.io.network.impl;
+
+import com.google.protobuf.ByteString;
+import com.google.protobuf.InvalidProtocolBufferException;
+import org.apache.reef.io.network.exception.NetworkRuntimeException;
+import org.apache.reef.io.network.proto.ReefNetworkServiceProtos.NSMessagePBuf;
+import org.apache.reef.io.network.proto.ReefNetworkServiceProtos.NSRecordPBuf;
+import org.apache.reef.wake.Identifier;
+import org.apache.reef.wake.IdentifierFactory;
+import org.apache.reef.wake.remote.Codec;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Network service message codec
+ *
+ * @param <T> type
+ */
+public class NSMessageCodec<T> implements Codec<NSMessage<T>> {
+
+  private final Codec<T> codec;
+  private final IdentifierFactory factory;
+  private final boolean isStreamingCodec;
+
+  /**
+   * Constructs a network service message codec
+   *
+   * @param codec   a codec
+   * @param factory an identifier factory
+   */
+  public NSMessageCodec(final Codec<T> codec, final IdentifierFactory factory) {
+    this.codec = codec;
+    this.factory = factory;
+    this.isStreamingCodec = codec instanceof StreamingCodec;
+  }
+
+  /**
+   * Encodes a network service message to bytes
+   *
+   * @param obj a message
+   * @return bytes
+   */
+  @Override
+  public byte[] encode(final NSMessage<T> obj) {
+    if (isStreamingCodec) {
+      final StreamingCodec<T> streamingCodec = (StreamingCodec<T>) codec;
+      try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+        try (DataOutputStream daos = new DataOutputStream(baos)) {
+          daos.writeUTF(obj.getSrcId().toString());
+          daos.writeUTF(obj.getDestId().toString());
+          daos.writeInt(obj.getData().size());
+          for (final T rec : obj.getData()) {
+            streamingCodec.encodeToStream(rec, daos);
+          }
+        }
+        return baos.toByteArray();
+      } catch (final IOException e) {
+        throw new RuntimeException("IOException", e);
+      }
+    } else {
+      final NSMessagePBuf.Builder pbuf = NSMessagePBuf.newBuilder();
+      pbuf.setSrcid(obj.getSrcId().toString());
+      pbuf.setDestid(obj.getDestId().toString());
+      for (final T rec : obj.getData()) {
+        final NSRecordPBuf.Builder rbuf = NSRecordPBuf.newBuilder();
+        rbuf.setData(ByteString.copyFrom(codec.encode(rec)));
+        pbuf.addMsgs(rbuf);
+      }
+      return pbuf.build().toByteArray();
+    }
+  }
+
+  /**
+   * Decodes a network service message from bytes
+   *
+   * @param buf bytes
+   * @return a message
+   */
+  @Override
+  public NSMessage<T> decode(final byte[] buf) {
+    if (isStreamingCodec) {
+      final StreamingCodec<T> streamingCodec = (StreamingCodec<T>) codec;
+      try (ByteArrayInputStream bais = new ByteArrayInputStream(buf)) {
+        try (DataInputStream dais = new DataInputStream(bais)) {
+          final Identifier srcId = factory.getNewInstance(dais.readUTF());
+          final Identifier destId = factory.getNewInstance(dais.readUTF());
+          final int size = dais.readInt();
+          final List<T> list = new ArrayList<T>(size);
+          for (int i = 0; i < size; i++) {
+            list.add(streamingCodec.decodeFromStream(dais));
+          }
+          return new NSMessage<>(srcId, destId, list);
+        }
+      } catch (final IOException e) {
+        throw new RuntimeException("IOException", e);
+      }
+    } else {
+      NSMessagePBuf pbuf;
+      try {
+        pbuf = NSMessagePBuf.parseFrom(buf);
+      } catch (final InvalidProtocolBufferException e) {
+        e.printStackTrace();
+        throw new NetworkRuntimeException(e);
+      }
+      final List<T> list = new ArrayList<T>();
+      for (final NSRecordPBuf rbuf : pbuf.getMsgsList()) {
+        list.add(codec.decode(rbuf.getData().toByteArray()));
+      }
+      return new NSMessage<T>(factory.getNewInstance(pbuf.getSrcid()), factory.getNewInstance(pbuf.getDestid()), list);
+    }
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NameServiceCloseHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NameServiceCloseHandler.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NameServiceCloseHandler.java
new file mode 100644
index 0000000..f569fcd
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NameServiceCloseHandler.java
@@ -0,0 +1,49 @@
+/**
+ * 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.reef.io.network.impl;
+
+import org.apache.reef.evaluator.context.events.ContextStop;
+import org.apache.reef.io.network.naming.NameServer;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public final class NameServiceCloseHandler implements EventHandler<ContextStop> {
+
+  private static final Logger LOG = Logger.getLogger(NameServiceCloseHandler.class.getName());
+
+  private final AutoCloseable toClose;
+
+  @Inject
+  public NameServiceCloseHandler(final NameServer toClose) {
+    this.toClose = toClose;
+  }
+
+  @Override
+  public void onNext(final ContextStop event) {
+    try {
+      LOG.log(Level.FINEST, "Closing {0}", this.toClose);
+      this.toClose.close();
+    } catch (final Throwable ex) {
+      LOG.log(Level.SEVERE, "Exception while closing " + this.toClose, ex);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NetworkService.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NetworkService.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NetworkService.java
new file mode 100644
index 0000000..6120193
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NetworkService.java
@@ -0,0 +1,235 @@
+/**
+ * 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.reef.io.network.impl;
+
+import org.apache.reef.io.Tuple;
+import org.apache.reef.io.naming.Naming;
+import org.apache.reef.io.network.Connection;
+import org.apache.reef.io.network.ConnectionFactory;
+import org.apache.reef.io.network.Message;
+import org.apache.reef.io.network.TransportFactory;
+import org.apache.reef.io.network.naming.NameCache;
+import org.apache.reef.io.network.naming.NameClient;
+import org.apache.reef.io.network.naming.NameLookupClient;
+import org.apache.reef.io.network.naming.NameServerParameters;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.wake.*;
+import org.apache.reef.wake.impl.LoggingEventHandler;
+import org.apache.reef.wake.impl.SingleThreadStage;
+import org.apache.reef.wake.remote.Codec;
+import org.apache.reef.wake.remote.impl.TransportEvent;
+import org.apache.reef.wake.remote.transport.LinkListener;
+import org.apache.reef.wake.remote.transport.Transport;
+
+import javax.inject.Inject;
+import java.net.InetSocketAddress;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Network service for Task
+ */
+public final class NetworkService<T> implements Stage, ConnectionFactory<T> {
+
+  private static final Logger LOG = Logger.getLogger(NetworkService.class.getName());
+
+  private static final int retryCount;
+  private static final int retryTimeout;
+
+  static {
+    try {
+      final Injector injector = Tang.Factory.getTang().newInjector();
+      retryCount = injector.getNamedInstance(NameLookupClient.RetryCount.class);
+      retryTimeout = injector.getNamedInstance(NameLookupClient.RetryTimeout.class);
+    } catch (final InjectionException ex) {
+      final String msg = "Exception while trying to find default values for retryCount & Timeout";
+      LOG.log(Level.SEVERE, msg, ex);
+      throw new RuntimeException(msg, ex);
+    }
+  }
+
+  private final IdentifierFactory factory;
+  private final Codec<T> codec;
+  private final Transport transport;
+  private final NameClient nameClient;
+  private final ConcurrentMap<Identifier, Connection<T>> idToConnMap = new ConcurrentHashMap<>();
+  private final EStage<Tuple<Identifier, InetSocketAddress>> nameServiceRegisteringStage;
+  private final EStage<Identifier> nameServiceUnregisteringStage;
+  private Identifier myId;
+
+  public NetworkService(final IdentifierFactory factory,
+                        final int nsPort,
+                        final String nameServerAddr,
+                        final int nameServerPort,
+                        final Codec<T> codec,
+                        final TransportFactory tpFactory,
+                        final EventHandler<Message<T>> recvHandler,
+                        final EventHandler<Exception> exHandler) {
+    this(factory, nsPort, nameServerAddr, nameServerPort,
+        retryCount, retryTimeout, codec, tpFactory, recvHandler, exHandler);
+  }
+
+  @Inject
+  public NetworkService(
+      final @Parameter(NetworkServiceParameters.NetworkServiceIdentifierFactory.class) IdentifierFactory factory,
+      final @Parameter(NetworkServiceParameters.NetworkServicePort.class) int nsPort,
+      final @Parameter(NameServerParameters.NameServerAddr.class) String nameServerAddr,
+      final @Parameter(NameServerParameters.NameServerPort.class) int nameServerPort,
+      final @Parameter(NameLookupClient.RetryCount.class) int retryCount,
+      final @Parameter(NameLookupClient.RetryTimeout.class) int retryTimeout,
+      final @Parameter(NetworkServiceParameters.NetworkServiceCodec.class) Codec<T> codec,
+      final @Parameter(NetworkServiceParameters.NetworkServiceTransportFactory.class) TransportFactory tpFactory,
+      final @Parameter(NetworkServiceParameters.NetworkServiceHandler.class) EventHandler<Message<T>> recvHandler,
+      final @Parameter(NetworkServiceParameters.NetworkServiceExceptionHandler.class) EventHandler<Exception> exHandler) {
+
+    this.factory = factory;
+    this.codec = codec;
+    this.transport = tpFactory.create(nsPort,
+        new LoggingEventHandler<TransportEvent>(),
+        new MessageHandler<T>(recvHandler, codec, factory), exHandler);
+
+    this.nameClient = new NameClient(nameServerAddr, nameServerPort,
+        factory, retryCount, retryTimeout, new NameCache(30000));
+
+    this.nameServiceRegisteringStage = new SingleThreadStage<>(
+        "NameServiceRegisterer", new EventHandler<Tuple<Identifier, InetSocketAddress>>() {
+      @Override
+      public void onNext(final Tuple<Identifier, InetSocketAddress> tuple) {
+        try {
+          nameClient.register(tuple.getKey(), tuple.getValue());
+          LOG.log(Level.FINEST, "Registered {0} with nameservice", tuple.getKey());
+        } catch (final Exception ex) {
+          final String msg = "Unable to register " + tuple.getKey() + "with name service";
+          LOG.log(Level.WARNING, msg, ex);
+          throw new RuntimeException(msg, ex);
+        }
+      }
+    }, 5);
+
+    this.nameServiceUnregisteringStage = new SingleThreadStage<>(
+        "NameServiceRegisterer", new EventHandler<Identifier>() {
+      @Override
+      public void onNext(final Identifier id) {
+        try {
+          nameClient.unregister(id);
+          LOG.log(Level.FINEST, "Unregistered {0} with nameservice", id);
+        } catch (final Exception ex) {
+          final String msg = "Unable to unregister " + id + " with name service";
+          LOG.log(Level.WARNING, msg, ex);
+          throw new RuntimeException(msg, ex);
+        }
+      }
+    }, 5);
+  }
+
+  public void registerId(final Identifier id) {
+    this.myId = id;
+    final Tuple<Identifier, InetSocketAddress> tuple =
+        new Tuple<>(id, (InetSocketAddress) this.transport.getLocalAddress());
+    LOG.log(Level.FINEST, "Binding {0} to NetworkService@({1})",
+        new Object[]{tuple.getKey(), tuple.getValue()});
+    this.nameServiceRegisteringStage.onNext(tuple);
+  }
+
+  public void unregisterId(Identifier id) {
+    this.myId = null;
+    LOG.log(Level.FINEST, "Unbinding {0} to NetworkService@({1})",
+        new Object[]{id, this.transport.getLocalAddress()});
+    this.nameServiceUnregisteringStage.onNext(id);
+  }
+
+  public Identifier getMyId() {
+    return this.myId;
+  }
+
+  public Transport getTransport() {
+    return this.transport;
+  }
+
+  public Codec<T> getCodec() {
+    return this.codec;
+  }
+
+  public Naming getNameClient() {
+    return this.nameClient;
+  }
+
+  public IdentifierFactory getIdentifierFactory() {
+    return this.factory;
+  }
+
+  void remove(final Identifier id) {
+    this.idToConnMap.remove(id);
+  }
+
+  @Override
+  public void close() throws Exception {
+    LOG.log(Level.FINE, "Shutting down");
+    this.transport.close();
+    this.nameClient.close();
+  }
+
+  @Override
+  public Connection<T> newConnection(final Identifier destId) {
+
+    if (this.myId == null) {
+      throw new RuntimeException(
+          "Trying to establish a connection from a Network Service that is not bound to any task");
+    }
+
+    final Connection<T> conn = this.idToConnMap.get(destId);
+    if (conn != null) {
+      return conn;
+    }
+
+    final Connection<T> newConnection = new NSConnection<T>(
+        this.myId, destId, new LinkListener<T>() {
+      @Override
+      public void messageReceived(final Object message) {
+      }
+    }, this);
+
+    final Connection<T> existing = this.idToConnMap.putIfAbsent(destId, newConnection);
+    return existing == null ? newConnection : existing;
+  }
+}
+
+class MessageHandler<T> implements EventHandler<TransportEvent> {
+
+  private final EventHandler<Message<T>> handler;
+  private final NSMessageCodec<T> codec;
+
+  public MessageHandler(final EventHandler<Message<T>> handler,
+                        final Codec<T> codec, final IdentifierFactory factory) {
+    this.handler = handler;
+    this.codec = new NSMessageCodec<T>(codec, factory);
+  }
+
+  @Override
+  public void onNext(final TransportEvent value) {
+    final byte[] data = value.getData();
+    final NSMessage<T> obj = this.codec.decode(data);
+    this.handler.onNext(obj);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NetworkServiceClosingHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NetworkServiceClosingHandler.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NetworkServiceClosingHandler.java
new file mode 100644
index 0000000..6e17922
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NetworkServiceClosingHandler.java
@@ -0,0 +1,43 @@
+/**
+ * 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.reef.io.network.impl;
+
+import org.apache.reef.evaluator.context.events.ContextStop;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+
+public class NetworkServiceClosingHandler implements EventHandler<ContextStop> {
+  private final NetworkService<?> networkService;
+
+  @Inject
+  public NetworkServiceClosingHandler(final NetworkService<?> networkService) {
+    this.networkService = networkService;
+  }
+
+  @Override
+  public void onNext(ContextStop arg0) {
+    try {
+      networkService.close();
+    } catch (Exception e) {
+      throw new RuntimeException("Exception while closing NetworkService", e);
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NetworkServiceParameters.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NetworkServiceParameters.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NetworkServiceParameters.java
new file mode 100644
index 0000000..a31c5de
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/NetworkServiceParameters.java
@@ -0,0 +1,60 @@
+/**
+ * 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.reef.io.network.impl;
+
+import org.apache.reef.io.network.TransportFactory;
+import org.apache.reef.io.network.util.StringIdentifierFactory;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.IdentifierFactory;
+import org.apache.reef.wake.remote.Codec;
+
+public class NetworkServiceParameters {
+
+  @NamedParameter
+  public static class TaskId implements Name<String> {
+
+  }
+
+  @NamedParameter(doc = "identifier factory for the service", short_name = "factory", default_class = StringIdentifierFactory.class)
+  public static class NetworkServiceIdentifierFactory implements Name<IdentifierFactory> {
+  }
+
+  @NamedParameter(doc = "port for the network service", short_name = "nsport", default_value = "7070")
+  public static class NetworkServicePort implements Name<Integer> {
+  }
+
+  @NamedParameter(doc = "codec for the network service", short_name = "nscodec")
+  public static class NetworkServiceCodec implements Name<Codec<?>> {
+  }
+
+  @NamedParameter(doc = "transport factory for the network service", short_name = "nstransportfactory", default_class = MessagingTransportFactory.class)
+  public static class NetworkServiceTransportFactory implements Name<TransportFactory> {
+  }
+
+  @NamedParameter(doc = "network receive handler for the network service", short_name = "nshandler")
+  public static class NetworkServiceHandler implements Name<EventHandler<?>> {
+  }
+
+  @NamedParameter(doc = "network exception handler for the network service", short_name = "exhandler")
+  public static class NetworkServiceExceptionHandler implements Name<EventHandler<?>> {
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/StreamingCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/StreamingCodec.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/StreamingCodec.java
new file mode 100644
index 0000000..ac669af
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/StreamingCodec.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.io.network.impl;
+
+import org.apache.reef.wake.remote.Codec;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+
+/**
+ * A codec that can make serialization more efficient when an object has to be
+ * codec'ed through a chain of codecs
+ */
+public interface StreamingCodec<T> extends Codec<T> {
+
+  void encodeToStream(T obj, DataOutputStream stream);
+
+  T decodeFromStream(DataInputStream stream);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/UnbindNSFromTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/UnbindNSFromTask.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/UnbindNSFromTask.java
new file mode 100644
index 0000000..df337d9
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/UnbindNSFromTask.java
@@ -0,0 +1,45 @@
+/**
+ * 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.reef.io.network.impl;
+
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.task.events.TaskStop;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.IdentifierFactory;
+
+import javax.inject.Inject;
+
+public class UnbindNSFromTask implements EventHandler<TaskStop> {
+
+  private final NetworkService<?> ns;
+  private final IdentifierFactory idFac;
+
+  @Inject
+  public UnbindNSFromTask(
+      final NetworkService<?> ns,
+      final @Parameter(NetworkServiceParameters.NetworkServiceIdentifierFactory.class) IdentifierFactory idFac) {
+    this.ns = ns;
+    this.idFac = idFac;
+  }
+
+  @Override
+  public void onNext(final TaskStop task) {
+    this.ns.unregisterId(this.idFac.getNewInstance(task.getId()));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/package-info.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/package-info.java
new file mode 100644
index 0000000..fbdc2ef
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/impl/package-info.java
@@ -0,0 +1,19 @@
+/**
+ * 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.reef.io.network.impl;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameAssignmentTuple.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameAssignmentTuple.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameAssignmentTuple.java
new file mode 100644
index 0000000..c7792fd
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameAssignmentTuple.java
@@ -0,0 +1,65 @@
+/**
+ * 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.reef.io.network.naming;
+
+import org.apache.reef.io.naming.NameAssignment;
+import org.apache.reef.wake.Identifier;
+
+import java.net.InetSocketAddress;
+
+/**
+ * An implementation of the NameAssignment interface
+ */
+public class NameAssignmentTuple implements NameAssignment {
+
+  private final Identifier id;
+  private final InetSocketAddress addr;
+
+  /**
+   * Constructs a name assignment tuple
+   *
+   * @param id   an identifier
+   * @param addr an Internet socket address
+   */
+  public NameAssignmentTuple(Identifier id, InetSocketAddress addr) {
+    this.id = id;
+    this.addr = addr;
+  }
+
+  /**
+   * Gets an identifier
+   *
+   * @return an identifier
+   */
+  @Override
+  public Identifier getIdentifier() {
+    return id;
+  }
+
+  /**
+   * Gets an address
+   *
+   * @return an Internet socket address
+   */
+  @Override
+  public InetSocketAddress getAddress() {
+    return addr;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameCache.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameCache.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameCache.java
new file mode 100644
index 0000000..384bfe4
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameCache.java
@@ -0,0 +1,72 @@
+/**
+ * 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.reef.io.network.naming;
+
+import com.google.common.cache.CacheBuilder;
+import org.apache.reef.io.network.Cache;
+import org.apache.reef.wake.Identifier;
+
+import java.net.InetSocketAddress;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Naming cache implementation
+ */
+public class NameCache implements Cache<Identifier, InetSocketAddress> {
+
+  private final com.google.common.cache.Cache<Identifier, InetSocketAddress> cache;
+
+  /**
+   * Constructs a naming cache
+   *
+   * @param timeout a cache entry timeout after access
+   */
+  public NameCache(long timeout) {
+    cache = CacheBuilder.newBuilder()
+        .expireAfterWrite(timeout, TimeUnit.MILLISECONDS)
+        .build();
+  }
+
+  /**
+   * Gets an address for an identifier
+   *
+   * @param key          an identifier
+   * @param valueFetcher a callable to load a value for the corresponding identifier
+   * @return an Internet socket address
+   * @throws ExecutionException
+   */
+  @Override
+  public InetSocketAddress get(Identifier key,
+                               Callable<InetSocketAddress> valueFetcher) throws ExecutionException {
+    return cache.get(key, valueFetcher);
+  }
+
+  /**
+   * Invalidates the entry for an identifier
+   *
+   * @param key an identifier
+   */
+  @Override
+  public void invalidate(Identifier key) {
+    cache.invalidate(key);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameClient.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameClient.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameClient.java
new file mode 100644
index 0000000..79b4a92
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameClient.java
@@ -0,0 +1,212 @@
+/**
+ * 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.reef.io.network.naming;
+
+import org.apache.reef.io.naming.Naming;
+import org.apache.reef.io.network.Cache;
+import org.apache.reef.io.network.naming.exception.NamingRuntimeException;
+import org.apache.reef.io.network.naming.serialization.NamingLookupResponse;
+import org.apache.reef.io.network.naming.serialization.NamingMessage;
+import org.apache.reef.io.network.naming.serialization.NamingRegisterResponse;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.Identifier;
+import org.apache.reef.wake.IdentifierFactory;
+import org.apache.reef.wake.Stage;
+import org.apache.reef.wake.impl.SyncStage;
+import org.apache.reef.wake.remote.Codec;
+import org.apache.reef.wake.remote.NetUtils;
+import org.apache.reef.wake.remote.impl.TransportEvent;
+import org.apache.reef.wake.remote.transport.Transport;
+import org.apache.reef.wake.remote.transport.netty.NettyMessagingTransport;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Naming client
+ */
+public class NameClient implements Stage, Naming {
+  private static final Logger LOG = Logger.getLogger(NameClient.class.getName());
+
+  private NameLookupClient lookupClient;
+  private NameRegistryClient registryClient;
+  private Transport transport;
+
+  /**
+   * Constructs a naming client
+   *
+   * @param serverAddr a server address
+   * @param serverPort a server port number
+   * @param factory    an identifier factory
+   * @param cache      a cache
+   */
+  public NameClient(String serverAddr, int serverPort,
+                    IdentifierFactory factory, int retryCount, int retryTimeout,
+                    Cache<Identifier, InetSocketAddress> cache) {
+    this(serverAddr, serverPort, 10000, factory, retryCount, retryTimeout, cache);
+  }
+
+  /**
+   * Constructs a naming client
+   *
+   * @param serverAddr a server address
+   * @param serverPort a server port number
+   * @param timeout    timeout in ms
+   * @param factory    an identifier factory
+   * @param cache      a cache
+   */
+  public NameClient(final String serverAddr, final int serverPort, final long timeout,
+                    final IdentifierFactory factory, final int retryCount, final int retryTimeout,
+                    final Cache<Identifier, InetSocketAddress> cache) {
+
+    final BlockingQueue<NamingLookupResponse> replyLookupQueue = new LinkedBlockingQueue<NamingLookupResponse>();
+    final BlockingQueue<NamingRegisterResponse> replyRegisterQueue = new LinkedBlockingQueue<NamingRegisterResponse>();
+    final Codec<NamingMessage> codec = NamingCodecFactory.createFullCodec(factory);
+
+    this.transport = new NettyMessagingTransport(NetUtils.getLocalAddress(), 0,
+        new SyncStage<>(new NamingClientEventHandler(
+            new NamingResponseHandler(replyLookupQueue, replyRegisterQueue), codec)),
+        null, retryCount, retryTimeout);
+
+    this.lookupClient = new NameLookupClient(serverAddr, serverPort, timeout,
+        factory, retryCount, retryTimeout, replyLookupQueue, this.transport, cache);
+
+    this.registryClient = new NameRegistryClient(serverAddr, serverPort, timeout,
+        factory, replyRegisterQueue, this.transport);
+  }
+
+  /**
+   * Registers an (identifier, address) mapping
+   *
+   * @param id   an identifier
+   * @param addr an Internet socket address
+   */
+  @Override
+  public void register(final Identifier id, final InetSocketAddress addr)
+      throws Exception {
+    LOG.log(Level.FINE, "Refister {0} : {1}", new Object[]{id, addr});
+    this.registryClient.register(id, addr);
+  }
+
+  /**
+   * Unregisters an identifier
+   *
+   * @param id an identifier
+   */
+  @Override
+  public void unregister(final Identifier id) throws IOException {
+    this.registryClient.unregister(id);
+  }
+
+  /**
+   * Finds an address for an identifier
+   *
+   * @param id an identifier
+   * @return an Internet socket address
+   */
+  @Override
+  public InetSocketAddress lookup(final Identifier id) throws Exception {
+    return this.lookupClient.lookup(id);
+  }
+
+  /**
+   * Retrieves an address for an identifier remotely
+   *
+   * @param id an identifier
+   * @return an Internet socket address
+   * @throws Exception
+   */
+  public InetSocketAddress remoteLookup(final Identifier id) throws Exception {
+    return this.lookupClient.remoteLookup(id);
+  }
+
+  /**
+   * Closes resources
+   */
+  @Override
+  public void close() throws Exception {
+
+    if (this.lookupClient != null) {
+      this.lookupClient.close();
+    }
+
+    if (this.registryClient != null) {
+      this.registryClient.close();
+    }
+
+    if (this.transport != null) {
+      this.transport.close();
+    }
+  }
+}
+
+/**
+ * Naming client transport event handler
+ */
+class NamingClientEventHandler implements EventHandler<TransportEvent> {
+
+  private static final Logger LOG = Logger.getLogger(NamingClientEventHandler.class.getName());
+
+  private final EventHandler<NamingMessage> handler;
+  private final Codec<NamingMessage> codec;
+
+  public NamingClientEventHandler(
+      final EventHandler<NamingMessage> handler, final Codec<NamingMessage> codec) {
+    this.handler = handler;
+    this.codec = codec;
+  }
+
+  @Override
+  public void onNext(final TransportEvent value) {
+    LOG.log(Level.FINE, "Transport: ", value);
+    this.handler.onNext(this.codec.decode(value.getData()));
+  }
+}
+
+/**
+ * Naming response message handler
+ */
+class NamingResponseHandler implements EventHandler<NamingMessage> {
+
+  private final BlockingQueue<NamingLookupResponse> replyLookupQueue;
+  private final BlockingQueue<NamingRegisterResponse> replyRegisterQueue;
+
+  NamingResponseHandler(BlockingQueue<NamingLookupResponse> replyLookupQueue,
+                        BlockingQueue<NamingRegisterResponse> replyRegisterQueue) {
+    this.replyLookupQueue = replyLookupQueue;
+    this.replyRegisterQueue = replyRegisterQueue;
+  }
+
+  @Override
+  public void onNext(NamingMessage value) {
+    if (value instanceof NamingLookupResponse) {
+      replyLookupQueue.offer((NamingLookupResponse) value);
+    } else if (value instanceof NamingRegisterResponse) {
+      replyRegisterQueue.offer((NamingRegisterResponse) value);
+    } else {
+      throw new NamingRuntimeException("Unknown naming response message");
+    }
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameLookupClient.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameLookupClient.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameLookupClient.java
new file mode 100644
index 0000000..31b7fca
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameLookupClient.java
@@ -0,0 +1,257 @@
+/**
+ * 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.reef.io.network.naming;
+
+import org.apache.reef.io.naming.NameAssignment;
+import org.apache.reef.io.naming.NamingLookup;
+import org.apache.reef.io.network.Cache;
+import org.apache.reef.io.network.naming.exception.NamingException;
+import org.apache.reef.io.network.naming.serialization.NamingLookupRequest;
+import org.apache.reef.io.network.naming.serialization.NamingLookupResponse;
+import org.apache.reef.io.network.naming.serialization.NamingMessage;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.Identifier;
+import org.apache.reef.wake.IdentifierFactory;
+import org.apache.reef.wake.Stage;
+import org.apache.reef.wake.impl.SyncStage;
+import org.apache.reef.wake.remote.Codec;
+import org.apache.reef.wake.remote.NetUtils;
+import org.apache.reef.wake.remote.impl.TransportEvent;
+import org.apache.reef.wake.remote.transport.Link;
+import org.apache.reef.wake.remote.transport.Transport;
+import org.apache.reef.wake.remote.transport.netty.LoggingLinkListener;
+import org.apache.reef.wake.remote.transport.netty.NettyMessagingTransport;
+
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.Callable;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Naming lookup client
+ */
+public class NameLookupClient implements Stage, NamingLookup {
+
+  private static final Logger LOG = Logger.getLogger(NameLookupClient.class.getName());
+  private final SocketAddress serverSocketAddr;
+  private final Transport transport;
+  private final Codec<NamingMessage> codec;
+  private final BlockingQueue<NamingLookupResponse> replyQueue;
+  private final long timeout;
+  private final Cache<Identifier, InetSocketAddress> cache;
+  private final int retryCount;
+  private final int retryTimeout;
+
+  /**
+   * Constructs a naming lookup client
+   *
+   * @param serverAddr a server address
+   * @param serverPort a server port number
+   * @param factory    an identifier factory
+   * @param cache      an cache
+   */
+  public NameLookupClient(final String serverAddr, final int serverPort,
+                          final IdentifierFactory factory, final int retryCount, final int retryTimeout,
+                          final Cache<Identifier, InetSocketAddress> cache) {
+    this(serverAddr, serverPort, 10000, factory, retryCount, retryTimeout, cache);
+  }
+
+  /**
+   * Constructs a naming lookup client
+   *
+   * @param serverAddr a server address
+   * @param serverPort a server port number
+   * @param timeout    request timeout in ms
+   * @param factory    an identifier factory
+   * @param cache      an cache
+   */
+  public NameLookupClient(final String serverAddr, final int serverPort, final long timeout,
+                          final IdentifierFactory factory, final int retryCount, final int retryTimeout,
+                          final Cache<Identifier, InetSocketAddress> cache) {
+
+    this.serverSocketAddr = new InetSocketAddress(serverAddr, serverPort);
+    this.timeout = timeout;
+    this.cache = cache;
+    this.codec = NamingCodecFactory.createLookupCodec(factory);
+    this.replyQueue = new LinkedBlockingQueue<>();
+
+    this.transport = new NettyMessagingTransport(NetUtils.getLocalAddress(), 0,
+        new SyncStage<>(new NamingLookupClientHandler(
+            new NamingLookupResponseHandler(this.replyQueue), this.codec)),
+        null, retryCount, retryTimeout);
+
+    this.retryCount = retryCount;
+    this.retryTimeout = retryTimeout;
+  }
+
+  NameLookupClient(final String serverAddr, final int serverPort, final long timeout,
+                   final IdentifierFactory factory, final int retryCount, final int retryTimeout,
+                   final BlockingQueue<NamingLookupResponse> replyQueue, final Transport transport,
+                   final Cache<Identifier, InetSocketAddress> cache) {
+
+    this.serverSocketAddr = new InetSocketAddress(serverAddr, serverPort);
+    this.timeout = timeout;
+    this.cache = cache;
+    this.codec = NamingCodecFactory.createFullCodec(factory);
+    this.replyQueue = replyQueue;
+    this.transport = transport;
+    this.retryCount = retryCount;
+    this.retryTimeout = retryTimeout;
+  }
+
+  /**
+   * Finds an address for an identifier
+   *
+   * @param id an identifier
+   * @return an Internet socket address
+   */
+  @Override
+  public InetSocketAddress lookup(final Identifier id) throws Exception {
+
+    return cache.get(id, new Callable<InetSocketAddress>() {
+
+      @Override
+      public InetSocketAddress call() throws Exception {
+        final int origRetryCount = NameLookupClient.this.retryCount;
+        int retryCount = origRetryCount;
+        while (true) {
+          try {
+            return remoteLookup(id);
+          } catch (final NamingException e) {
+            if (retryCount <= 0) {
+              throw e;
+            } else {
+              final int retryTimeout = NameLookupClient.this.retryTimeout
+                  * (origRetryCount - retryCount + 1);
+              LOG.log(Level.WARNING,
+                  "Caught Naming Exception while looking up " + id
+                      + " with Name Server. Will retry " + retryCount
+                      + " time(s) after waiting for " + retryTimeout + " msec.");
+              Thread.sleep(retryTimeout * retryCount);
+              --retryCount;
+            }
+          }
+        }
+      }
+
+    });
+  }
+
+  /**
+   * Retrieves an address for an identifier remotely
+   *
+   * @param id an identifier
+   * @return an Internet socket address
+   * @throws Exception
+   */
+  public InetSocketAddress remoteLookup(final Identifier id) throws Exception {
+    // the lookup is not thread-safe, because concurrent replies may
+    // be read by the wrong thread.
+    // TODO: better fix uses a map of id's after REEF-198
+    synchronized (this) {
+
+      LOG.log(Level.INFO, "Looking up {0} on NameServer {1}", new Object[]{id, serverSocketAddr});
+
+      final List<Identifier> ids = Arrays.asList(id);
+      final Link<NamingMessage> link = transport.open(serverSocketAddr, codec,
+          new LoggingLinkListener<NamingMessage>());
+      link.write(new NamingLookupRequest(ids));
+
+      final NamingLookupResponse resp;
+      for (; ; ) {
+        try {
+          resp = replyQueue.poll(timeout, TimeUnit.MILLISECONDS);
+          break;
+        } catch (final InterruptedException e) {
+          LOG.log(Level.INFO, "Lookup interrupted", e);
+          throw new NamingException(e);
+        }
+      }
+
+      final List<NameAssignment> list = resp.getNameAssignments();
+      if (list.isEmpty()) {
+        throw new NamingException("Cannot find " + id + " from the name server");
+      } else {
+        return list.get(0).getAddress();
+      }
+    }
+  }
+
+  /**
+   * Closes resources
+   */
+  @Override
+  public void close() throws Exception {
+    // Should not close transport as we did not
+    // create it
+  }
+
+  @NamedParameter(doc = "When should a retry timeout(msec)?", short_name = "retryTimeout", default_value = "100")
+  public static class RetryTimeout implements Name<Integer> {
+  }
+
+  @NamedParameter(doc = "How many times should I retry?", short_name = "retryCount", default_value = "10")
+  public static class RetryCount implements Name<Integer> {
+  }
+}
+
+/**
+ * Naming lookup client transport event handler
+ */
+class NamingLookupClientHandler implements EventHandler<TransportEvent> {
+
+  private final EventHandler<NamingLookupResponse> handler;
+  private final Codec<NamingMessage> codec;
+
+  NamingLookupClientHandler(final EventHandler<NamingLookupResponse> handler, final Codec<NamingMessage> codec) {
+    this.handler = handler;
+    this.codec = codec;
+  }
+
+  @Override
+  public void onNext(final TransportEvent value) {
+    handler.onNext((NamingLookupResponse) codec.decode(value.getData()));
+  }
+
+}
+
+/**
+ * Naming lookup response handler
+ */
+class NamingLookupResponseHandler implements EventHandler<NamingLookupResponse> {
+
+  private final BlockingQueue<NamingLookupResponse> replyQueue;
+
+  NamingLookupResponseHandler(final BlockingQueue<NamingLookupResponse> replyQueue) {
+    this.replyQueue = replyQueue;
+  }
+
+  @Override
+  public void onNext(final NamingLookupResponse value) {
+    replyQueue.offer(value);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameRegistryClient.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameRegistryClient.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameRegistryClient.java
new file mode 100644
index 0000000..554a33b
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameRegistryClient.java
@@ -0,0 +1,200 @@
+/**
+ * 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.reef.io.network.naming;
+
+import org.apache.reef.io.naming.NamingRegistry;
+import org.apache.reef.io.network.naming.exception.NamingException;
+import org.apache.reef.io.network.naming.serialization.NamingMessage;
+import org.apache.reef.io.network.naming.serialization.NamingRegisterRequest;
+import org.apache.reef.io.network.naming.serialization.NamingRegisterResponse;
+import org.apache.reef.io.network.naming.serialization.NamingUnregisterRequest;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.Identifier;
+import org.apache.reef.wake.IdentifierFactory;
+import org.apache.reef.wake.Stage;
+import org.apache.reef.wake.impl.SyncStage;
+import org.apache.reef.wake.remote.Codec;
+import org.apache.reef.wake.remote.NetUtils;
+import org.apache.reef.wake.remote.impl.TransportEvent;
+import org.apache.reef.wake.remote.transport.Link;
+import org.apache.reef.wake.remote.transport.LinkListener;
+import org.apache.reef.wake.remote.transport.Transport;
+import org.apache.reef.wake.remote.transport.netty.LoggingLinkListener;
+import org.apache.reef.wake.remote.transport.netty.NettyMessagingTransport;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Naming registry client
+ */
+public class NameRegistryClient implements Stage, NamingRegistry {
+
+  private static final Logger LOG = Logger.getLogger(NameRegistryClient.class.getName());
+
+  private final SocketAddress serverSocketAddr;
+  private final Transport transport;
+  private final Codec<NamingMessage> codec;
+  private final BlockingQueue<NamingRegisterResponse> replyQueue;
+  private final long timeout;
+
+  /**
+   * Constructs a naming registry client
+   *
+   * @param serverAddr a name server address
+   * @param serverPort a name server port
+   * @param factory    an identifier factory
+   */
+  public NameRegistryClient(
+      final String serverAddr, final int serverPort, final IdentifierFactory factory) {
+    this(serverAddr, serverPort, 10000, factory);
+  }
+
+  /**
+   * Constructs a naming registry client
+   *
+   * @param serverAddr a name server address
+   * @param serverPort a name server port
+   * @param timeout    timeout in ms
+   * @param factory    an identifier factory
+   */
+  public NameRegistryClient(final String serverAddr, final int serverPort,
+                            final long timeout, final IdentifierFactory factory) {
+
+    this.serverSocketAddr = new InetSocketAddress(serverAddr, serverPort);
+    this.timeout = timeout;
+    this.codec = NamingCodecFactory.createRegistryCodec(factory);
+    this.replyQueue = new LinkedBlockingQueue<>();
+    this.transport = new NettyMessagingTransport(NetUtils.getLocalAddress(), 0,
+        new SyncStage<>(new NamingRegistryClientHandler(new NamingRegistryResponseHandler(replyQueue), codec)),
+        null, 3, 10000);
+  }
+
+  public NameRegistryClient(final String serverAddr, final int serverPort,
+                            final long timeout, final IdentifierFactory factory,
+                            final BlockingQueue<NamingRegisterResponse> replyQueue,
+                            final Transport transport) {
+    this.serverSocketAddr = new InetSocketAddress(serverAddr, serverPort);
+    this.timeout = timeout;
+    this.codec = NamingCodecFactory.createFullCodec(factory);
+    this.replyQueue = replyQueue;
+    this.transport = transport;
+  }
+
+  /**
+   * Registers an (identifier, address) mapping
+   *
+   * @param id   an identifier
+   * @param addr an Internet socket address
+   */
+  @Override
+  public void register(final Identifier id, final InetSocketAddress addr) throws Exception {
+
+    // needed to keep threads from reading the wrong response
+    // TODO: better fix matches replies to threads with a map after REEF-198
+    synchronized (this) {
+
+      LOG.log(Level.FINE, "Register {0} : {1}", new Object[]{id, addr});
+
+      final Link<NamingMessage> link = this.transport.open(
+          this.serverSocketAddr, this.codec, new LoggingLinkListener<NamingMessage>());
+
+      link.write(new NamingRegisterRequest(new NameAssignmentTuple(id, addr)));
+
+      for (; ; ) {
+        try {
+          this.replyQueue.poll(this.timeout, TimeUnit.MILLISECONDS);
+          break;
+        } catch (final InterruptedException e) {
+          LOG.log(Level.INFO, "Interrupted", e);
+          throw new NamingException(e);
+        }
+      }
+    }
+  }
+
+  /**
+   * Unregisters an identifier
+   *
+   * @param id an identifier
+   */
+  @Override
+  public void unregister(Identifier id) throws IOException {
+    Link<NamingMessage> link = transport.open(serverSocketAddr, codec,
+        new LinkListener<NamingMessage>() {
+          @Override
+          public void messageReceived(NamingMessage message) {
+          }
+        });
+    link.write(new NamingUnregisterRequest(id));
+  }
+
+  /**
+   * Closes resources
+   */
+  @Override
+  public void close() throws Exception {
+    // Should not close transport as we did not
+    // create it
+  }
+}
+
+/**
+ * Naming registry client transport event handler
+ */
+class NamingRegistryClientHandler implements EventHandler<TransportEvent> {
+  private static final Logger LOG = Logger.getLogger(NamingRegistryClientHandler.class.getName());
+
+  private final EventHandler<NamingRegisterResponse> handler;
+  private final Codec<NamingMessage> codec;
+
+  NamingRegistryClientHandler(EventHandler<NamingRegisterResponse> handler, Codec<NamingMessage> codec) {
+    this.handler = handler;
+    this.codec = codec;
+  }
+
+  @Override
+  public void onNext(TransportEvent value) {
+    LOG.log(Level.FINE, value.toString());
+    handler.onNext((NamingRegisterResponse) codec.decode(value.getData()));
+  }
+}
+
+/**
+ * Naming register response handler
+ */
+class NamingRegistryResponseHandler implements EventHandler<NamingRegisterResponse> {
+
+  private final BlockingQueue<NamingRegisterResponse> replyQueue;
+
+  NamingRegistryResponseHandler(BlockingQueue<NamingRegisterResponse> replyQueue) {
+    this.replyQueue = replyQueue;
+  }
+
+  @Override
+  public void onNext(NamingRegisterResponse value) {
+    replyQueue.offer(value);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameServer.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameServer.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameServer.java
new file mode 100644
index 0000000..5a4c765
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameServer.java
@@ -0,0 +1,88 @@
+/**
+ * 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.reef.io.network.naming;
+
+import org.apache.reef.io.naming.NameAssignment;
+import org.apache.reef.io.network.naming.serialization.*;
+import org.apache.reef.tang.annotations.DefaultImplementation;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.Identifier;
+import org.apache.reef.wake.IdentifierFactory;
+import org.apache.reef.wake.Stage;
+import org.apache.reef.wake.impl.MultiEventHandler;
+import org.apache.reef.wake.impl.SyncStage;
+import org.apache.reef.wake.remote.Codec;
+import org.apache.reef.wake.remote.NetUtils;
+import org.apache.reef.wake.remote.impl.TransportEvent;
+import org.apache.reef.wake.remote.transport.Transport;
+import org.apache.reef.wake.remote.transport.netty.NettyMessagingTransport;
+import org.apache.reef.webserver.AvroReefServiceInfo;
+import org.apache.reef.webserver.ReefEventStateManager;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Naming server interface
+ */
+public interface NameServer extends Stage {
+
+  /**
+   * get port number
+   * @return
+   */
+  public int getPort();
+
+  /**
+   * Registers an (identifier, address) mapping locally
+   *
+   * @param id   an identifier
+   * @param addr an Internet socket address
+   */
+  public void register(final Identifier id, final InetSocketAddress addr);
+
+  /**
+   * Unregisters an identifier locally
+   *
+   * @param id an identifier
+   */
+  public void unregister(final Identifier id);
+
+  /**
+   * Finds an address for an identifier locally
+   *
+   * @param id an identifier
+   * @return an Internet socket address
+   */
+  public InetSocketAddress lookup(final Identifier id);
+
+  /**
+   * Finds addresses for identifiers locally
+   *
+   * @param identifiers an Iterable of identifiers
+   * @return a list of name assignments
+   */
+  public List<NameAssignment> lookup(final Iterable<Identifier> identifiers);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameServerConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameServerConfiguration.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameServerConfiguration.java
new file mode 100644
index 0000000..1912686
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameServerConfiguration.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.reef.io.network.naming;
+
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.OptionalParameter;
+import org.apache.reef.wake.IdentifierFactory;
+
+/**
+ * Configuration Module Builder for NameServer
+ */
+public final class NameServerConfiguration extends ConfigurationModuleBuilder {
+
+  /**
+   * The port used by name server
+   */
+  public static final OptionalParameter<Integer> NAME_SERVICE_PORT = new OptionalParameter<>();
+  /**
+   * DNS hostname running the name service
+   */
+  public static final OptionalParameter<String> NAME_SERVER_HOSTNAME = new OptionalParameter<>();
+  /**
+   * Identifier factory for the name service
+   */
+  public static final OptionalParameter<IdentifierFactory> NAME_SERVER_IDENTIFIER_FACTORY = new OptionalParameter<>();
+
+  public static final ConfigurationModule CONF = new NameServerConfiguration()
+      .bindNamedParameter(NameServerParameters.NameServerPort.class, NAME_SERVICE_PORT)
+      .bindNamedParameter(NameServerParameters.NameServerAddr.class, NAME_SERVER_HOSTNAME)
+      .bindNamedParameter(NameServerParameters.NameServerIdentifierFactory.class, NAME_SERVER_IDENTIFIER_FACTORY)
+      .bindImplementation(NameServer.class, NameServerImpl.class)
+      .build();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameServerImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameServerImpl.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameServerImpl.java
new file mode 100644
index 0000000..306682a
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameServerImpl.java
@@ -0,0 +1,300 @@
+/**
+ * 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.reef.io.network.naming;
+
+import org.apache.reef.io.naming.NameAssignment;
+import org.apache.reef.io.network.naming.serialization.*;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.Identifier;
+import org.apache.reef.wake.IdentifierFactory;
+import org.apache.reef.wake.Stage;
+import org.apache.reef.wake.impl.MultiEventHandler;
+import org.apache.reef.wake.impl.SyncStage;
+import org.apache.reef.wake.remote.Codec;
+import org.apache.reef.wake.remote.NetUtils;
+import org.apache.reef.wake.remote.impl.TransportEvent;
+import org.apache.reef.wake.remote.transport.Transport;
+import org.apache.reef.wake.remote.transport.netty.NettyMessagingTransport;
+import org.apache.reef.webserver.AvroReefServiceInfo;
+import org.apache.reef.webserver.ReefEventStateManager;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Naming server implementation
+ */
+public class NameServerImpl implements NameServer {
+
+  private static final Logger LOG = Logger.getLogger(NameServer.class.getName());
+
+  private final Transport transport;
+  private final Map<Identifier, InetSocketAddress> idToAddrMap;
+  private final ReefEventStateManager reefEventStateManager;
+  private final int port;
+
+  /**
+   * @param port    a listening port number
+   * @param factory an identifier factory
+   * @deprecated inject the NameServer instead of new it up
+   * Constructs a name server
+   */
+  // TODO: All existing NameServer usage is currently new-up, need to make them injected as well.
+  @Deprecated
+  public NameServerImpl(
+      final int port,
+      final IdentifierFactory factory) {
+
+    this.reefEventStateManager = null;
+    final Codec<NamingMessage> codec = NamingCodecFactory.createFullCodec(factory);
+    final EventHandler<NamingMessage> handler = createEventHandler(codec);
+
+    this.transport = new NettyMessagingTransport(NetUtils.getLocalAddress(), port, null,
+        new SyncStage<>(new NamingServerHandler(handler, codec)), 3, 10000);
+
+    this.port = transport.getListeningPort();
+    this.idToAddrMap = Collections.synchronizedMap(new HashMap<Identifier, InetSocketAddress>());
+
+    LOG.log(Level.FINE, "NameServer starting, listening at port {0}", this.port);
+  }
+
+
+  /**
+   * Constructs a name server
+   *
+   * @param port                  a listening port number
+   * @param factory               an identifier factory
+   * @param reefEventStateManager the event state manager used to register name server info
+   */
+  @Inject
+  public NameServerImpl(
+      final @Parameter(NameServerParameters.NameServerPort.class) int port,
+      final @Parameter(NameServerParameters.NameServerIdentifierFactory.class) IdentifierFactory factory,
+      final ReefEventStateManager reefEventStateManager) {
+
+    this.reefEventStateManager = reefEventStateManager;
+    final Codec<NamingMessage> codec = NamingCodecFactory.createFullCodec(factory);
+    final EventHandler<NamingMessage> handler = createEventHandler(codec);
+
+    this.transport = new NettyMessagingTransport(NetUtils.getLocalAddress(), port, null,
+        new SyncStage<>(new NamingServerHandler(handler, codec)), 3, 10000);
+
+    this.port = transport.getListeningPort();
+    this.idToAddrMap = Collections.synchronizedMap(new HashMap<Identifier, InetSocketAddress>());
+
+    this.reefEventStateManager.registerServiceInfo(
+        AvroReefServiceInfo.newBuilder()
+            .setServiceName("NameServer")
+            .setServiceInfo(getNameServerId())
+            .build());
+    LOG.log(Level.FINE, "NameServer starting, listening at port {0}", this.port);
+  }
+
+  private EventHandler<NamingMessage> createEventHandler(final Codec<NamingMessage> codec) {
+
+    final Map<Class<? extends NamingMessage>, EventHandler<? extends NamingMessage>>
+        clazzToHandlerMap = new HashMap<>();
+
+    clazzToHandlerMap.put(NamingLookupRequest.class, new NamingLookupRequestHandler(this, codec));
+    clazzToHandlerMap.put(NamingRegisterRequest.class, new NamingRegisterRequestHandler(this, codec));
+    clazzToHandlerMap.put(NamingUnregisterRequest.class, new NamingUnregisterRequestHandler(this));
+    final EventHandler<NamingMessage> handler = new MultiEventHandler<>(clazzToHandlerMap);
+
+    return handler;
+  }
+
+  /**
+   * Gets port
+   */
+  @Override
+  public int getPort() {
+    return port;
+  }
+
+  /**
+   * Closes resources
+   */
+  @Override
+  public void close() throws Exception {
+    transport.close();
+  }
+
+  /**
+   * Registers an (identifier, address) mapping locally
+   *
+   * @param id   an identifier
+   * @param addr an Internet socket address
+   */
+  @Override
+  public void register(final Identifier id, final InetSocketAddress addr) {
+    LOG.log(Level.FINE, "id: " + id + " addr: " + addr);
+    idToAddrMap.put(id, addr);
+  }
+
+  /**
+   * Unregisters an identifier locally
+   *
+   * @param id an identifier
+   */
+  @Override
+  public void unregister(final Identifier id) {
+    LOG.log(Level.FINE, "id: " + id);
+    idToAddrMap.remove(id);
+  }
+
+  /**
+   * Finds an address for an identifier locally
+   *
+   * @param id an identifier
+   * @return an Internet socket address
+   */
+  @Override
+  public InetSocketAddress lookup(final Identifier id) {
+    LOG.log(Level.FINE, "id: {0}", id);
+    return idToAddrMap.get(id);
+  }
+
+  /**
+   * Finds addresses for identifiers locally
+   *
+   * @param identifiers an iterable of identifiers
+   * @return a list of name assignments
+   */
+  @Override
+  public List<NameAssignment> lookup(final Iterable<Identifier> identifiers) {
+    LOG.log(Level.FINE, "identifiers");
+    final List<NameAssignment> nas = new ArrayList<>();
+    for (final Identifier id : identifiers) {
+      final InetSocketAddress addr = idToAddrMap.get(id);
+      LOG.log(Level.FINEST, "id : {0} addr: {1}", new Object[]{id, addr});
+      if (addr != null) {
+        nas.add(new NameAssignmentTuple(id, addr));
+      }
+    }
+    return nas;
+  }
+
+  private String getNameServerId() {
+    return NetUtils.getLocalAddress() + ":" + getPort();
+  }
+}
+
+/**
+ * Naming server transport event handler that invokes a specific naming message handler
+ */
+class NamingServerHandler implements EventHandler<TransportEvent> {
+
+  private final Codec<NamingMessage> codec;
+  private final EventHandler<NamingMessage> handler;
+
+  NamingServerHandler(final EventHandler<NamingMessage> handler, final Codec<NamingMessage> codec) {
+    this.codec = codec;
+    this.handler = handler;
+  }
+
+  @Override
+  public void onNext(final TransportEvent value) {
+    final byte[] data = value.getData();
+    final NamingMessage message = codec.decode(data);
+    message.setLink(value.getLink());
+    handler.onNext(message);
+  }
+}
+
+/**
+ * Naming lookup request handler
+ */
+class NamingLookupRequestHandler implements EventHandler<NamingLookupRequest> {
+
+  private static final Logger LOG = Logger.getLogger(NamingLookupRequestHandler.class.getName());
+
+
+  private final NameServer server;
+  private final Codec<NamingMessage> codec;
+
+  public NamingLookupRequestHandler(final NameServer server, final Codec<NamingMessage> codec) {
+    this.server = server;
+    this.codec = codec;
+  }
+
+  @Override
+  public void onNext(final NamingLookupRequest value) {
+    final List<NameAssignment> nas = server.lookup(value.getIdentifiers());
+    final byte[] resp = codec.encode(new NamingLookupResponse(nas));
+    try {
+      value.getLink().write(resp);
+    } catch (final IOException e) {
+      //Actually, there is no way Link.write can throw and IOException
+      //after netty4 merge. This needs to cleaned up
+      LOG.throwing("NamingLookupRequestHandler", "onNext", e);
+    }
+  }
+}
+
+/**
+ * Naming register request handler
+ */
+class NamingRegisterRequestHandler implements EventHandler<NamingRegisterRequest> {
+
+  private static final Logger LOG = Logger.getLogger(NamingRegisterRequestHandler.class.getName());
+
+
+  private final NameServer server;
+  private final Codec<NamingMessage> codec;
+
+  public NamingRegisterRequestHandler(final NameServer server, final Codec<NamingMessage> codec) {
+    this.server = server;
+    this.codec = codec;
+  }
+
+  @Override
+  public void onNext(final NamingRegisterRequest value) {
+    server.register(value.getNameAssignment().getIdentifier(), value.getNameAssignment().getAddress());
+    final byte[] resp = codec.encode(new NamingRegisterResponse(value));
+    try {
+      value.getLink().write(resp);
+    } catch (final IOException e) {
+      //Actually, there is no way Link.write can throw and IOException
+      //after netty4 merge. This needs to cleaned up
+      LOG.throwing("NamingRegisterRequestHandler", "onNext", e);
+    }
+  }
+}
+
+/**
+ * Naming unregister request handler
+ */
+class NamingUnregisterRequestHandler implements EventHandler<NamingUnregisterRequest> {
+
+  private final NameServer server;
+
+  public NamingUnregisterRequestHandler(final NameServer server) {
+    this.server = server;
+  }
+
+  @Override
+  public void onNext(final NamingUnregisterRequest value) {
+    server.unregister(value.getIdentifier());
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameServerParameters.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameServerParameters.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameServerParameters.java
new file mode 100644
index 0000000..1888886
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NameServerParameters.java
@@ -0,0 +1,40 @@
+/**
+ * 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.reef.io.network.naming;
+
+import org.apache.reef.io.network.util.StringIdentifierFactory;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.IdentifierFactory;
+
+public class NameServerParameters {
+
+  @NamedParameter(doc = "port for the name service", default_value = "0", short_name = "nameport")
+  public class NameServerPort implements Name<Integer> {
+  }
+
+  @NamedParameter(doc = "DNS hostname running the name service")
+  public class NameServerAddr implements Name<String> {
+  }
+
+  @NamedParameter(doc = "identifier factory for the name service", default_class = StringIdentifierFactory.class)
+  public class NameServerIdentifierFactory implements Name<IdentifierFactory> {
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NamingCodecFactory.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NamingCodecFactory.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NamingCodecFactory.java
new file mode 100644
index 0000000..8ec320a
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/NamingCodecFactory.java
@@ -0,0 +1,82 @@
+/**
+ * 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.reef.io.network.naming;
+
+import org.apache.reef.io.network.naming.serialization.*;
+import org.apache.reef.wake.IdentifierFactory;
+import org.apache.reef.wake.remote.Codec;
+import org.apache.reef.wake.remote.impl.MultiCodec;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Factory to create naming codecs
+ */
+class NamingCodecFactory {
+
+  /**
+   * Creates a codec only for lookup
+   *
+   * @param factory an identifier factory
+   * @return a codec
+   */
+  static Codec<NamingMessage> createLookupCodec(IdentifierFactory factory) {
+    Map<Class<? extends NamingMessage>, Codec<? extends NamingMessage>> clazzToCodecMap
+        = new HashMap<Class<? extends NamingMessage>, Codec<? extends NamingMessage>>();
+    clazzToCodecMap.put(NamingLookupRequest.class, new NamingLookupRequestCodec(factory));
+    clazzToCodecMap.put(NamingLookupResponse.class, new NamingLookupResponseCodec(factory));
+    Codec<NamingMessage> codec = new MultiCodec<NamingMessage>(clazzToCodecMap);
+    return codec;
+  }
+
+  /**
+   * Creates a codec only for registration
+   *
+   * @param factory an identifier factory
+   * @return a codec
+   */
+  static Codec<NamingMessage> createRegistryCodec(IdentifierFactory factory) {
+    Map<Class<? extends NamingMessage>, Codec<? extends NamingMessage>> clazzToCodecMap
+        = new HashMap<Class<? extends NamingMessage>, Codec<? extends NamingMessage>>();
+    clazzToCodecMap.put(NamingRegisterRequest.class, new NamingRegisterRequestCodec(factory));
+    clazzToCodecMap.put(NamingRegisterResponse.class, new NamingRegisterResponseCodec(new NamingRegisterRequestCodec(factory)));
+    clazzToCodecMap.put(NamingUnregisterRequest.class, new NamingUnregisterRequestCodec(factory));
+    Codec<NamingMessage> codec = new MultiCodec<NamingMessage>(clazzToCodecMap);
+    return codec;
+  }
+
+  /**
+   * Creates a codec for both lookup and registration
+   *
+   * @param factory an identifier factory
+   * @return a codec
+   */
+  static Codec<NamingMessage> createFullCodec(IdentifierFactory factory) {
+    Map<Class<? extends NamingMessage>, Codec<? extends NamingMessage>> clazzToCodecMap
+        = new HashMap<Class<? extends NamingMessage>, Codec<? extends NamingMessage>>();
+    clazzToCodecMap.put(NamingLookupRequest.class, new NamingLookupRequestCodec(factory));
+    clazzToCodecMap.put(NamingLookupResponse.class, new NamingLookupResponseCodec(factory));
+    clazzToCodecMap.put(NamingRegisterRequest.class, new NamingRegisterRequestCodec(factory));
+    clazzToCodecMap.put(NamingRegisterResponse.class, new NamingRegisterResponseCodec(new NamingRegisterRequestCodec(factory)));
+    clazzToCodecMap.put(NamingUnregisterRequest.class, new NamingUnregisterRequestCodec(factory));
+    Codec<NamingMessage> codec = new MultiCodec<NamingMessage>(clazzToCodecMap);
+    return codec;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/exception/NamingException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/exception/NamingException.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/exception/NamingException.java
new file mode 100644
index 0000000..b5093b4
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/exception/NamingException.java
@@ -0,0 +1,56 @@
+/**
+ * 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.reef.io.network.naming.exception;
+
+import org.apache.reef.exception.evaluator.NetworkException;
+
+/**
+ * Naming exception
+ */
+public class NamingException extends NetworkException {
+  private static final long serialVersionUID = 1L;
+
+  /**
+   * Constructs a new resourcemanager naming exception with the specified detail message and cause
+   *
+   * @param s the detailed message
+   * @param e the cause
+   */
+  public NamingException(String s, Throwable e) {
+    super(s, e);
+  }
+
+  /**
+   * Constructs a new resourcemanager naming exception with the specified detail message
+   *
+   * @param s the detailed message
+   */
+  public NamingException(String s) {
+    super(s);
+  }
+
+  /**
+   * Constructs a new resourcemanager naming exception with the specified cause
+   *
+   * @param e the cause
+   */
+  public NamingException(Throwable e) {
+    super(e);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/exception/NamingRuntimeException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/exception/NamingRuntimeException.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/exception/NamingRuntimeException.java
new file mode 100644
index 0000000..9ed0f49
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/exception/NamingRuntimeException.java
@@ -0,0 +1,56 @@
+/**
+ * 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.reef.io.network.naming.exception;
+
+import org.apache.reef.io.network.exception.NetworkRuntimeException;
+
+/**
+ * Naming resourcemanager exception
+ */
+public class NamingRuntimeException extends NetworkRuntimeException {
+  private static final long serialVersionUID = 1L;
+
+  /**
+   * Constructs a new resourcemanager naming exception with the specified detail message and cause
+   *
+   * @param s the detailed message
+   * @param e the cause
+   */
+  public NamingRuntimeException(String s, Throwable e) {
+    super(s, e);
+  }
+
+  /**
+   * Constructs a new resourcemanager naming exception with the specified detail message
+   *
+   * @param s the detailed message
+   */
+  public NamingRuntimeException(String s) {
+    super(s);
+  }
+
+  /**
+   * Constructs a new resourcemanager naming exception with the specified cause
+   *
+   * @param e the cause
+   */
+  public NamingRuntimeException(Throwable e) {
+    super(e);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/exception/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/exception/package-info.java b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/exception/package-info.java
new file mode 100644
index 0000000..86741b8
--- /dev/null
+++ b/lang/java/reef-io/src/main/java/org/apache/reef/io/network/naming/exception/package-info.java
@@ -0,0 +1,19 @@
+/**
+ * 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.reef.io.network.naming.exception;
\ No newline at end of file


[42/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/RunningTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/RunningTask.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/RunningTask.java
new file mode 100644
index 0000000..5121c31
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/RunningTask.java
@@ -0,0 +1,73 @@
+/**
+ * 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.reef.driver.task;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.io.naming.Identifiable;
+
+/**
+ * Represents a running Task
+ */
+@DriverSide
+@Public
+@Provided
+public interface RunningTask extends Identifiable, AutoCloseable {
+
+
+  /**
+   * @return the context the task is running on.
+   */
+  public ActiveContext getActiveContext();
+
+
+  /**
+   * Sends the message to the running task.
+   *
+   * @param message to be sent to the running task
+   */
+  public void send(final byte[] message);
+
+  /**
+   * Signal the task to suspend.
+   *
+   * @param message a message that is sent to the Task.
+   */
+  public void suspend(final byte[] message);
+
+  /**
+   * Signal the task to suspend.
+   */
+  public void suspend();
+
+  /**
+   * Signal the task to shut down.
+   *
+   * @param message a message that is sent to the Task.
+   */
+  public void close(final byte[] message);
+
+  /**
+   * Signal the task to shut down.
+   */
+  @Override
+  public void close();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/SuspendedTask.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/SuspendedTask.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/SuspendedTask.java
new file mode 100644
index 0000000..0c88b3a
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/SuspendedTask.java
@@ -0,0 +1,41 @@
+/**
+ * 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.reef.driver.task;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.io.Message;
+import org.apache.reef.io.naming.Identifiable;
+
+/**
+ * Represents a suspended Task.
+ */
+@DriverSide
+@Public
+@Provided
+public interface SuspendedTask extends Message, Identifiable {
+  /**
+   * @return the context the task ran on. This context is now available to run another task or to spwan new
+   * child context
+   */
+  public ActiveContext getActiveContext();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/TaskConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/TaskConfiguration.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/TaskConfiguration.java
new file mode 100644
index 0000000..3735993
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/TaskConfiguration.java
@@ -0,0 +1,92 @@
+/**
+ * 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.reef.driver.task;
+
+import org.apache.reef.tang.formats.*;
+import org.apache.reef.task.Task;
+import org.apache.reef.task.TaskMessageSource;
+import org.apache.reef.task.events.*;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ * A ConfigurationModule to fill out to generate legal task Configurations that can be submitted.
+ */
+public class TaskConfiguration extends ConfigurationModuleBuilder {
+
+  /**
+   * Identifier for the task.
+   */
+  public static final RequiredParameter<String> IDENTIFIER = new RequiredParameter<>();
+
+  /**
+   * The task to instantiate.
+   */
+  public static final RequiredImpl<Task> TASK = new RequiredImpl<>();
+
+  /**
+   * Handler for task suspension. Defaults to task failure if not bound.
+   */
+  public static final OptionalImpl<EventHandler<SuspendEvent>> ON_SUSPEND = new OptionalImpl<>();
+
+  /**
+   * Handler for messages from the driver. Defaults to task failure if not bound.
+   */
+  public static final OptionalImpl<EventHandler<DriverMessage>> ON_MESSAGE = new OptionalImpl<>();
+
+  /**
+   * Handler for closure requests from the driver. Defaults to task failure if not bound.
+   */
+  public static final OptionalImpl<EventHandler<CloseEvent>> ON_CLOSE = new OptionalImpl<>();
+
+  /**
+   * The Base64 encoded memento to be passed to Task.call().
+   * You can do the encoding for example via DatatypeConverter.printBase64Binary()
+   */
+  public static final OptionalParameter<String> MEMENTO = new OptionalParameter<>();
+
+  /**
+   * Message source invoked upon each evaluator heartbeat.
+   */
+  public static final OptionalImpl<TaskMessageSource> ON_SEND_MESSAGE = new OptionalImpl<>();
+
+  /**
+   * Event handler to receive TaskStart after the Task.call() method was called.
+   */
+  public static final OptionalImpl<EventHandler<TaskStart>> ON_TASK_STARTED = new OptionalImpl<>();
+
+  /**
+   * Event handler to receive TaskStop after the Task.call() method returned.
+   */
+  public static final OptionalImpl<EventHandler<TaskStop>> ON_TASK_STOP = new OptionalImpl<>();
+
+  /**
+   * ConfigurationModule to fill out for a Task configuration.
+   */
+  public static final ConfigurationModule CONF = new TaskConfiguration()
+      .bindNamedParameter(TaskConfigurationOptions.Identifier.class, IDENTIFIER)
+      .bindImplementation(Task.class, TASK)
+      .bindNamedParameter(TaskConfigurationOptions.Memento.class, MEMENTO)
+      .bindNamedParameter(TaskConfigurationOptions.CloseHandler.class, ON_CLOSE)
+      .bindNamedParameter(TaskConfigurationOptions.SuspendHandler.class, ON_SUSPEND)
+      .bindNamedParameter(TaskConfigurationOptions.MessageHandler.class, ON_MESSAGE)
+      .bindSetEntry(TaskConfigurationOptions.TaskMessageSources.class, ON_SEND_MESSAGE)
+      .bindSetEntry(TaskConfigurationOptions.StartHandlers.class, ON_TASK_STARTED)
+      .bindSetEntry(TaskConfigurationOptions.StopHandlers.class, ON_TASK_STOP)
+      .build();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/TaskConfigurationOptions.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/TaskConfigurationOptions.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/TaskConfigurationOptions.java
new file mode 100644
index 0000000..73caf0a
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/TaskConfigurationOptions.java
@@ -0,0 +1,77 @@
+/**
+ * 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.reef.driver.task;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.runtime.common.evaluator.task.defaults.DefaultCloseHandler;
+import org.apache.reef.runtime.common.evaluator.task.defaults.DefaultDriverMessageHandler;
+import org.apache.reef.runtime.common.evaluator.task.defaults.DefaultSuspendHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.task.TaskMessageSource;
+import org.apache.reef.task.events.*;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * Configuration parameters for the TaskConfiguration class.
+ */
+@Public
+@DriverSide
+@Provided
+public final class TaskConfigurationOptions {
+
+  @NamedParameter(default_value = "Unnamed Task", doc = "The Identifier of the Task")
+  public static final class Identifier implements Name<String> {
+  }
+
+  @NamedParameter(doc = "The memento to be used for the Task.")
+  public final class Memento implements Name<String> {
+  }
+
+  @NamedParameter(doc = "TaskMessageSource instances.")
+  public final class TaskMessageSources implements Name<Set<TaskMessageSource>> {
+  }
+
+  @NamedParameter(doc = "The set of event handlers for the TaskStart event.")
+  public final class StartHandlers implements Name<Set<EventHandler<TaskStart>>> {
+  }
+
+  @NamedParameter(doc = "The set of event handlers for the TaskStop event.")
+  public final class StopHandlers implements Name<Set<EventHandler<TaskStop>>> {
+  }
+
+  @NamedParameter(doc = "The event handler that receives the close event",
+      default_class = DefaultCloseHandler.class)
+  public final class CloseHandler implements Name<EventHandler<CloseEvent>> {
+  }
+
+  @NamedParameter(doc = "The event handler that receives the suspend event",
+      default_class = DefaultSuspendHandler.class)
+  public final class SuspendHandler implements Name<EventHandler<SuspendEvent>> {
+  }
+
+  @NamedParameter(doc = "The event handler that receives messages from the driver",
+      default_class = DefaultDriverMessageHandler.class)
+  public final class MessageHandler implements Name<EventHandler<DriverMessage>> {
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/TaskMessage.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/TaskMessage.java b/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/TaskMessage.java
new file mode 100644
index 0000000..4b3c71a
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/driver/task/TaskMessage.java
@@ -0,0 +1,56 @@
+/**
+ * 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.reef.driver.task;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.io.Message;
+import org.apache.reef.io.naming.Identifiable;
+
+/**
+ * A message from a running task to the driver.
+ */
+@DriverSide
+@Public
+@Provided
+public interface TaskMessage extends Message, Identifiable {
+
+  /**
+   * @return the message.
+   */
+  @Override
+  byte[] get();
+
+  /**
+   * @return the ID of the sending task.
+   */
+  @Override
+  String getId();
+
+  /**
+   * @return the id of the context the sending task is running in.
+   */
+  String getContextId();
+
+  /**
+   * @return the ID of the TaskMessageSource
+   */
+  String getMessageSourceID();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/ContextMessage.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/ContextMessage.java b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/ContextMessage.java
new file mode 100644
index 0000000..0c66551
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/ContextMessage.java
@@ -0,0 +1,69 @@
+/**
+ * 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.reef.evaluator.context;
+
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.io.Message;
+
+/**
+ * Evaluator-side representation of a message sent from an Evaluator to a Driver.
+ */
+@EvaluatorSide
+@Public
+@Provided
+public final class ContextMessage implements Message {
+
+  private final String messageSourceID;
+  private final byte[] theBytes;
+
+  private ContextMessage(final String messageSourceID, final byte[] theBytes) {
+    this.messageSourceID = messageSourceID;
+    this.theBytes = theBytes;
+  }
+
+  /**
+   * @param messageSourceID The message's sourceID. This will be accessible in the Driver for routing.
+   * @param theBytes        The actual content of the message, serialized into a byte[]
+   * @return a new EvaluatorMessage with the given content.
+   */
+  public static ContextMessage from(final String messageSourceID, final byte[] theBytes) {
+    assert (theBytes != null && messageSourceID != null);
+    return new ContextMessage(messageSourceID, theBytes);
+  }
+
+  /**
+   * @return the message source identifier.
+   */
+  public String getMessageSourceID() {
+    return this.messageSourceID;
+  }
+
+  /**
+   * @return the message
+   */
+  @Override
+  public byte[] get() {
+    return this.theBytes;
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/ContextMessageHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/ContextMessageHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/ContextMessageHandler.java
new file mode 100644
index 0000000..b08a07d
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/ContextMessageHandler.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.evaluator.context;
+
+import org.apache.reef.annotations.Optional;
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ * Implement this interface to receive messages from the driver in a context.
+ */
+@EvaluatorSide
+@Public
+@Optional
+public interface ContextMessageHandler extends EventHandler<byte[]> {
+
+  /**
+   * @param message sent by the driver to this context
+   */
+  @Override
+  public void onNext(final byte[] message);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/ContextMessageSource.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/ContextMessageSource.java b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/ContextMessageSource.java
new file mode 100644
index 0000000..3f31327
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/ContextMessageSource.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.evaluator.context;
+
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.util.Optional;
+
+
+/**
+ * Message source for control flow messages from a context to the Driver.
+ */
+@Public
+@EvaluatorSide
+public interface ContextMessageSource {
+
+  /**
+   * @return a message to be sent back to the Driver.
+   */
+  public Optional<ContextMessage> getMessage();
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/events/ContextStart.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/events/ContextStart.java b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/events/ContextStart.java
new file mode 100644
index 0000000..bb7ed33
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/events/ContextStart.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.evaluator.context.events;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.io.naming.Identifiable;
+
+/**
+ * This Event is fired when a Context is started.
+ */
+@EvaluatorSide
+@Public
+@Provided
+public interface ContextStart extends Identifiable {
+
+  /**
+   * @return the ID of the EvaluatorContext that was just launched.
+   */
+  public String getId();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/events/ContextStop.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/events/ContextStop.java b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/events/ContextStop.java
new file mode 100644
index 0000000..6e2297c
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/events/ContextStop.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.evaluator.context.events;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.annotations.audience.EvaluatorSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.io.naming.Identifiable;
+
+/**
+ * This event is fired when a Context is about to be closed.
+ */
+@EvaluatorSide
+@Public
+@Provided
+public interface ContextStop extends Identifiable {
+
+  /**
+   * @return the ID of the EvaluatorContext.
+   */
+  public String getId();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextIdentifier.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextIdentifier.java b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextIdentifier.java
new file mode 100644
index 0000000..f95185f
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextIdentifier.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.evaluator.context.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * Context identifier.
+ */
+@NamedParameter(doc = "The identifier for the context.")
+public final class ContextIdentifier implements Name<String> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextMessageHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextMessageHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextMessageHandlers.java
new file mode 100644
index 0000000..8fe130d
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextMessageHandlers.java
@@ -0,0 +1,34 @@
+/**
+ * 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.reef.evaluator.context.parameters;
+
+import org.apache.reef.evaluator.context.ContextMessageHandler;
+import org.apache.reef.runtime.common.evaluator.context.defaults.DefaultContextMessageHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+import java.util.Set;
+
+/**
+ * The set of Context message handlers.
+ */
+@NamedParameter(doc = "The set of Context message handlers.",
+    default_classes = DefaultContextMessageHandler.class)
+public final class ContextMessageHandlers implements Name<Set<ContextMessageHandler>> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextMessageSources.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextMessageSources.java b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextMessageSources.java
new file mode 100644
index 0000000..793d54d
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextMessageSources.java
@@ -0,0 +1,34 @@
+/**
+ * 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.reef.evaluator.context.parameters;
+
+import org.apache.reef.evaluator.context.ContextMessageSource;
+import org.apache.reef.runtime.common.evaluator.context.defaults.DefaultContextMessageSource;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+import java.util.Set;
+
+/**
+ * The set of ContextMessageSource implementations called during heartbeats.
+ */
+@NamedParameter(doc = "The set of ContextMessageSource implementations called during heartbeats.",
+    default_classes = DefaultContextMessageSource.class)
+public final class ContextMessageSources implements Name<Set<ContextMessageSource>> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextStartHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextStartHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextStartHandlers.java
new file mode 100644
index 0000000..8c3376f
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextStartHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.evaluator.context.parameters;
+
+import org.apache.reef.evaluator.context.events.ContextStart;
+import org.apache.reef.runtime.common.evaluator.context.defaults.DefaultContextStartHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * The set of event handlers for the ContextStart event.
+ */
+@NamedParameter(doc = "The set of event handlers for the ContextStart event.",
+    default_classes = DefaultContextStartHandler.class)
+public class ContextStartHandlers implements Name<Set<EventHandler<ContextStart>>> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextStopHandlers.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextStopHandlers.java b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextStopHandlers.java
new file mode 100644
index 0000000..c4af612
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/ContextStopHandlers.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.evaluator.context.parameters;
+
+import org.apache.reef.evaluator.context.events.ContextStop;
+import org.apache.reef.runtime.common.evaluator.context.defaults.DefaultContextStopHandler;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.wake.EventHandler;
+
+import java.util.Set;
+
+/**
+ * The set of event handlers for the ContextStop event.
+ */
+@NamedParameter(doc = "The set of event handlers for the ContextStop event.",
+    default_classes = DefaultContextStopHandler.class)
+public final class ContextStopHandlers implements Name<Set<EventHandler<ContextStop>>> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/Services.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/Services.java b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/Services.java
new file mode 100644
index 0000000..df5a2ed
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/evaluator/context/parameters/Services.java
@@ -0,0 +1,35 @@
+/**
+ * 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.reef.evaluator.context.parameters;
+
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.util.ObjectInstantiationLogger;
+
+import java.util.Set;
+
+/**
+ * A set of classes to be instantiated and shared as singletons within this context and all child context
+ */
+@NamedParameter(doc = "A set of classes to be instantiated and shared as singletons within this context and all child context",
+    default_classes = ObjectInstantiationLogger.class)
+@Private
+public class Services implements Name<Set<Object>> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/exception/DriverException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/exception/DriverException.java b/lang/java/reef-common/src/main/java/org/apache/reef/exception/DriverException.java
new file mode 100644
index 0000000..87e3861
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/exception/DriverException.java
@@ -0,0 +1,65 @@
+/**
+ * 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.reef.exception;
+
+import java.util.concurrent.ExecutionException;
+
+/**
+ * Thrown by the {@link Driver} and to the clients of {@link REEF}.
+ */
+public class DriverException extends ExecutionException {
+
+  private static final long serialVersionUID = 1L;
+
+  /**
+   * Standard Exception constructor.
+   */
+  public DriverException() {
+    super();
+  }
+
+  /**
+   * Standard Exception constructor.
+   *
+   * @param message
+   * @param cause
+   */
+  public DriverException(final String message, final Throwable cause) {
+    super(message, cause);
+  }
+
+  /**
+   * Standard Exception constructor.
+   *
+   * @param message
+   */
+  public DriverException(final String message) {
+    super(message);
+  }
+
+  /**
+   * Standard Exception constructor.
+   *
+   * @param cause
+   */
+  public DriverException(final Throwable cause) {
+    super(cause);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/exception/EvaluatorException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/exception/EvaluatorException.java b/lang/java/reef-common/src/main/java/org/apache/reef/exception/EvaluatorException.java
new file mode 100644
index 0000000..4c22c7e
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/exception/EvaluatorException.java
@@ -0,0 +1,66 @@
+/**
+ * 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.reef.exception;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.io.naming.Identifiable;
+
+import java.util.concurrent.ExecutionException;
+
+/**
+ * Exception thrown to the Driver when an Evaluator becomes unusable.
+ */
+@DriverSide
+public class EvaluatorException extends ExecutionException implements Identifiable {
+
+  private static final long serialVersionUID = 1L;
+  private final transient String evaluatorId;
+
+  public EvaluatorException(final String evaluatorId) {
+    super();
+    this.evaluatorId = evaluatorId;
+  }
+
+  public EvaluatorException(final String evaluatorId, final String message, final Throwable cause) {
+    super(message, cause);
+    this.evaluatorId = evaluatorId;
+  }
+
+  public EvaluatorException(final String evaluatorId, final String message) {
+    super(message);
+    this.evaluatorId = evaluatorId;
+  }
+
+
+  public EvaluatorException(final String evaluatorId, final Throwable cause) {
+    super(cause);
+    this.evaluatorId = evaluatorId;
+  }
+
+  /**
+   * Access the affected Evaluator.
+   *
+   * @return the affected Evaluator.
+   */
+  @Override
+  public String getId() {
+    return this.evaluatorId;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/exception/EvaluatorKilledByResourceManagerException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/exception/EvaluatorKilledByResourceManagerException.java b/lang/java/reef-common/src/main/java/org/apache/reef/exception/EvaluatorKilledByResourceManagerException.java
new file mode 100644
index 0000000..2a0c5f4
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/exception/EvaluatorKilledByResourceManagerException.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.exception;
+
+/**
+ * Reported as part of a FailedEvaluator when the resource manager killed the Evaluator
+ */
+public final class EvaluatorKilledByResourceManagerException extends EvaluatorException {
+
+  public EvaluatorKilledByResourceManagerException(final String evaluatorId, final String message) {
+    super(evaluatorId, message);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/exception/EvaluatorTimeoutException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/exception/EvaluatorTimeoutException.java b/lang/java/reef-common/src/main/java/org/apache/reef/exception/EvaluatorTimeoutException.java
new file mode 100644
index 0000000..236e119
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/exception/EvaluatorTimeoutException.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.exception;
+
+/**
+ * Thrown if an Evaluator hasn't been reporting for a while.
+ */
+public class EvaluatorTimeoutException extends EvaluatorException {
+
+  private static final long serialVersionUID = 1L;
+
+  public EvaluatorTimeoutException(final String evaluatorID) {
+    super(evaluatorID);
+  }
+
+  public EvaluatorTimeoutException(final String evaluatorID, final String message, final Throwable cause) {
+    super(evaluatorID, message, cause);
+  }
+
+  public EvaluatorTimeoutException(final String evaluatorID, final String message) {
+    super(evaluatorID, message);
+  }
+
+  public EvaluatorTimeoutException(final String evaluatorID, final Throwable cause) {
+    super(evaluatorID, cause);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/NetworkException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/NetworkException.java b/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/NetworkException.java
new file mode 100644
index 0000000..20c5bdc
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/NetworkException.java
@@ -0,0 +1,38 @@
+/**
+ * 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.reef.exception.evaluator;
+
+/**
+ * Network exception
+ */
+public class NetworkException extends ServiceException {
+  private static final long serialVersionUID = 1L;
+
+  public NetworkException(final String s, final Throwable e) {
+    super(s, e);
+  }
+
+  public NetworkException(final String s) {
+    super(s);
+  }
+
+  public NetworkException(final Throwable e) {
+    super(e);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/ServiceException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/ServiceException.java b/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/ServiceException.java
new file mode 100644
index 0000000..a29535d
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/ServiceException.java
@@ -0,0 +1,53 @@
+/**
+ * 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.reef.exception.evaluator;
+
+/**
+ * The base class for exceptions thrown by REEF libraries and services.
+ * <p/>
+ * Rules of thumb for exception handling in REEF:
+ * <ul>
+ * <li>When possible, throw a subclass of ServiceException, with the following exceptions (no pun intended)</li>
+ * <li>Iterator and other standard Java interfaces neglect to declare throws
+ * clauses. Use ServiceRuntimeException when implementing such interfaces.</li>
+ * <li>If there is no good way for Task code to recover from the exception, throw
+ * (and document) a subclass of ServiceRuntimeException</li>
+ * <li>Applications with generic, catch-all error handling should catch ServiceRuntimeException and ServiceException.</li>
+ * <li>Applications with specific error handling logic (eg: ignoring/coping with a failed remote task) should catch
+ * the subclass of ServiceRuntimeException / ServiceException thrown by the library they are using.</li>
+ * </ul>
+ *
+ * @see ServiceRuntimeException
+ */
+public class ServiceException extends Exception {
+  private static final long serialVersionUID = 1L;
+
+  public ServiceException(final String s, final Throwable e) {
+    super(s, e);
+  }
+
+  public ServiceException(final String s) {
+    super(s);
+  }
+
+  public ServiceException(final Throwable e) {
+    super(e);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/ServiceRuntimeException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/ServiceRuntimeException.java b/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/ServiceRuntimeException.java
new file mode 100644
index 0000000..b91c9f2
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/ServiceRuntimeException.java
@@ -0,0 +1,75 @@
+/**
+ * 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.reef.exception.evaluator;
+
+
+/**
+ * The base class for resourcemanager exceptions thrown by REEF services, such as
+ * storage and networking routines. SERVICES that throw exceptions that
+ * applications may be able to cope with should subclass ServiceRuntimeException
+ * or ServiceException.
+ *
+ * @see ServiceException which is generally preferred over ServiceRuntimeException.
+ */
+public class ServiceRuntimeException extends RuntimeException {
+  private static final long serialVersionUID = 1L;
+  private final boolean isWrappedServiceException;
+
+  public ServiceRuntimeException() {
+    this.isWrappedServiceException = false;
+  }
+
+  /**
+   * It often is the case that analogous ServiceException and ServiceRuntimeExceptions
+   * are needed so that exception types can be uniformly thrown from Reef APIs that
+   * declare throws clauses, and legacy interfaces that do not.  This constructor
+   * wraps ServiceExceptions, and is the preferred way to deal with such situations.
+   *
+   * @param cause
+   */
+  public ServiceRuntimeException(final ServiceException cause) {
+    super("Wrapped ServiceException", cause);
+    this.isWrappedServiceException = true;
+  }
+
+  public ServiceRuntimeException(final String message, final Throwable cause) {
+    super(message, cause);
+    this.isWrappedServiceException = false;
+  }
+
+  public ServiceRuntimeException(final String message) {
+    super(message);
+    this.isWrappedServiceException = false;
+
+  }
+
+  public ServiceRuntimeException(final Throwable cause) {
+    super(cause);
+    this.isWrappedServiceException = (cause instanceof ServiceException);
+  }
+
+  /**
+   * Upon catching a ServiceRuntimeException, the receiving code should call unwrap().
+   *
+   * @return this, or getCause(), depending on whether or not this is a wrapped ServiceException.
+   */
+  public Throwable unwrap() {
+    return this.isWrappedServiceException ? getCause() : this;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/StorageException.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/StorageException.java b/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/StorageException.java
new file mode 100644
index 0000000..7f49c87
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/StorageException.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.exception.evaluator;
+
+public class StorageException extends ServiceException {
+  private static final long serialVersionUID = 1L;
+
+  public StorageException(final String s, final Throwable e) {
+    super(s, e);
+  }
+
+  public StorageException(final String s) {
+    super(s);
+  }
+
+  public StorageException(final Throwable e) {
+    super(e);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/package-info.java
new file mode 100644
index 0000000..9ce7ca5
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/exception/evaluator/package-info.java
@@ -0,0 +1,23 @@
+/**
+ * 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.
+ */
+/**
+ * Exceptions thrown in the Evaluators.
+ *
+ */
+package org.apache.reef.exception.evaluator;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/exception/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/exception/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/exception/package-info.java
new file mode 100644
index 0000000..6b4f318
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/exception/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Exceptions thrown to Job Drivers.
+ */
+package org.apache.reef.exception;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/Accumulable.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/Accumulable.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/Accumulable.java
new file mode 100644
index 0000000..f3656b2
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/Accumulable.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.io;
+
+import org.apache.reef.annotations.Unstable;
+import org.apache.reef.exception.evaluator.ServiceException;
+
+/**
+ * Similar to {@link Iterable}, this is an interface for objects that can return
+ * {@link Accumulator}s.
+ *
+ * @param <T> The type accumulated.
+ */
+@Unstable
+public interface Accumulable<T> {
+  /**
+   * Returns a new Accumulator.
+   *
+   * @return the new {@link Accumulator}
+   * @throws ServiceException
+   */
+  public Accumulator<T> accumulator() throws ServiceException;
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/Accumulator.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/Accumulator.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/Accumulator.java
new file mode 100644
index 0000000..23b488a
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/Accumulator.java
@@ -0,0 +1,45 @@
+/**
+ * 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.reef.io;
+
+import org.apache.reef.annotations.Unstable;
+import org.apache.reef.exception.evaluator.ServiceException;
+
+/**
+ * A basic Accumulator interface.
+ *
+ * @param <T> the type of the datums accumulated
+ */
+@Unstable
+public interface Accumulator<T> extends AutoCloseable {
+
+  /**
+   * Add the given datum to this.
+   *
+   * @param datum the datum to be added
+   * @throws ServiceException
+   */
+  void add(final T datum) throws ServiceException;
+
+  @Override
+  void close() throws ServiceException;
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/ExternalMap.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/ExternalMap.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/ExternalMap.java
new file mode 100644
index 0000000..31350f4
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/ExternalMap.java
@@ -0,0 +1,93 @@
+/**
+ * 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.reef.io;
+
+import org.apache.reef.annotations.Unstable;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A Map interface for data that can be swapped out to other processes, managed
+ * by native code, paged to disk, stored remotely, etc...
+ *
+ * @param <T> the entry type of the map
+ */
+@Unstable
+public interface ExternalMap<T> {
+
+  /**
+   * @param key
+   * @return true, if an entry with the given key exists
+   */
+  public boolean containsKey(final CharSequence key);
+
+  /**
+   * Element access
+   *
+   * @param key
+   * @return the object stored under key nor null if no such object exists
+   */
+  public T get(final CharSequence key);
+
+  /**
+   * Put a record into the map
+   *
+   * @param key
+   * @param value
+   * @return the previous value associated with key, or null if there was no
+   * mapping for key. (A null return can also indicate that the map previously
+   * associated null with key, if the implementation supports null values.)
+   */
+  public T put(final CharSequence key, final T value);
+
+  /**
+   * Removes the mapping for a key from this map if it is present (optional
+   * operation). More formally, if this map contains a mapping from key k to
+   * value v such that (key==null ? k==null : key.equals(k)), that mapping is
+   * removed. (The map can contain at most one such mapping.) Returns the
+   * value to which this map previously associated the key, or null if the map
+   * contained no mapping for the key.
+   * <p/>
+   * If this map permits null values, then a return value of null does not
+   * necessarily indicate that the map contained no mapping for the key; it's
+   * also possible that the map explicitly mapped the key to null.
+   * <p/>
+   * The map will not contain a mapping for the specified key once the call
+   * returns.
+   *
+   * @param key key whose mapping is to be removed from the map
+   * @return the previous value associated with key, or null if there was no
+   * mapping for key.
+   */
+  public T remove(final CharSequence key);
+
+  /**
+   * Copies all of the mappings from the specified map to this map (optional
+   * operation). The effect of this call is equivalent to that of calling
+   * put(k, v) on this map once for each mapping from key k to value v in the
+   * specified map. The behavior of this operation is undefined if the
+   * specified map is modified while the operation is in progress.
+   *
+   * @param m
+   */
+  public void putAll(final Map<? extends CharSequence, ? extends T> m);
+
+  public Iterable<Map.Entry<CharSequence, T>> getAll(Set<? extends CharSequence> keys);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/Message.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/Message.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/Message.java
new file mode 100644
index 0000000..17eade3
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/Message.java
@@ -0,0 +1,36 @@
+/**
+ * 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.reef.io;
+
+import org.apache.reef.annotations.audience.Public;
+
+/**
+ * A message from a REEF component
+ */
+@Public
+public interface Message {
+
+  /**
+   * Message payload
+   *
+   * @return message payload
+   */
+  public byte[] get();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/PartitionSpec.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/PartitionSpec.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/PartitionSpec.java
new file mode 100644
index 0000000..8cdcfd7
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/PartitionSpec.java
@@ -0,0 +1,49 @@
+/**
+ * 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.reef.io;
+
+import org.apache.reef.annotations.Unstable;
+
+// FIXME:
+// This was another more type safe
+// alternative to integer partitions
+@Unstable
+public class PartitionSpec {
+  private final Type type;
+  private final int id;
+
+  public PartitionSpec(final Type type, final int id) {
+    this.type = type;
+    this.id = id;
+  }
+
+  public Type getType() {
+    return type;
+  }
+
+  public int getId() {
+    return id;
+  }
+
+  public enum Type {
+    SINGLE,
+    ALL,
+    NONE
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/Spool.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/Spool.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/Spool.java
new file mode 100644
index 0000000..ff0b4c8
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/Spool.java
@@ -0,0 +1,60 @@
+/**
+ * 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.reef.io;
+
+import org.apache.reef.annotations.Unstable;
+import org.apache.reef.exception.evaluator.ServiceException;
+
+import java.util.Iterator;
+
+/**
+ * Spool files can be appended to, and can be scanned starting at the beginning.
+ * Random read and write access is not supported. Spool files are ephemeral; the
+ * space they use will be automatically reclaimed by REEF.
+ */
+@Unstable
+public interface Spool<T> extends Iterable<T>, Accumulable<T> {
+
+  /**
+   * Returns an Iterable over the spool file.
+   * <p/>
+   * Depending on the implementation, this method may be called only once per
+   * Spool instance, or it may be called repeatedly. Similarly, with some Spool
+   * implementations, attempts to append to the SpoolFile after calling
+   * iterator() may fail fast with a ConcurrentModificationException.
+   *
+   * @return An Iterator over the SpoolFile, in the order data was inserted.
+   * @throws Exception
+   */
+  @Override
+  public Iterator<T> iterator();
+
+  /**
+   * Returns an Accumulator for the spool file.
+   * <p/>
+   * Depending on the implementation, this method may be called only once per
+   * Spool instance, or it may be called repeatedly. Similarly, with some Spool
+   * implementations, attempts to append to the SpoolFile after calling
+   * iterator() may fail fast with a ConcurrentModificationException.
+   *
+   * @throws ServiceException
+   */
+  @Override
+  public Accumulator<T> accumulator() throws ServiceException;
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/SystemTempFileCreator.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/SystemTempFileCreator.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/SystemTempFileCreator.java
new file mode 100644
index 0000000..985906e
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/SystemTempFileCreator.java
@@ -0,0 +1,66 @@
+/**
+ * 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.reef.io;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.attribute.FileAttribute;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A TempFileCreator that uses the system's temp directory.
+ */
+public final class SystemTempFileCreator implements TempFileCreator {
+  private static final Logger LOG = Logger.getLogger(SystemTempFileCreator.class.getName());
+
+  @Inject
+  public SystemTempFileCreator() {
+    LOG.log(Level.FINE, "Temporary files and folders will be created in the system temp folder.");
+  }
+
+  @Override
+  public File createTempFile(final String prefix, final String suffix) throws IOException {
+    final File result = File.createTempFile(prefix, suffix);
+    if (LOG.isLoggable(Level.FINEST)) {
+      LOG.log(Level.FINEST, "Created temporary file: {0}", result.getAbsolutePath());
+    }
+    return result;
+  }
+
+  @Override
+  public File createTempDirectory(final String prefix, final FileAttribute<?> attributes) throws IOException {
+    final File result = Files.createTempDirectory(prefix, attributes).toFile();
+    if (LOG.isLoggable(Level.FINEST)) {
+      LOG.log(Level.FINEST, "Created temporary folder: {0}", result.getAbsolutePath());
+    }
+    return result;
+  }
+
+  @Override
+  public File createTempDirectory(final String prefix) throws IOException {
+    final File result = Files.createTempDirectory(prefix).toFile();
+    if (LOG.isLoggable(Level.FINEST)) {
+      LOG.log(Level.FINEST, "Created temporary folder: {0}", result.getAbsolutePath());
+    }
+    return result;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/TempFileCreator.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/TempFileCreator.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/TempFileCreator.java
new file mode 100644
index 0000000..7ff59c2
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/TempFileCreator.java
@@ -0,0 +1,65 @@
+/**
+ * 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.reef.io;
+
+import org.apache.reef.annotations.Provided;
+import org.apache.reef.tang.annotations.DefaultImplementation;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.attribute.FileAttribute;
+
+/**
+ * Utility to create temporary files and folders in accordance with the underlying resource manager.
+ */
+@Provided
+@DefaultImplementation(WorkingDirectoryTempFileCreator.class)
+public interface TempFileCreator {
+  /**
+   * Creates a temporary file.
+   *
+   * @param prefix
+   * @param suffix
+   * @return
+   * @throws IOException
+   */
+  public File createTempFile(final String prefix, final String suffix) throws IOException;
+
+  /**
+   * Creates a temporary folder.
+   *
+   * @param prefix
+   * @param attrs
+   * @return
+   * @throws IOException
+   */
+  public File createTempDirectory(final String prefix, final FileAttribute<?> attrs) throws IOException;
+
+
+  /**
+   * Create a temporary folder.
+   *
+   * @param prefix
+   * @return
+   * @throws IOException
+   */
+  public File createTempDirectory(final String prefix) throws IOException;
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/Tuple.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/Tuple.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/Tuple.java
new file mode 100644
index 0000000..9c5aa00
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/Tuple.java
@@ -0,0 +1,67 @@
+/**
+ * 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.reef.io;
+
+import org.apache.reef.annotations.Unstable;
+
+// TODO: Document
+@Unstable
+public final class Tuple<K, V> {
+  private final K k;
+  private final V v;
+
+  public Tuple(final K k, final V v) {
+    this.k = k;
+    this.v = v;
+  }
+
+  public K getKey() {
+    return k;
+  }
+
+  public V getValue() {
+    return v;
+  }
+
+  @Override
+  public boolean equals(final Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    final Tuple tuple = (Tuple) o;
+
+    if (!k.equals(tuple.k)) return false;
+    if (!v.equals(tuple.v)) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = k.hashCode();
+    result = 31 * result + v.hashCode();
+    return result;
+  }
+
+  @Override
+  public String toString() {
+    return "(" + getKey() + "," + getValue() + ")";
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/WorkingDirectoryTempFileCreator.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/WorkingDirectoryTempFileCreator.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/WorkingDirectoryTempFileCreator.java
new file mode 100644
index 0000000..23ecb2e
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/WorkingDirectoryTempFileCreator.java
@@ -0,0 +1,76 @@
+/**
+ * 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.reef.io;
+
+import org.apache.reef.annotations.Provided;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.FileAttribute;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Creates temp files in a directory named "temp" within  the current working directory.
+ */
+@Provided
+public final class WorkingDirectoryTempFileCreator implements TempFileCreator {
+  private static final Logger LOG = Logger.getLogger(WorkingDirectoryTempFileCreator.class.getName());
+  private final File tempFolderAsFile;
+  private final Path tempFolderAsPath;
+
+  @Inject
+  WorkingDirectoryTempFileCreator() throws IOException {
+    this.tempFolderAsFile = new File("./reef/temp");
+    this.tempFolderAsFile.mkdirs();
+    this.tempFolderAsPath = this.tempFolderAsFile.toPath();
+    LOG.log(Level.FINE, "Temporary files and folders will be created in [{0}]", this.tempFolderAsFile.getAbsolutePath());
+  }
+
+
+  @Override
+  public File createTempFile(final String prefix, final String suffix) throws IOException {
+    final File result = File.createTempFile(prefix, suffix, this.tempFolderAsFile);
+    if (LOG.isLoggable(Level.FINEST)) {
+      LOG.log(Level.FINEST, "Created temporary file: {0}", result.getAbsolutePath());
+    }
+    return result;
+  }
+
+  @Override
+  public File createTempDirectory(final String prefix, final FileAttribute<?> fileAttributes) throws IOException {
+    final File result = Files.createTempDirectory(this.tempFolderAsPath, prefix, fileAttributes).toFile();
+    if (LOG.isLoggable(Level.FINEST)) {
+      LOG.log(Level.FINEST, "Created temporary folder: {0}", result.getAbsolutePath());
+    }
+    return result;
+  }
+
+  @Override
+  public File createTempDirectory(String prefix) throws IOException {
+    final File result = Files.createTempDirectory(this.tempFolderAsPath, prefix).toFile();
+    if (LOG.isLoggable(Level.FINEST)) {
+      LOG.log(Level.FINEST, "Created temporary folder: {0}", result.getAbsolutePath());
+    }
+    return result;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/Identifiable.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/Identifiable.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/Identifiable.java
new file mode 100644
index 0000000..0230434
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/Identifiable.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.io.naming;
+
+/**
+ * This interface imposes that each object of the class that implements it
+ * has an identifier.
+ */
+public interface Identifiable {
+
+  /**
+   * Returns an identifier of this object
+   *
+   * @return an identifier of this object
+   */
+  public String getId();
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/NameAssignment.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/NameAssignment.java b/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/NameAssignment.java
new file mode 100644
index 0000000..eb00022
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/io/naming/NameAssignment.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.io.naming;
+
+import org.apache.reef.wake.Identifier;
+
+import java.net.InetSocketAddress;
+
+/**
+ * Pair of an identifier and an address
+ */
+public interface NameAssignment {
+
+  /**
+   * Returns an identifier of this object
+   *
+   * @return an identifier
+   */
+  public Identifier getIdentifier();
+
+  /**
+   * Returns an address of this object
+   *
+   * @return a socket address
+   */
+  public InetSocketAddress getAddress();
+
+}


[33/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/EnvironmentUtils.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/EnvironmentUtils.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/EnvironmentUtils.java
new file mode 100644
index 0000000..9d19d35
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/EnvironmentUtils.java
@@ -0,0 +1,153 @@
+/**
+ * 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.reef.util;
+
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.OptionalParameter;
+import org.apache.reef.tang.formats.Param;
+
+import java.io.File;
+import java.nio.file.InvalidPathException;
+import java.nio.file.Path;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public final class EnvironmentUtils {
+
+  private static final Logger LOG = Logger.getLogger(EnvironmentUtils.class.getName());
+
+  /**
+   * Get a set of all classpath entries EXCEPT of those under
+   * $JAVA_HOME, $YARN_HOME, and $HADOOP_HOME.
+   *
+   * @return A set of classpath entries as strings.
+   */
+  public static Set<String> getAllClasspathJars() {
+    return getAllClasspathJars(
+        "JAVA_HOME",
+        "YARN_HOME",
+        "HADOOP_HOME",
+        "HADOOP_YARN_HOME",
+        "HADOOP_HDFS_HOME",
+        "HADOOP_COMMON_HOME",
+        "HADOOP_MAPRED_HOME",
+        "YARN_CONF_DIR",
+        "HADOOP_CONF_DIR");
+  }
+
+  /**
+   * Get a set of all classpath entries EXCEPT of those under excludeEnv directories.
+   * Every excludeEnv entry is an environment variable name.
+   *
+   * @return A set of classpath entries as strings.
+   */
+  public static Set<String> getAllClasspathJars(final String... excludeEnv) {
+
+    final Set<String> jars = new HashSet<>();
+    final Set<Path> excludePaths = new HashSet<>();
+
+    for (final String env : excludeEnv) {
+      final String path = System.getenv(env);
+      if (null != path) {
+        final File file = new File(path);
+        if (file.exists()) {
+          excludePaths.add(file.toPath());
+        }
+      }
+    }
+
+    for (final String path : System.getProperty("java.class.path").split(File.pathSeparator)) {
+      try {
+        final File file = new File(path);
+        if (file.exists()) {
+          final Path absolutePath = file.toPath();
+          boolean toBeAdded = true;
+          for (final Path prefix : excludePaths) {
+            if (absolutePath.startsWith(prefix)) {
+              toBeAdded = false;
+            }
+          }
+          if (toBeAdded) {
+            jars.add(absolutePath.toString());
+          }
+        }
+      } catch (final InvalidPathException ex) {
+        LOG.log(Level.FINE, "Skip path: {0}: {1}", new Object[]{path, ex});
+      }
+    }
+
+    return jars;
+  }
+
+  /**
+   * @param config
+   * @param param
+   * @param values
+   * @param <P>
+   * @return
+   * @deprecated in 0.2 this really should be in Tang.
+   */
+  @Deprecated
+  public static <P extends Param> ConfigurationModule addAll(
+      ConfigurationModule config, final P param, final Iterable<String> values) {
+    for (final String val : values) {
+      config = config.set(param, val);
+    }
+    return config;
+  }
+
+  /**
+   * @param config
+   * @param param
+   * @return
+   * @deprecated Using this method is inherently non-deterministic as it depends on environment variables on your local
+   * machine.
+   */
+  @Deprecated
+  public static ConfigurationModule addClasspath(
+      final ConfigurationModule config, final OptionalParameter<String> param) {
+    return addAll(config, param, getAllClasspathJars());
+  }
+
+  /**
+   * Check whether assert() statements are evaluated.
+   *
+   * @return true, if assertions are enabled. False otherwise.
+   */
+  public static boolean areAssertionsEnabled() {
+    try {
+      assert false;
+      // If we got here, the assert above can't have thrown an exception. hence, asserts must be off.
+      return false;
+    } catch (final AssertionError assertionError) {
+      // The assert above threw an exception. Asserts must be enabled.
+      return true;
+    }
+  }
+
+  /**
+   * @param clazz
+   * @return the location (JAR or .class file) where the given class is located.
+   */
+  public static String getClassLocation(final Class<?> clazz) {
+    return clazz.getProtectionDomain().getCodeSource().getLocation().getFile();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/ExceptionHandlingEventHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/ExceptionHandlingEventHandler.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/ExceptionHandlingEventHandler.java
new file mode 100644
index 0000000..00908a9
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/ExceptionHandlingEventHandler.java
@@ -0,0 +1,50 @@
+/**
+ * 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.reef.util;
+
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.wake.EventHandler;
+
+/**
+ * An ExceptionHandler that wraps another one, but catches all exceptions thrown by that one and forwards them
+ * to an ExceptionHandler.
+ *
+ * @param <T> the event type handled
+ */
+@Private
+public final class ExceptionHandlingEventHandler<T> implements EventHandler<T> {
+
+  private final EventHandler<T> wrapped;
+  private final EventHandler<Throwable> exceptionHandler;
+
+  public ExceptionHandlingEventHandler(final EventHandler<T> wrapped,
+                                       final EventHandler<Throwable> exceptionHandler) {
+    this.wrapped = wrapped;
+    this.exceptionHandler = exceptionHandler;
+  }
+
+  @Override
+  public void onNext(final T t) {
+    try {
+      this.wrapped.onNext(t);
+    } catch (final Throwable throwable) {
+      this.exceptionHandler.onNext(throwable);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/Exceptions.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/Exceptions.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/Exceptions.java
new file mode 100644
index 0000000..735f053
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/Exceptions.java
@@ -0,0 +1,42 @@
+/**
+ * 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.reef.util;
+
+/**
+ * Utility class to deal with Exceptions
+ */
+public final class Exceptions {
+  private Exceptions() {
+  }
+
+  /**
+   * Walks the .getCause() chain till it hits the leaf node.
+   *
+   * @param throwable
+   * @return
+   */
+  public static Throwable getUltimateCause(final Throwable throwable) {
+    if (throwable.getCause() == null) {
+      return throwable;
+    } else {
+      return getUltimateCause(throwable.getCause());
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/JARFileMaker.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/JARFileMaker.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/JARFileMaker.java
new file mode 100644
index 0000000..fb59c58
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/JARFileMaker.java
@@ -0,0 +1,114 @@
+/**
+ * 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.reef.util;
+
+import org.apache.commons.compress.utils.IOUtils;
+
+import java.io.*;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Helper class to create JAR files.
+ */
+public class JARFileMaker implements AutoCloseable {
+
+  private static final Logger LOG = Logger.getLogger(JARFileMaker.class.getName());
+
+  private final FileOutputStream fileOutputStream;
+  private final JarOutputStream jarOutputStream;
+  private String relativeStartCanonicalPath = null;
+
+  public JARFileMaker(final File outputFile, final Manifest manifest) throws IOException {
+    this.fileOutputStream = new FileOutputStream(outputFile);
+    this.jarOutputStream = new JarOutputStream(this.fileOutputStream, manifest);
+  }
+
+  public JARFileMaker(final File outputFile) throws IOException {
+    this.fileOutputStream = new FileOutputStream(outputFile);
+    this.jarOutputStream = new JarOutputStream(this.fileOutputStream);
+  }
+
+  /**
+   * Adds a file to the JAR. If inputFile is a folder, it will be added recursively.
+   *
+   * @param inputFile
+   * @throws IOException
+   */
+  public JARFileMaker add(final File inputFile) throws IOException {
+
+    final String fileNameInJAR = makeRelative(inputFile);
+    if (inputFile.isDirectory()) {
+      final JarEntry entry = new JarEntry(fileNameInJAR);
+      entry.setTime(inputFile.lastModified());
+      this.jarOutputStream.putNextEntry(entry);
+      this.jarOutputStream.closeEntry();
+      for (final File nestedFile : inputFile.listFiles()) {
+        add(nestedFile);
+      }
+      return this;
+    }
+
+    final JarEntry entry = new JarEntry(fileNameInJAR);
+    entry.setTime(inputFile.lastModified());
+    this.jarOutputStream.putNextEntry(entry);
+    try (final BufferedInputStream in = new BufferedInputStream(new FileInputStream(inputFile))) {
+      IOUtils.copy(in, this.jarOutputStream);
+      this.jarOutputStream.closeEntry();
+    } catch (final FileNotFoundException ex) {
+      LOG.log(Level.WARNING, "Skip the file: " + inputFile, ex);
+    }
+    return this;
+  }
+
+  public JARFileMaker addChildren(final File folder) throws IOException {
+    this.relativeStartCanonicalPath = folder.getCanonicalPath();
+    for (final File f : folder.listFiles()) {
+      this.add(f);
+    }
+    this.relativeStartCanonicalPath = null;
+    return this;
+  }
+
+  private String makeRelative(final File input) throws IOException {
+    final String result;
+    if (this.relativeStartCanonicalPath == null) {
+      result = input.getCanonicalPath();
+    } else {
+      result = input.getCanonicalPath()
+          .replace(this.relativeStartCanonicalPath, "") // Drop the absolute prefix
+          .substring(1);                                // drop the '/' at the beginning
+    }
+    if (input.isDirectory()) {
+      return result.replace("\\", "/") + "/";
+    } else {
+      return result.replace("\\", "/");
+    }
+
+  }
+
+  @Override
+  public void close() throws IOException {
+    this.jarOutputStream.close();
+    this.fileOutputStream.close();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/MemoryUtils.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/MemoryUtils.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/MemoryUtils.java
new file mode 100644
index 0000000..5f9e6e7
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/MemoryUtils.java
@@ -0,0 +1,120 @@
+/**
+ * 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.reef.util;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryPoolMXBean;
+import java.util.List;
+
+/**
+ * Utility class to report current and peak memory
+ * usage. Structured to be used while logging. Is
+ * useful for debugging memory issues
+ */
+public final class MemoryUtils {
+
+  private static final int MBs = 1024 * 1024;
+
+  private MemoryUtils() {
+  }
+
+  public static String memPoolNames() {
+    final List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
+    final StringBuilder output = new StringBuilder();
+    for (final MemoryPoolMXBean bean : memoryPoolMXBeans) {
+      output.append(bean.getName());
+      output.append(",");
+    }
+    output.deleteCharAt(output.length() - 1);
+    return output.toString();
+  }
+
+  public static long currentEdenMemoryUsageMB() {
+    return currentMemoryUsage("eden");
+  }
+
+  public static long currentOldMemoryUsageMB() {
+    return currentMemoryUsage("old");
+  }
+
+  public static long currentPermMemoryUsageMB() {
+    return currentMemoryUsage("perm");
+  }
+
+  private static long currentMemoryUsage(final String name) {
+    final List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
+    for (final MemoryPoolMXBean bean : memoryPoolMXBeans) {
+      if (bean.getName().toLowerCase().indexOf(name) != -1) {
+        return bean.getUsage().getUsed() / MBs;
+      }
+    }
+    return 0;
+  }
+
+  public static long peakEdenMemoryUsageMB() {
+    return peakMemoryUsage("eden");
+  }
+
+  public static long peakOldMemoryUsageMB() {
+    return peakMemoryUsage("old");
+  }
+
+  public static long peakPermMemoryUsageMB() {
+    return peakMemoryUsage("perm");
+  }
+
+  private static long peakMemoryUsage(final String name) {
+    final List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
+    for (final MemoryPoolMXBean bean : memoryPoolMXBeans) {
+      if (bean.getName().toLowerCase().indexOf(name) != -1) {
+        return bean.getPeakUsage().getUsed() / MBs;
+      }
+    }
+    return 0;
+  }
+
+  public static void resetPeakUsage() {
+    final List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
+    for (final MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
+      memoryPoolMXBean.resetPeakUsage();
+    }
+  }
+
+  public static void main(final String[] args) {
+    System.out.println(memPoolNames());
+    {
+      final byte[] b = new byte[1 << 24];
+      System.out.println(currentEdenMemoryUsageMB()
+          + "," + currentOldMemoryUsageMB()
+          + "," + currentPermMemoryUsageMB());
+    }
+
+    System.gc();
+    System.out.println(currentEdenMemoryUsageMB()
+        + "," + currentOldMemoryUsageMB()
+        + "," + currentPermMemoryUsageMB());
+    System.out.println(peakEdenMemoryUsageMB()
+        + "," + peakOldMemoryUsageMB()
+        + "," + peakPermMemoryUsageMB());
+    resetPeakUsage();
+    System.out.println(peakEdenMemoryUsageMB()
+        + "," + peakOldMemoryUsageMB()
+        + "," + peakPermMemoryUsageMB());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/OSUtils.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/OSUtils.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/OSUtils.java
new file mode 100644
index 0000000..b6cd16e
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/OSUtils.java
@@ -0,0 +1,105 @@
+/**
+ * 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.reef.util;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public final class OSUtils {
+  private static final Logger LOG = Logger.getLogger(OSUtils.class.getName());
+
+  private OSUtils() {
+  }
+
+  /**
+   * Determines whether the current JVM is running on the Windows OS.
+   *
+   * @return true, if the JVM is running on Windows. false, otherwise
+   */
+  public static boolean isWindows() {
+    return System.getProperty("os.name").toLowerCase().contains("windows");
+  }
+
+  /**
+   * Determines whether the current JVM is running on the Linux OS.
+   *
+   * @return true, if the JVM is running on Linux. false, otherwise
+   */
+  public static boolean isLinux() {
+    return System.getProperty("os.name").toLowerCase().contains("linux");
+  }
+
+  /**
+   * @return the process ID of the JVM, if running on Linux. This returns -1 for other OSs.
+   */
+  public static long getPID() {
+    if (isLinux()) {
+      try {
+        final Process process = new ProcessBuilder()
+            .command("bash", "-c", "echo $PPID")
+            .start();
+        final byte[] returnBytes = new byte[128];
+        process.getInputStream().read(returnBytes);
+        final Long result = Long.valueOf(new String(returnBytes).trim());
+        process.destroy();
+        return result;
+      } catch (final IOException e) {
+        LOG.log(Level.SEVERE, "Unable to determine PID", e);
+        return -1;
+      }
+
+    } else {
+      return -1;
+    }
+  }
+
+  /**
+   * Applies `kill -9` to the process.
+   *
+   * @param pid
+   * @throws IOException
+   */
+  public static void kill(final long pid) throws IOException, InterruptedException {
+    if (isLinux()) {
+      final Process process = new ProcessBuilder()
+          .command("bash", "-c", "kill", "-9", String.valueOf(pid))
+          .start();
+      final int returnCode = process.waitFor();
+      LOG.fine("Kill returned: " + returnCode);
+    } else {
+      throw new UnsupportedOperationException("Unable to execute kill on non-linux OS");
+    }
+  }
+
+  /**
+   * Formats the given variable for expansion by Windows (<code>%VARIABE%</code>) or Linux (<code>$VARIABLE</code>)
+   *
+   * @param variableName
+   * @return
+   */
+  public static String formatVariable(final String variableName) {
+    if (isWindows()) {
+      return "%" + variableName + "%";
+    } else {
+      return "$" + variableName;
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/ObjectInstantiationLogger.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/ObjectInstantiationLogger.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/ObjectInstantiationLogger.java
new file mode 100644
index 0000000..5374e95
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/ObjectInstantiationLogger.java
@@ -0,0 +1,33 @@
+/**
+ * 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.reef.util;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A utility class used as a default at times.
+ */
+public class ObjectInstantiationLogger {
+  @Inject
+  public ObjectInstantiationLogger() {
+    Logger.getLogger(this.getClass().getName()).log(Level.FINER, "Instantiated");
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/REEFVersion.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/REEFVersion.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/REEFVersion.java
new file mode 100644
index 0000000..1b74e7f
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/REEFVersion.java
@@ -0,0 +1,84 @@
+/**
+ * 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.reef.util;
+
+import javax.inject.Inject;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Version information, retrieved from the pom (via a properties file reference)
+ */
+public final class REEFVersion {
+
+  private final static Logger LOG = Logger.getLogger(REEFVersion.class.getName());
+
+  private final static String FILENAME = "version.properties";
+  private final static String VERSION_KEY = "version";
+  private final static String VERSION_DEFAULT = "unknown";
+
+  private final String version;
+
+  @Inject
+  public REEFVersion() {
+    this.version = loadVersion();
+  }
+
+  /**
+   * Logs the version of REEF into the log Level INFO.
+   */
+  public void logVersion() {
+    this.logVersion(Level.INFO);
+  }
+
+  /**
+   * Logs the version of REEF into the given logLevel.
+   *
+   * @param logLevel The level to use in the log.
+   */
+  public void logVersion(final Level logLevel) {
+    LOG.log(logLevel, "REEF Version: {0}", this.version);
+  }
+
+  /**
+   * @return the version string for REEF.
+   */
+  public String getVersion() {
+    return version;
+  }
+
+  private static String loadVersion() {
+    String version;
+    try (final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(FILENAME)) {
+      if (is == null) {
+        throw new IOException(FILENAME + " not found");
+      }
+      final Properties properties = new Properties();
+      properties.load(is);
+      version = properties.getProperty(VERSION_KEY, VERSION_DEFAULT);
+    } catch (IOException e) {
+      LOG.log(Level.WARNING, "Could not find REEF version");
+      version = VERSION_DEFAULT;
+    }
+    return version;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/SetOnce.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/SetOnce.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/SetOnce.java
new file mode 100644
index 0000000..7408078
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/SetOnce.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.reef.util;
+
+/**
+ * A reference to a value that can be set exactly once.
+ */
+public final class SetOnce<T> {
+
+  private Optional<T> value;
+
+  public SetOnce(final T value) {
+    this.set(value);
+  }
+
+  public SetOnce() {
+    this.value = Optional.empty();
+  }
+
+  public synchronized T get() {
+    return value.get();
+  }
+
+  public synchronized void set(final T value) {
+    if (this.value.isPresent()) {
+      throw new IllegalStateException("Trying to set new value " + value +
+          " while an old value was already present: " + this.value);
+    }
+    this.value = Optional.of(value);
+  }
+
+  public synchronized boolean isSet() {
+    return this.value.isPresent();
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/SingletonAsserter.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/SingletonAsserter.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/SingletonAsserter.java
new file mode 100644
index 0000000..08ac456
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/SingletonAsserter.java
@@ -0,0 +1,41 @@
+/**
+ * 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.reef.util;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A helper class that can be used to ensure that objects are only instantiated once.
+ */
+public final class SingletonAsserter {
+
+  private static final Set<Class> classes = Collections.synchronizedSet(new HashSet<Class>());
+
+  /**
+   * This class operates purely in static mode.
+   */
+  private SingletonAsserter() {
+  }
+
+  public static boolean assertSingleton(final Class clazz) {
+    return classes.add(clazz);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/ThreadLogger.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/ThreadLogger.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/ThreadLogger.java
new file mode 100644
index 0000000..9a47184
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/ThreadLogger.java
@@ -0,0 +1,94 @@
+/**
+ * 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.reef.util;
+
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Methods to log the currently active set of threads with their stack traces. This is useful to log abnormal
+ * process exit situations, for instance the Driver timeout in the tests.
+ */
+public final class ThreadLogger {
+
+  /**
+   * This is a utility class that shall not be instantiated.
+   */
+  private ThreadLogger() {
+  }
+
+  /**
+   * Same as <code>logThreads(logger, level, prefix, "\n\t", "\n\t\t")</code>
+   */
+  public static void logThreads(final Logger logger, final Level level, final String prefix) {
+    logThreads(logger, level, prefix, "\n\t", "\n\t\t");
+  }
+
+  /**
+   * Logs the currently active threads and their stack trace to the given Logger and Level.
+   *
+   * @param logger             the Logger instance to log to.
+   * @param level              the Level to log into.
+   * @param prefix             a prefix of the log message.
+   * @param threadPrefix       logged before each thread, e.g. "\n\t" to create an indented list.
+   * @param stackElementPrefix logged before each stack trace element, e.g. "\n\t\t" to create an indented list.
+   */
+  public static void logThreads(
+      final Logger logger, final Level level, final String prefix,
+      final String threadPrefix, final String stackElementPrefix) {
+    logger.log(level, getFormattedThreadList(prefix, threadPrefix, stackElementPrefix));
+  }
+
+  /**
+   * Produces a String representation of the currently running threads.
+   *
+   * @param prefix             The prefix of the string returned.
+   * @param threadPrefix       Printed before each thread, e.g. "\n\t" to create an indented list.
+   * @param stackElementPrefix Printed before each stack trace element, e.g. "\n\t\t" to create an indented list.
+   * @return a String representation of the currently running threads.
+   */
+  public static String getFormattedThreadList(
+      final String prefix, final String threadPrefix, final String stackElementPrefix) {
+    final StringBuilder message = new StringBuilder(prefix);
+    for (final Map.Entry<Thread, StackTraceElement[]> entry : Thread.getAllStackTraces().entrySet()) {
+      message.append(threadPrefix).append("Thread '").append(entry.getKey().getName()).append("':");
+      for (final StackTraceElement element : entry.getValue()) {
+        message.append(stackElementPrefix).append(element.toString());
+      }
+    }
+    return message.toString();
+  }
+
+  /**
+   * Same as <code>getFormattedThreadList(prefix, "\n\t", "\n\t\t")</code>
+   */
+  public static String getFormattedThreadList(final String prefix) {
+    return getFormattedThreadList(prefix, "\n\t", "\n\t\t");
+  }
+
+  /**
+   * An example how to use the above methods.
+   *
+   * @param args ignored.
+   */
+  public static void main(final String[] args) {
+    logThreads(Logger.getAnonymousLogger(), Level.INFO, "Threads active:");
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/Config.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/Config.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/Config.java
new file mode 100644
index 0000000..b72ecf0
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/Config.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.util.logging;
+
+import java.io.IOException;
+import java.util.logging.LogManager;
+
+public final class Config {
+
+  public Config() throws IOException {
+    LogManager.getLogManager().readConfiguration(
+        Thread.currentThread().getContextClassLoader()
+            .getResourceAsStream("org/apache/reef/logging.properties"));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LogLevelName.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LogLevelName.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LogLevelName.java
new file mode 100644
index 0000000..a25a578
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LogLevelName.java
@@ -0,0 +1,30 @@
+/**
+ * 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.reef.util.logging;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+/**
+ * Name of a log Level as a string such as "INFO", "FINE"
+ */
+@NamedParameter(default_value = "FINE")
+public class LogLevelName implements Name<String> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LogParser.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LogParser.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LogParser.java
new file mode 100644
index 0000000..4f6ed04
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LogParser.java
@@ -0,0 +1,164 @@
+/**
+ * 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.reef.util.logging;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+
+/**
+ * Parse logs for reporting
+ */
+public class LogParser {
+
+  public static String endIndicators[] = {
+      LoggingScopeImpl.EXIT_PREFIX + LoggingScopeFactory.BRIDGE_SETUP,
+      LoggingScopeImpl.EXIT_PREFIX + LoggingScopeFactory.EVALUATOR_SUBMIT,
+      LoggingScopeImpl.EXIT_PREFIX + LoggingScopeFactory.EVALUATOR_BRIDGE_SUBMIT,
+      LoggingScopeImpl.EXIT_PREFIX + LoggingScopeFactory.DRIVER_START,
+      LoggingScopeImpl.EXIT_PREFIX + LoggingScopeFactory.EVALUATOR_LAUNCH,
+      LoggingScopeImpl.EXIT_PREFIX + LoggingScopeFactory.EVALUATOR_ALLOCATED,
+      LoggingScopeImpl.EXIT_PREFIX + LoggingScopeFactory.ACTIVE_CONTEXT,
+      LoggingScopeImpl.EXIT_PREFIX + LoggingScopeFactory.HTTP_REQUEST,
+      LoggingScopeImpl.EXIT_PREFIX + LoggingScopeFactory.TASK_COMPLETE
+  };
+
+  public static String startIndicators[] = {
+      LoggingScopeImpl.START_PREFIX + LoggingScopeFactory.DRIVER_START,
+      LoggingScopeImpl.START_PREFIX + LoggingScopeFactory.BRIDGE_SETUP,
+      LoggingScopeImpl.START_PREFIX + LoggingScopeFactory.EVALUATOR_BRIDGE_SUBMIT,
+      LoggingScopeImpl.START_PREFIX + LoggingScopeFactory.EVALUATOR_SUBMIT,
+      LoggingScopeImpl.START_PREFIX + LoggingScopeFactory.EVALUATOR_ALLOCATED,
+      LoggingScopeImpl.START_PREFIX + LoggingScopeFactory.EVALUATOR_LAUNCH,
+      LoggingScopeImpl.START_PREFIX + LoggingScopeFactory.ACTIVE_CONTEXT,
+      LoggingScopeImpl.START_PREFIX + LoggingScopeFactory.HTTP_REQUEST,
+      LoggingScopeImpl.START_PREFIX + LoggingScopeFactory.TASK_COMPLETE
+  };
+
+  private LogParser() {
+  }
+
+  /**
+   * Get lines from a given file with a specified filter, trim the line by removing strings before removeBeforeToken and after removeAfterToken
+   * @param fileName
+   * @param filter
+   * @return
+   * @throws IOException
+   */
+  public static ArrayList<String> getFilteredLinesFromFile(final String fileName, final String filter, final String removeBeforeToken, final String removeAfterToken) throws IOException{
+    final ArrayList<String> filteredLines = new ArrayList<String>();
+    try (final FileReader fr =  new FileReader(fileName)) {
+      try (final BufferedReader in = new BufferedReader(fr)) {
+        String line = "";
+        while ((line = in.readLine()) != null) {
+          if (line.trim().length() == 0) {
+            continue;
+          }
+          if (line.contains(filter)) {
+            String trimedLine;
+            if (removeBeforeToken != null) {
+              final String[] p = line.split(removeBeforeToken);
+              if (p.length > 1) {
+                trimedLine = p[p.length-1];
+              } else {
+                trimedLine = line.trim();
+              }
+            } else {
+              trimedLine = line.trim();
+            }
+            if (removeAfterToken != null) {
+              final String[] p = trimedLine.split(removeAfterToken);
+              if (p.length > 1) {
+                trimedLine = p[0];
+              }
+            }
+            filteredLines.add(trimedLine);
+          }
+        }
+      }
+    }
+    return filteredLines;
+  }
+
+  /**
+   * get lines from given file with specified filter
+   * @param fileName
+   * @param filter
+   * @return
+   * @throws IOException
+   */
+  public static ArrayList<String> getFilteredLinesFromFile(final String fileName, final String filter) throws IOException {
+    return getFilteredLinesFromFile(fileName, filter, null, null);
+  }
+
+  /**
+   * filter array list of lines and get the last portion of the line separated by the token, like ":::"
+   * @param original
+   * @param filter
+   * @return
+   */
+  public static ArrayList<String> filter(final ArrayList<String> original, final String filter, final String token) {
+    final ArrayList<String> result = new ArrayList<String>();
+    for (String line : original) {
+      if (line.contains(filter)) {
+        final String[] p = line.split(token);
+        if (p.length > 1) {
+          result.add(p[p.length-1]);
+        }
+      }
+    }
+    return result;
+  }
+
+  /**
+   * find lines that contain stage indicators. The stageIndicators must be in sequence which appear in the lines.
+   * @param lines
+   * @param stageIndicators
+   * @return
+   */
+  public static ArrayList<String> findStages(final ArrayList<String> lines, final String[] stageIndicators) {
+    ArrayList<String> stages = new ArrayList<String>();
+
+    int i = 0;
+    for (String line: lines) {
+      if (line.contains(stageIndicators[i])){
+        stages.add(stageIndicators[i]);
+        if (i < stageIndicators.length - 1) {
+          i++;
+        }
+      }
+    }
+    return stages;
+  }
+
+  public static ArrayList<String> mergeStages(ArrayList<String> startStages, ArrayList<String> endStages) {
+    ArrayList<String> mergeStage = new ArrayList<String>();
+    for (int i = 0; i < startStages.size(); i++) {
+      String end = startStages.get(i).replace(LoggingScopeImpl.START_PREFIX, LoggingScopeImpl.EXIT_PREFIX);
+      if (endStages.contains(end)) {
+        mergeStage.add(startStages.get(i)  + "   " + end);
+      } else {
+        mergeStage.add(startStages.get(i));
+      }
+    }
+    return mergeStage;
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LoggingScope.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LoggingScope.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LoggingScope.java
new file mode 100644
index 0000000..56cb779
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LoggingScope.java
@@ -0,0 +1,29 @@
+/**
+ * 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.reef.util.logging;
+
+/**
+ * Log time elapsed for a scope
+ */
+public interface LoggingScope extends AutoCloseable {
+
+  @Override
+  public void close();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LoggingScopeFactory.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LoggingScopeFactory.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LoggingScopeFactory.java
new file mode 100644
index 0000000..6f4bc54
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LoggingScopeFactory.java
@@ -0,0 +1,343 @@
+/**
+ * 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.reef.util.logging;
+
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Create Logging scope objects
+ */
+public class LoggingScopeFactory {
+
+  private static final Logger LOG = Logger.getLogger(LoggingScopeFactory.class.getName());
+  public static final String DRIVER_START = "Driver Start Handler";
+  public static final String DRIVER_STOP = "Driver Stop Handler";
+  public static final String BRIDGE_SETUP = "Bridge setup";
+  public static final String LOAD_LIB = "Load libraries";
+  public static final String EVALUATOR_REQUESTOR = "Evaluator requestor passed to C#";
+  public static final String EVALUATOR_BRIDGE_SUBMIT = "Evaluator request submit cross bridge";
+  public static final String EVALUATOR_SUBMIT = "Evaluator submit";
+  public static final String EVALUATOR_LAUNCH = "Evaluator launch";
+  public static final String EVALUATOR_ALLOCATED = "Evaluator allocated";
+  public static final String EVALUATOR_COMPLETED = "Evaluator completed";
+  public static final String EVALUATOR_FAILED = "Evaluator failed";
+  public static final String ACTIVE_CONTEXT = "Active context created";
+  public static final String TASK_RUNNING = "Task running";
+  public static final String TASK_COMPLETE = "Task complete";
+  public static final String TASK_MESSAGE = "Task message";
+  public static final String CONTEXT_MESSAGE = "Context message";
+  public static final String CONTEXT_CLOSE = "Context close";
+  public static final String DRIVER_RESTART = "Driver restart";
+  public static final String DRIVER_RESTART_COMPLETE = "Driver restart complete";
+  public static final String DRIVER_RESTART_RUNNING_TASK = "Driver restart running task";
+  public static final String DRIVER_RESTART_ACTIVE_CONTEXT = "Driver restart active context";
+  public static final String TASK_SUSPEND = "Task suspend";
+  public static final String DRIVER_SUBMIT = "Driver submit";
+  public static final String REEF_SUBMIT = "Reef submit";
+  public static final String LOCAL_JOB_SUBMIT = "Local job submit";
+  public static final String HTTP_REQUEST = "Http request";
+  public static final String HTTP_SERVER = "Http server";
+
+  /**
+   * Log level. Client can set it through LogLevelName named parameter
+   */
+  private final Level logLevel;
+
+  /**
+   * User can inject a LoggingScopeFactory with injected log level as a string
+   */
+  @Inject
+  private LoggingScopeFactory(@Parameter(LogLevelName.class) final String logLevelName) {
+    this.logLevel = Level.parse(logLevelName);
+  }
+
+  /**
+   * Get a new instance of LoggingScope with specified log level
+   * @param logLevel
+   * @param msg
+   * @return
+   */
+  public static LoggingScope getNewLoggingScope(final Level logLevel, final String msg) {
+    return new LoggingScopeImpl(LOG, logLevel, msg);
+  }
+
+  /**
+   * Get a new instance of LoggingScope with injected LoggingScopeFactory instance
+   * @param msg
+   * @return
+   */
+  public LoggingScope getNewLoggingScope(final String msg) {
+    return new LoggingScopeImpl(LOG, logLevel, msg);
+  }
+
+  /**
+   * Get a new instance of LoggingScope with msg and params through new
+   * @param msg
+   * @param params
+   * @return
+   */
+  public LoggingScope getNewLoggingScope(final String msg, final Object params[]) {
+    return new LoggingScopeImpl(LOG, logLevel, msg, params);
+  }
+
+  /**
+   * The method is to measure the time used to start the driver. It can be inserted to the code between start driver till it is started
+   * @param startTime
+   * @return
+   */
+  public LoggingScope driverStart(final StartTime startTime) {
+    return new LoggingScopeImpl(LOG, logLevel, DRIVER_START + " :" + startTime);
+  }
+
+  /**
+   * The method is to measure the time used to stop the driver. It can be inserted to the code between start driver stop till it is stopped
+   * @param timeStamp
+   * @return
+   */
+  public LoggingScope driverStop(final long timeStamp) {
+    return new LoggingScopeImpl(LOG, logLevel, this.DRIVER_STOP + " :" + timeStamp);
+  }
+
+  /**
+   * The method is to measure the time used to set up Java CRL bridge. It can be inserted to the code between beginning of bridge set up and the end of it
+   * @return
+   */
+  public LoggingScope setupBridge() {
+    return new LoggingScopeImpl(LOG, logLevel, BRIDGE_SETUP);
+  }
+
+  /**
+   * The method is to measure the time used to load global files and libraries
+   * @return
+   */
+  public LoggingScope loadLib() {
+    return new LoggingScopeImpl(LOG, logLevel, LOAD_LIB);
+  }
+
+  /**
+   * The method is to measure the time used to pass EvaluatorRequestor from Java to .Net. It can be inserted to the code between beginning to send EvaluatorRequestor to CLR until it is returned.
+   * @return
+   */
+  public LoggingScope evaluatorRequestorPassToCs() {
+    return new LoggingScopeImpl(LOG, logLevel, EVALUATOR_REQUESTOR);
+  }
+
+  /**
+   * The method is to measure the time used to submit Evaluator request from CLR to Java driver. It can be inserted to evaluator submit() method.
+   * @param evaluatorsNumber
+   * @return
+   */
+  public LoggingScope evaluatorRequestSubmitToJavaDriver(final int evaluatorsNumber) {
+    return new LoggingScopeImpl(LOG, logLevel, EVALUATOR_BRIDGE_SUBMIT + ":" + evaluatorsNumber);
+  }
+
+  /**
+   * The method is to measure the time used to submit a Evaluator request at java side
+   * @param evaluatorNumber
+   * @return
+   */
+  public LoggingScope evaluatorSubmit(final int evaluatorNumber) {
+    return new LoggingScopeImpl(LOG, logLevel, EVALUATOR_SUBMIT + ":" + evaluatorNumber);
+  }
+
+  /**
+   * This is to measure the time on evaluatorAllocated handler
+   * @param evaluatorId
+   * @return
+   */
+  public LoggingScope evaluatorAllocated(final String evaluatorId) {
+    return new LoggingScopeImpl(LOG, logLevel, EVALUATOR_ALLOCATED + " :" + evaluatorId);
+  }
+
+  /**
+   * This is to measure the time to launch an evaluator
+   * @param evaluatorId
+   * @return
+   */
+  public LoggingScope evaluatorLaunch(final String evaluatorId) {
+    return new LoggingScopeImpl(LOG, logLevel, EVALUATOR_LAUNCH + " :" + evaluatorId);
+  }
+
+  /**
+   * This is to measure the time in calling evaluatorCompleted handler
+   * @param evaluatorId
+   * @return
+   */
+  public LoggingScope evaluatorCompleted(final String evaluatorId) {
+    return new LoggingScopeImpl(LOG, logLevel, EVALUATOR_COMPLETED + " :" + evaluatorId);
+  }
+
+  /**
+   * This is to measure the time in calling evaluatorFailed handler
+   * @param evaluatorId
+   * @return
+   */
+  public LoggingScope evaluatorFailed(final String evaluatorId) {
+    return new LoggingScopeImpl(LOG, logLevel, this.EVALUATOR_FAILED + " :" + evaluatorId);
+  }
+
+  /**
+   * This is to measure the time in calling activeContext handler
+   * @param contextId
+   * @return
+   */
+  public LoggingScope activeContextReceived(final String contextId) {
+    return new LoggingScopeImpl(LOG, logLevel, ACTIVE_CONTEXT + " :" + contextId);
+  }
+
+  /**
+   * This is to measure the time in calling closedContext handler
+   * @param contextId
+   * @return
+   */
+  public LoggingScope closedContext(final String contextId) {
+    return new LoggingScopeImpl(LOG, logLevel, this.CONTEXT_CLOSE + " :" + contextId);
+  }
+
+  /**
+   * This is to measure the time in calling runningTaskHandler
+   * @param taskId
+   * @return
+   */
+  public LoggingScope taskRunning(final String taskId) {
+    return new LoggingScopeImpl(LOG, logLevel, TASK_RUNNING + " :" + taskId);
+  }
+
+  /**
+   * This is to measure the time in calling taskCompletedHandler
+   * @param taskId
+   * @return
+   */
+  public LoggingScope taskCompleted(final String taskId) {
+    return new LoggingScopeImpl(LOG, logLevel, TASK_COMPLETE + " :" + taskId);
+  }
+
+  /**
+   * This is to measure the time in calling taskSuspendedHandler
+   * @param taskId
+   * @return
+   */
+  public LoggingScope taskSuspended(final String taskId) {
+    return new LoggingScopeImpl(LOG, logLevel, TASK_SUSPEND + " :" + taskId);
+  }
+
+  /**
+   * This is to measure the time in calling taskMessageReceivedHandler
+   * @param msg
+   * @return
+   */
+  public LoggingScope taskMessageReceived(final String msg) {
+    return new LoggingScopeImpl(LOG, logLevel, TASK_MESSAGE + " :" + msg);
+  }
+
+  /**
+   * This is to measure the time in calling contextMessageReceivedHandler
+   * @param msg
+   * @return
+   */
+  public LoggingScope contextMessageReceived(final String msg) {
+    return new LoggingScopeImpl(LOG, logLevel, CONTEXT_MESSAGE + " :" + msg);
+  }
+
+  /**
+   * This is to measure the time in calling driverRestartHandler
+   * @param startTime
+   * @return
+   */
+  public LoggingScope driverRestart(final StartTime startTime) {
+    return new LoggingScopeImpl(LOG, logLevel, DRIVER_RESTART + " :" + startTime);
+  }
+
+  /**
+   * This is to measure the time in calling driverRestartCompletedHandler
+   * @param timeStamp
+   * @return
+   */
+  public LoggingScope driverRestartCompleted(final long timeStamp) {
+    return new LoggingScopeImpl(LOG, logLevel, DRIVER_RESTART_COMPLETE + " :" + timeStamp);
+  }
+
+  /**
+   * This is to measure the time in calling driverRestartRunningTaskHandler
+   * @param taskId
+   * @return
+   */
+  public LoggingScope driverRestartRunningTask(final String taskId) {
+    return new LoggingScopeImpl(LOG, logLevel, DRIVER_RESTART_RUNNING_TASK + " :" + taskId);
+  }
+
+  /**
+   * This is to measure the time in calling driverRestartActiveContextReceivedHandler
+   * @param contextId
+   * @return
+   */
+  public LoggingScope driverRestartActiveContextReceived(final String contextId) {
+    return new LoggingScopeImpl(LOG, logLevel, DRIVER_RESTART_ACTIVE_CONTEXT + " :" + contextId);
+  }
+
+  /**
+   * This is to measure the time in handling a http request
+   * @param uri
+   * @return
+   */
+  public LoggingScope httpRequest(final String uri) {
+    return new LoggingScopeImpl(LOG, logLevel, this.HTTP_REQUEST + " :" + uri);
+  }
+
+  /**
+   * This is to measure the time used to create HttpServer
+   * @return
+   */
+  public LoggingScope httpServer() {
+    return new LoggingScopeImpl(LOG, logLevel, this.HTTP_SERVER);
+  }
+
+  /**
+   * This is to measure the time to submit a driver
+   * @param submitDriver
+   * @return
+   */
+  public LoggingScope driverSubmit(final Boolean submitDriver) {
+    return new LoggingScopeImpl(LOG, logLevel, DRIVER_SUBMIT + " :" + submitDriver);
+  }
+
+  /**
+   * This is to measure the time to call Reef.Submit
+   * @return
+   */
+  public LoggingScope reefSubmit() {
+    return new LoggingScopeImpl(LOG, logLevel, this.REEF_SUBMIT);
+  }
+
+  /**
+   * This is to measure the time for a job submission
+   * @return
+   */
+  public LoggingScope localJobSubmission() {
+    return new LoggingScopeImpl(LOG, logLevel, this.LOCAL_JOB_SUBMIT);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LoggingScopeImpl.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LoggingScopeImpl.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LoggingScopeImpl.java
new file mode 100644
index 0000000..8475532
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LoggingScopeImpl.java
@@ -0,0 +1,104 @@
+/**
+ * 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.reef.util.logging;
+
+import org.apache.commons.lang3.time.StopWatch;
+import org.apache.reef.util.Optional;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Log time and duration for a scope
+ */
+public class LoggingScopeImpl implements LoggingScope {
+  public static final String TOKEN = ":::";
+  public static final String START_PREFIX = "START" + TOKEN;
+  public static final String EXIT_PREFIX = "EXIT" + TOKEN;
+  public static final String DURATION = " Duration = ";
+
+  private final StopWatch stopWatch = new StopWatch();
+
+  private final Logger logger;
+
+  private final String msg;
+
+  private final Object[] params;
+
+  private final Optional<Object[]> optionalParams;
+
+  private final Level logLevel;
+
+  /**
+   * A constructor of ReefLoggingScope. It starts the timer and logs the msg
+   *
+   * @param logger
+   * @param msg
+   * @param params
+   */
+  LoggingScopeImpl(final Logger logger, final Level logLevel, final String msg, final Object params[]) {
+    this.logger = logger;
+    this.logLevel = logLevel;
+    this.msg = msg;
+    this.params = params;
+    stopWatch.start();
+    this.optionalParams = Optional.ofNullable(params);
+
+    if (logger.isLoggable(logLevel)) {
+      final StringBuilder sb = new StringBuilder();
+      log(sb.append(START_PREFIX).append(msg).toString());
+    }
+  }
+
+  /**
+   * A constructor of ReefLoggingScope.  It starts the timer and and logs the msg.
+   *
+   * @param logger
+   * @param msg
+   */
+  LoggingScopeImpl(final Logger logger, final Level logLevel, final String msg) {
+    this(logger, logLevel, msg, null);
+  }
+
+  /**
+   * The close() will be called when the object is to deleted. It stops the timer and logs the time elapsed.
+   */
+  @Override
+  public void close() {
+    stopWatch.stop();
+
+    if (logger.isLoggable(logLevel)) {
+      final StringBuilder sb = new StringBuilder();
+      log(sb.append(EXIT_PREFIX).append(msg).append(DURATION).append(stopWatch.getTime()).toString());
+    }
+  }
+
+  /**
+   * log massage
+   * @param msg
+   */
+  private void log(final String msg) {
+    if (this.optionalParams.isPresent()) {
+      logger.log(logLevel, msg, params);
+    } else {
+      logger.log(logLevel, msg);
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LoggingSetup.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LoggingSetup.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LoggingSetup.java
new file mode 100644
index 0000000..7d683f0
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/LoggingSetup.java
@@ -0,0 +1,37 @@
+/**
+ * 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.reef.util.logging;
+
+/**
+ * Configure Commons Logging
+ */
+public final class LoggingSetup {
+
+  private LoggingSetup() {
+  }
+
+  /**
+   * Redirect the commons logging to the JDK logger.
+   */
+  public static void setupCommonsLogging() {
+    if (System.getProperty("org.apache.commons.logging.Log") == null) {
+      System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger");
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/ThreadLogFormatter.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/ThreadLogFormatter.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/ThreadLogFormatter.java
new file mode 100644
index 0000000..36cfde6
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/logging/ThreadLogFormatter.java
@@ -0,0 +1,141 @@
+/**
+ * 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.reef.util.logging;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.logging.Formatter;
+import java.util.logging.LogManager;
+import java.util.logging.LogRecord;
+
+/**
+ * A denser logging format for REEF that is similar to the standard SimpleFormatter.
+ * <p/>
+ * The following config properties are available:
+ * <p/>
+ * * `org.apache.reef.util.logging.ThreadLogFormatter.format`
+ * is a format string for String.format() that takes same arguments and in
+ * the same order as the standard SimpleFormatter, plus the thread name:
+ * 1. date
+ * 2. class and method name
+ * 3. logger name
+ * 4. logging level
+ * 5. message
+ * 6. stack trace
+ * 7. thread name
+ * <p/>
+ * * `org.apache.reef.util.logging.ThreadLogFormatter.dropPrefix`
+ * contains a comma-separated list of package name prefixes that should be
+ * removed from the class name for logging. e.g. value `com.microsoft.,org.apache.`
+ * will have the formatter write class `org.apache.reef.util.logging.Config` as
+ * `reef.util.logging.Config`. (Note the dot at the end of the prefix).
+ */
+public final class ThreadLogFormatter extends Formatter {
+
+  private static final String DEFAULT_FORMAT = "%1$tF %1$tT,%1$tL %4$s %2$s %7$s | %5$s%6$s%n";
+
+  private final List<String> dropPrefix = new ArrayList<>();
+  private final Date date = new Date();
+  private final String logFormat;
+
+  public ThreadLogFormatter() {
+
+    super();
+    final LogManager logManager = LogManager.getLogManager();
+    final String className = this.getClass().getName();
+
+    final String format = logManager.getProperty(className + ".format");
+    this.logFormat = format != null ? format : DEFAULT_FORMAT;
+
+    final String rawDropStr = logManager.getProperty(className + ".dropPrefix");
+    if (rawDropStr != null) {
+      for (String prefix : rawDropStr.trim().split(",")) {
+        prefix = prefix.trim();
+        if (!prefix.isEmpty()) {
+          this.dropPrefix.add(prefix);
+        }
+      }
+    }
+  }
+
+  /**
+   * Format the log string. Internally, it uses `String.format()` that takes same
+   * arguments and in the same order as the standard SimpleFormatter, plus the thread name:
+   * 1. date
+   * 2. class and method name
+   * 3. logger name
+   * 4. logging level
+   * 5. message
+   * 6. stack trace
+   * 7. thread name
+   *
+   * @return string to be written to the log.
+   */
+  @Override
+  public String format(final LogRecord logRecord) {
+    this.date.setTime(System.currentTimeMillis());
+    return String.format(
+        this.logFormat,
+        this.date,
+        this.trimPrefix(logRecord.getSourceClassName()) + "." + logRecord.getSourceMethodName(),
+        logRecord.getLoggerName(),
+        logRecord.getLevel().getLocalizedName(),
+        formatMessage(logRecord),
+        this.getStackTrace(logRecord.getThrown()),
+        Thread.currentThread().getName());
+  }
+
+  /**
+   * Check if the class name starts with one of the prefixes specified in `dropPrefix`,
+   * and remove it. e.g. for class name `org.apache.reef.util.logging.Config` and
+   * prefix `com.microsoft.` (note the trailing dot), the result will be
+   * `reef.util.logging.Config`
+   */
+  private String trimPrefix(final String className) {
+    for (final String prefix : this.dropPrefix) {
+      if (className.startsWith(prefix)) {
+        return className.substring(prefix.length());
+      }
+    }
+    return className;
+  }
+
+  /**
+   * @return a string that contains stack trace of a given exception.
+   * if `error` is null, return an empty string.
+   */
+  private String getStackTrace(final Throwable error) {
+    if (error != null) {
+      try (final StringWriter sw = new StringWriter();
+           final PrintWriter pw = new PrintWriter(sw)) {
+        pw.println();
+        error.printStackTrace(pw);
+        return sw.toString();
+      } catch (final IOException ex) {
+        // should never happen
+        throw new RuntimeException("Unexpected error while logging stack trace", ex);
+      }
+    }
+    return "";
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/java/org/apache/reef/util/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/java/org/apache/reef/util/package-info.java b/lang/java/reef-common/src/main/java/org/apache/reef/util/package-info.java
new file mode 100644
index 0000000..f96eef5
--- /dev/null
+++ b/lang/java/reef-common/src/main/java/org/apache/reef/util/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Various utility classes.
+ */
+package org.apache.reef.util;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/proto/client_runtime.proto
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/proto/client_runtime.proto b/lang/java/reef-common/src/main/proto/client_runtime.proto
new file mode 100644
index 0000000..36c648b
--- /dev/null
+++ b/lang/java/reef-common/src/main/proto/client_runtime.proto
@@ -0,0 +1,54 @@
+// 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.
+option java_package = "org.apache.reef.proto";
+option java_outer_classname = "ClientRuntimeProtocol";
+option java_generic_services = true;
+option java_generate_equals_and_hash = true;
+
+import "reef_service_protos.proto";
+
+// Messages from REEF Client -> Driver Runtime
+
+message JobSubmissionProto {
+	required string identifier     = 1; // the job identifier
+	required string remote_id      = 2; // the remote identifier
+	required string configuration  = 5; // the runtime configuration
+	required string user_name      = 6; // the user name
+
+  //optional SIZE   driver_size    = 7; // Removed in REEF 0.3 in favor of driver_memory below.
+  optional int32  driver_memory  = 8;
+  optional int32  priority       = 9;
+  optional string queue          = 10;
+
+	repeated FileResourceProto global_file = 11; // files that should be placed on the driver and all subsequent evaluators
+	repeated FileResourceProto local_File  = 12; // files that should be placed on the driver only
+
+}
+
+enum Signal {
+	SIG_TERMINATE = 1;
+	SIG_SUSPEND   = 2;
+	SIG_RESUME    = 3;
+}
+
+message JobControlProto {
+	required string identifier = 1;
+	optional Signal signal     = 2;
+	optional bytes message     = 3;
+}
+
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/proto/driver_runtime.proto
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/proto/driver_runtime.proto b/lang/java/reef-common/src/main/proto/driver_runtime.proto
new file mode 100644
index 0000000..64f5dc1
--- /dev/null
+++ b/lang/java/reef-common/src/main/proto/driver_runtime.proto
@@ -0,0 +1,89 @@
+// 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.
+option java_package = "org.apache.reef.proto";
+option java_outer_classname = "DriverRuntimeProtocol";
+option java_generic_services = true;
+option java_generate_equals_and_hash = true;
+
+
+import "reef_service_protos.proto";
+
+// Messages from Driver Runtime -> Driver Process
+
+message DriverProcessRegistrationProto {
+	required string remote_identifier = 1;
+}
+
+
+message NodeDescriptorProto {
+	required string identifier = 1;
+	required string host_name  = 2; // e.g., IP address
+	required int32 port        = 3; // e.g., IP port
+	required int32 memory_size = 4;
+	optional string rack_name  = 5; // e.g., /default-rack
+}
+
+message ResourceAllocationProto {
+	required string identifier     = 1; // e.g., the container id, or the thread id
+	required int32 resource_memory = 2; // megabytes
+	required string node_id        = 3;
+	optional int32 virtual_cores   = 4;
+}
+
+message ResourceStatusProto {
+	required string identifier   = 1;
+	required State  state        = 2;
+	optional string diagnostics  = 3;
+	optional int32  exit_code    = 4;
+	optional bool is_from_previous_driver = 5;
+}
+
+message RuntimeStatusProto {
+   required string name  = 1;   // e.g., local, yarn21
+   required State  state = 2;
+   optional RuntimeErrorProto error = 3; // runtime (e.g., YARN) error
+
+   optional int32 outstanding_container_requests = 5;
+   repeated string container_allocation = 6;
+}
+
+//////////////////////////////////////////////////////
+// Messages from Driver Process -> Driver Runtime
+
+message ResourceRequestProto {
+	// optional SIZE resource_size  = 1; // Removed in REEF 0.3 in favor of memory_size.
+    optional int32 memory_size    = 2; // Memory size of the evaluator in MB
+    optional int32 priority       = 3;
+    optional int32 virtual_cores  = 4;
+    required int32 resource_count = 5;
+	  repeated string node_name     = 6; // a list of specific nodes
+	  repeated string rack_name     = 7; // a list of specific racks
+
+    optional bool relax_locality = 10;
+}
+
+message ResourceReleaseProto {
+	required string identifier = 1;
+}
+
+message ResourceLaunchProto {
+	required string identifier      = 1;
+	required string remote_id       = 2;
+	required string evaluator_conf  = 3;
+  required ProcessType type       = 4;
+	repeated FileResourceProto file = 10;
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/proto/evaluator_runtime.proto
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/proto/evaluator_runtime.proto b/lang/java/reef-common/src/main/proto/evaluator_runtime.proto
new file mode 100644
index 0000000..ea07ea0
--- /dev/null
+++ b/lang/java/reef-common/src/main/proto/evaluator_runtime.proto
@@ -0,0 +1,90 @@
+// 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.
+
+option java_package = "org.apache.reef.proto";
+option java_outer_classname = "EvaluatorRuntimeProtocol";
+option java_generic_services = true;
+option java_generate_equals_and_hash = true;
+
+import "reef_service_protos.proto";
+
+// Stop the evaluator
+message StopEvaluatorProto {
+}
+
+// Kill the evaluator
+message KillEvaluatorProto {
+}
+
+// Start a task
+message StartTaskProto {
+    required string context_id = 1;
+    required string configuration = 2;
+}
+
+message AddContextProto {
+    required string parent_context_id = 1;
+    required string context_configuration = 2;
+    optional string service_configuration = 3;
+}
+
+message RemoveContextProto {
+    required string context_id = 1;
+}
+
+// Stop the task
+message StopTaskProto {
+}
+
+// Suspend the task
+message SuspendTaskProto {
+}
+
+/////////////////////////////////////////
+// Message aggregators
+
+message ContextMessageProto {
+    required string context_id = 1;
+    required bytes message = 2;
+}
+
+message ContextControlProto {
+    optional bytes task_message = 1;
+    optional ContextMessageProto context_message = 2;
+
+    optional AddContextProto    add_context    = 5;
+    optional RemoveContextProto remove_context = 6;
+    optional StartTaskProto     start_task     = 7;
+    optional StopTaskProto      stop_task      = 8;
+    optional SuspendTaskProto   suspend_task   = 9;
+}
+
+message EvaluatorHeartbeatProto {
+    required int64 timestamp = 1;
+    required EvaluatorStatusProto evaluator_status = 2;
+    repeated ContextStatusProto   context_status   = 3;
+    optional TaskStatusProto      task_status      = 4;
+    optional bool                 recovery         = 5;  
+}
+
+message EvaluatorControlProto {
+    required int64 timestamp = 1;
+    required string identifier = 2;
+
+    optional ContextControlProto context_control = 3;
+    optional KillEvaluatorProto kill_evaluator = 4;
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/proto/reef_protocol.proto
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/proto/reef_protocol.proto b/lang/java/reef-common/src/main/proto/reef_protocol.proto
new file mode 100644
index 0000000..a8c793f
--- /dev/null
+++ b/lang/java/reef-common/src/main/proto/reef_protocol.proto
@@ -0,0 +1,42 @@
+// 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.
+import "client_runtime.proto";
+
+import "evaluator_runtime.proto";
+
+import "reef_service_protos.proto";
+
+
+option java_package = "org.apache.reef.proto";
+
+option java_generic_services = true;
+
+option java_generate_equals_and_hash = true;
+
+option java_outer_classname = "REEFProtocol";
+
+message REEFMessage {
+    // Messages defined in client_runtime.proto
+    optional JobSubmissionProto jobSubmission = 1;
+    optional JobControlProto jobControl = 2;
+    // Messages defined in reef_service_protos.proto
+    optional RuntimeErrorProto runtimeError = 3;
+    optional JobStatusProto jobStatus = 4;
+    // Messages from evaluator_runtime.proto
+    optional EvaluatorControlProto evaluatorControl = 5;
+    optional EvaluatorHeartbeatProto evaluatorHeartBeat = 6;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/proto/reef_service_protos.proto
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/proto/reef_service_protos.proto b/lang/java/reef-common/src/main/proto/reef_service_protos.proto
new file mode 100644
index 0000000..7494737
--- /dev/null
+++ b/lang/java/reef-common/src/main/proto/reef_service_protos.proto
@@ -0,0 +1,116 @@
+// 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.
+
+option java_package = "org.apache.reef.proto";
+
+option java_outer_classname = "ReefServiceProtos";
+
+option java_generic_services = true;
+
+option java_generate_equals_and_hash = true;
+
+enum State {
+    INIT = 0;
+    RUNNING = 1;
+    DONE = 2;
+    SUSPEND = 3;
+    FAILED = 4;
+    KILLED = 5;
+}
+
+enum FileType {
+    PLAIN = 0;
+    LIB = 1;
+    ARCHIVE = 2;
+}
+
+// Removed in REEF 0.3 in favor of explicit memory sizes.
+// enum SIZE {
+//    SMALL = 0;
+//    MEDIUM = 1;
+//    LARGE = 2;
+//    XLARGE = 3;
+//}
+
+enum ProcessType {
+    JVM = 0;
+    CLR = 1;
+}
+
+message FileResourceProto {
+    required FileType type = 1;
+    required string name = 2;
+    required string path = 3;
+}
+
+message RuntimeErrorProto {
+    required string name = 1; // e.g., local, yarn21
+    required string message = 2;
+    optional bytes exception = 3;
+
+    optional string identifier = 5; // e.g., evaluator id
+}
+
+message JobStatusProto {
+    required string identifier = 1;
+    required State state = 2;
+    optional bytes message = 3;
+    optional bytes exception = 4;
+}
+
+message ContextStatusProto {
+    enum State {
+        READY = 0;
+        DONE = 1;
+        FAIL = 2;
+    }
+    required State context_state = 1;
+
+    required string context_id = 2;
+    optional string parent_id = 3;
+
+    optional bytes error = 5; // when creating the context
+
+    optional bool recovery = 6;
+    // Context messages
+    message ContextMessageProto {
+        required string source_id = 1;
+        required bytes message = 2;
+    }
+    repeated ContextMessageProto context_message = 7;
+}
+
+message TaskStatusProto {
+    required string task_id = 1;
+    required string context_id = 2;
+    required State state = 3;
+    optional bytes result = 4; // e.g., return value from Task.call()
+    optional bool  recovery = 5;
+
+    // TaskMessageSource messages
+    message TaskMessageProto {
+        required string source_id = 1;
+        required bytes message = 2;
+    }
+    repeated TaskMessageProto task_message = 6;
+}
+
+message EvaluatorStatusProto {
+    required string evaluator_id = 1;
+    required State state = 2;
+    optional bytes error = 3;
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/resources/log4j.properties b/lang/java/reef-common/src/main/resources/log4j.properties
new file mode 100644
index 0000000..f80a941
--- /dev/null
+++ b/lang/java/reef-common/src/main/resources/log4j.properties
@@ -0,0 +1,27 @@
+#
+# 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.
+#
+
+# Set root logger level to DEBUG and its only appender to stderr.
+log4j.rootLogger=DEBUG, stderr
+
+log4j.appender.stderr=org.apache.log4j.ConsoleAppender
+log4j.appender.stderr.layout=org.apache.log4j.PatternLayout
+
+# Pattern to output the caller's file name and line number.
+log4j.appender.stderr.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %p %C %M %t %m%n


[21/51] [partial] incubator-reef git commit: [REEF-93] Move java sources to lang/java

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ProcessContainer.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ProcessContainer.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ProcessContainer.java
new file mode 100644
index 0000000..cdd8b90
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ProcessContainer.java
@@ -0,0 +1,178 @@
+/**
+ * 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.reef.runtime.local.driver;
+
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.annotations.audience.TaskSide;
+import org.apache.reef.runtime.common.files.REEFFileNames;
+import org.apache.reef.runtime.local.process.ReefRunnableProcessObserver;
+import org.apache.reef.runtime.local.process.RunnableProcess;
+import org.apache.reef.runtime.local.process.RunnableProcessObserver;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A Container that runs an Evaluator in a Process
+ */
+@Private
+@TaskSide
+final class ProcessContainer implements Container {
+
+  private static final Logger LOG = Logger.getLogger(ProcessContainer.class.getName());
+
+  private final String errorHandlerRID;
+  private final String nodeID;
+  private final File folder;
+  private final String containedID;
+  private final int megaBytes;
+  private final int numberOfCores;
+  private final REEFFileNames fileNames;
+  private final File reefFolder;
+  private final File localFolder;
+  private final File globalFolder;
+  private final RunnableProcessObserver processObserver;
+  private Thread theThread;
+  private RunnableProcess process;
+
+  /**
+   * @param errorHandlerRID the remoteID of the error handler.
+   * @param nodeID          the ID of the (fake) node this Container is instantiated on
+   * @param containedID     the  ID used to identify this container uniquely
+   * @param folder          the folder in which logs etc. will be deposited
+   */
+  ProcessContainer(final String errorHandlerRID,
+                   final String nodeID,
+                   final String containedID,
+                   final File folder,
+                   final int megaBytes,
+                   final int numberOfCores,
+                   final REEFFileNames fileNames,
+                   final ReefRunnableProcessObserver processObserver) {
+    this.errorHandlerRID = errorHandlerRID;
+    this.nodeID = nodeID;
+    this.containedID = containedID;
+    this.folder = folder;
+    this.megaBytes = megaBytes;
+    this.numberOfCores = numberOfCores;
+    this.fileNames = fileNames;
+    this.processObserver = processObserver;
+    this.reefFolder = new File(folder, fileNames.getREEFFolderName());
+    this.localFolder = new File(reefFolder, fileNames.getLocalFolderName());
+    this.localFolder.mkdirs();
+    this.globalFolder = new File(reefFolder, fileNames.getGlobalFolderName());
+    this.globalFolder.mkdirs();
+  }
+
+  private static void copy(final Iterable<File> files, final File folder) throws IOException {
+    for (final File sourceFile : files) {
+      final File destinationFile = new File(folder, sourceFile.getName());
+      if (Files.isSymbolicLink(sourceFile.toPath())) {
+        final Path linkTargetPath = Files.readSymbolicLink(sourceFile.toPath());
+        Files.createSymbolicLink(destinationFile.toPath(), linkTargetPath);
+      } else {
+        Files.copy(sourceFile.toPath(), destinationFile.toPath());
+      }
+    }
+  }
+
+  @Override
+  public void addLocalFiles(final Iterable<File> files) {
+    try {
+      copy(files, this.localFolder);
+    } catch (final IOException e) {
+      throw new RuntimeException("Unable to copy files to the evaluator folder.", e);
+    }
+  }
+
+  @Override
+  public void addGlobalFiles(final File globalFolder) {
+    try {
+      copy(Arrays.asList(globalFolder.listFiles()), this.globalFolder);
+    } catch (final IOException e) {
+      throw new RuntimeException("Unable to copy files to the evaluator folder.", e);
+    }
+  }
+
+  @Override
+  public void run(final List<String> commandLine) {
+    this.process = new RunnableProcess(commandLine,
+        this.containedID,
+        this.folder,
+        this.processObserver,
+        this.fileNames.getEvaluatorStdoutFileName(),
+        this.fileNames.getEvaluatorStderrFileName());
+    this.theThread = new Thread(this.process);
+    this.theThread.start();
+  }
+
+  @Override
+  public final boolean isRunning() {
+    return null != this.theThread && this.theThread.isAlive();
+  }
+
+  @Override
+  public final int getMemory() {
+    return this.megaBytes;
+  }
+
+  @Override
+  public final int getNumberOfCores() {
+    return this.numberOfCores;
+  }
+
+  @Override
+  public File getFolder() {
+    return this.folder;
+  }
+
+  @Override
+  public String getNodeID() {
+    return this.nodeID;
+  }
+
+  @Override
+  public String getContainerID() {
+    return this.containedID;
+  }
+
+  @Override
+  public void close() {
+    if (isRunning()) {
+      LOG.log(Level.WARNING, "Force-closing a container that is still running: {0}", this);
+      this.process.cancel();
+    }
+  }
+
+  @Override
+  public String toString() {
+    return "ProcessContainer{" +
+        "containedID='" + containedID + '\'' +
+        ", nodeID='" + nodeID + '\'' +
+        ", errorHandlerRID='" + errorHandlerRID + '\'' +
+        ", folder=" + folder +
+        '}';
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ResourceManager.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ResourceManager.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ResourceManager.java
new file mode 100644
index 0000000..9708e77
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ResourceManager.java
@@ -0,0 +1,270 @@
+/**
+ * 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.reef.runtime.local.driver;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.driver.api.RuntimeParameters;
+import org.apache.reef.runtime.common.files.ClasspathProvider;
+import org.apache.reef.runtime.common.files.REEFFileNames;
+import org.apache.reef.runtime.common.launch.CLRLaunchCommandBuilder;
+import org.apache.reef.runtime.common.launch.JavaLaunchCommandBuilder;
+import org.apache.reef.runtime.common.launch.LaunchCommandBuilder;
+import org.apache.reef.runtime.common.parameters.JVMHeapSlack;
+import org.apache.reef.runtime.common.utils.RemoteManager;
+import org.apache.reef.runtime.local.client.parameters.DefaultMemorySize;
+import org.apache.reef.runtime.local.client.parameters.DefaultNumberOfCores;
+import org.apache.reef.runtime.local.driver.parameters.GlobalFiles;
+import org.apache.reef.runtime.local.driver.parameters.GlobalLibraries;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.formats.ConfigurationSerializer;
+import org.apache.reef.util.logging.LoggingScope;
+import org.apache.reef.util.logging.LoggingScopeFactory;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A resource manager that uses threads to execute containers.
+ */
+@Private
+@DriverSide
+public final class ResourceManager {
+
+  private final static Logger LOG = Logger.getLogger(ResourceManager.class.getName());
+
+  private final ResourceRequestQueue requestQueue = new ResourceRequestQueue();
+
+  private final EventHandler<DriverRuntimeProtocol.ResourceAllocationProto> allocationHandler;
+  private final ContainerManager theContainers;
+  private final EventHandler<DriverRuntimeProtocol.RuntimeStatusProto> runtimeStatusHandlerEventHandler;
+  private final int defaultMemorySize;
+  private final int defaultNumberOfCores;
+  private final ConfigurationSerializer configurationSerializer;
+  private final RemoteManager remoteManager;
+  private final REEFFileNames fileNames;
+  private final ClasspathProvider classpathProvider;
+  private final double jvmHeapFactor;
+  private final LoggingScopeFactory loggingScopeFactory;
+
+  @Inject
+  ResourceManager(
+      final ContainerManager containerManager,
+      final @Parameter(RuntimeParameters.ResourceAllocationHandler.class) EventHandler<DriverRuntimeProtocol.ResourceAllocationProto> allocationHandler,
+      final @Parameter(RuntimeParameters.RuntimeStatusHandler.class) EventHandler<DriverRuntimeProtocol.RuntimeStatusProto> runtimeStatusHandlerEventHandler,
+      final @Parameter(GlobalLibraries.class) Set<String> globalLibraries,
+      final @Parameter(GlobalFiles.class) Set<String> globalFiles,
+      final @Parameter(DefaultMemorySize.class) int defaultMemorySize,
+      final @Parameter(DefaultNumberOfCores.class) int defaultNumberOfCores,
+      final @Parameter(JVMHeapSlack.class) double jvmHeapSlack,
+      final ConfigurationSerializer configurationSerializer,
+      final RemoteManager remoteManager,
+      final REEFFileNames fileNames,
+      final ClasspathProvider classpathProvider,
+      final LoggingScopeFactory loggingScopeFactory) {
+
+    this.theContainers = containerManager;
+    this.allocationHandler = allocationHandler;
+    this.runtimeStatusHandlerEventHandler = runtimeStatusHandlerEventHandler;
+    this.configurationSerializer = configurationSerializer;
+    this.remoteManager = remoteManager;
+    this.defaultMemorySize = defaultMemorySize;
+    this.defaultNumberOfCores = defaultNumberOfCores;
+    this.fileNames = fileNames;
+    this.classpathProvider = classpathProvider;
+    this.jvmHeapFactor = 1.0 - jvmHeapSlack;
+    this.loggingScopeFactory = loggingScopeFactory;
+
+    LOG.log(Level.FINE, "Instantiated 'ResourceManager'");
+  }
+
+  /**
+   * Extracts the files out of the launchRequest.
+   *
+   * @param launchRequest the ResourceLaunchProto to parse
+   * @return a list of files set in the given ResourceLaunchProto
+   */
+  private static List<File> getLocalFiles(final DriverRuntimeProtocol.ResourceLaunchProto launchRequest) {
+    final List<File> files = new ArrayList<>();  // Libraries local to this evaluator
+    for (final ReefServiceProtos.FileResourceProto frp : launchRequest.getFileList()) {
+      files.add(new File(frp.getPath()).getAbsoluteFile());
+    }
+    return files;
+  }
+
+  /**
+   * Receives a resource request.
+   * <p/>
+   * If the request can be met, it will also be satisfied immediately.
+   *
+   * @param resourceRequest the resource request to be handled.
+   */
+  final void onResourceRequest(final DriverRuntimeProtocol.ResourceRequestProto resourceRequest) {
+    synchronized (this.theContainers) {
+      this.requestQueue.add(new ResourceRequest(resourceRequest));
+      this.checkRequestQueue();
+    }
+  }
+
+  /**
+   * Receives and processes a resource release request.
+   *
+   * @param releaseRequest the release request to be processed
+   */
+  final void onResourceReleaseRequest(final DriverRuntimeProtocol.ResourceReleaseProto releaseRequest) {
+    synchronized (this.theContainers) {
+      LOG.log(Level.FINEST, "Release container: {0}", releaseRequest.getIdentifier());
+      this.theContainers.release(releaseRequest.getIdentifier());
+      this.checkRequestQueue();
+    }
+  }
+
+  /**
+   * Called when the ReefRunnableProcessObserver detects that the Evaluator process has exited.
+   *
+   * @param evaluatorId the ID of the Evaluator that exited.
+   */
+  public final void onEvaluatorExit(final String evaluatorId) {
+    synchronized (this.theContainers) {
+      this.theContainers.release(evaluatorId);
+      this.checkRequestQueue();
+    }
+  }
+
+  /**
+   * Processes a resource launch request.
+   *
+   * @param launchRequest the launch request to be processed.
+   */
+  final void onResourceLaunchRequest(
+      final DriverRuntimeProtocol.ResourceLaunchProto launchRequest) {
+
+    synchronized (this.theContainers) {
+
+      final Container c = this.theContainers.get(launchRequest.getIdentifier());
+
+      try (final LoggingScope lb = this.loggingScopeFactory.getNewLoggingScope("ResourceManager.onResourceLaunchRequest:evaluatorConfigurationFile")) {
+        // Add the global files and libraries.
+        c.addGlobalFiles(this.fileNames.getGlobalFolder());
+        c.addLocalFiles(getLocalFiles(launchRequest));
+
+        // Make the configuration file of the evaluator.
+        final File evaluatorConfigurationFile = new File(c.getFolder(), fileNames.getEvaluatorConfigurationPath());
+
+        try {
+          this.configurationSerializer.toFile(this.configurationSerializer.fromString(launchRequest.getEvaluatorConf()),
+              evaluatorConfigurationFile);
+        } catch (final IOException | BindException e) {
+          throw new RuntimeException("Unable to write configuration.", e);
+        }
+      }
+
+      try (final LoggingScope lc = this.loggingScopeFactory.getNewLoggingScope("ResourceManager.onResourceLaunchRequest:runCommand")) {
+        // Assemble the command line
+        final LaunchCommandBuilder commandBuilder;
+        switch (launchRequest.getType()) {
+          case JVM:
+            commandBuilder = new JavaLaunchCommandBuilder()
+                .setClassPath(this.classpathProvider.getEvaluatorClasspath());
+            break;
+          case CLR:
+            commandBuilder = new CLRLaunchCommandBuilder();
+            break;
+          default:
+            throw new IllegalArgumentException(
+                "Unsupported container type: " + launchRequest.getType());
+        }
+
+        final List<String> command = commandBuilder
+            .setErrorHandlerRID(this.remoteManager.getMyIdentifier())
+            .setLaunchID(c.getNodeID())
+            .setConfigurationFileName(this.fileNames.getEvaluatorConfigurationPath())
+            .setMemory((int) (this.jvmHeapFactor * c.getMemory()))
+            .build();
+
+        LOG.log(Level.FINEST, "Launching container: {0}", c);
+        c.run(command);
+      }
+    }
+  }
+
+  /**
+   * Checks the allocation queue for new allocations and if there are any
+   * satisfies them.
+   */
+  private void checkRequestQueue() {
+
+    if (this.theContainers.hasContainerAvailable() && this.requestQueue.hasOutStandingRequests()) {
+
+      // Record the satisfaction of one request and get its details.
+      final DriverRuntimeProtocol.ResourceRequestProto requestProto = this.requestQueue.satisfyOne();
+
+      // Allocate a Container
+      final Container container = this.theContainers.allocateOne(
+          requestProto.hasMemorySize() ? requestProto.getMemorySize() : this.defaultMemorySize,
+          requestProto.hasVirtualCores() ? requestProto.getVirtualCores() : this.defaultNumberOfCores);
+
+      // Tell the receivers about it
+      final DriverRuntimeProtocol.ResourceAllocationProto alloc =
+          DriverRuntimeProtocol.ResourceAllocationProto.newBuilder()
+              .setIdentifier(container.getContainerID())
+              .setNodeId(container.getNodeID())
+              .setResourceMemory(container.getMemory())
+              .setVirtualCores(container.getNumberOfCores())
+              .build();
+
+      LOG.log(Level.FINEST, "Allocating container: {0}", container);
+      this.allocationHandler.onNext(alloc);
+
+      // update REEF
+      this.sendRuntimeStatus();
+
+      // Check whether we can satisfy another one.
+      this.checkRequestQueue();
+
+    } else {
+      this.sendRuntimeStatus();
+    }
+  }
+
+  private void sendRuntimeStatus() {
+
+    final DriverRuntimeProtocol.RuntimeStatusProto msg =
+        DriverRuntimeProtocol.RuntimeStatusProto.newBuilder()
+            .setName("LOCAL")
+            .setState(ReefServiceProtos.State.RUNNING)
+            .setOutstandingContainerRequests(this.requestQueue.getNumberOfOutstandingRequests())
+            .addAllContainerAllocation(this.theContainers.getAllocatedContainerIDs())
+            .build();
+
+    LOG.log(Level.INFO, "Allocated: {0}, Outstanding requests: {1}",
+        new Object[]{msg.getContainerAllocationCount(), msg.getOutstandingContainerRequests()});
+    this.runtimeStatusHandlerEventHandler.onNext(msg);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ResourceRequest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ResourceRequest.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ResourceRequest.java
new file mode 100644
index 0000000..bbb20a3
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ResourceRequest.java
@@ -0,0 +1,63 @@
+/**
+ * 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.reef.runtime.local.driver;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+
+/**
+ * Manages a ResourceRequestProto and its satisfaction.
+ */
+@Private
+@DriverSide
+final class ResourceRequest {
+
+  private final DriverRuntimeProtocol.ResourceRequestProto req;
+  private int satisfied = 0;
+
+  ResourceRequest(final DriverRuntimeProtocol.ResourceRequestProto req) {
+    if (null == req) {
+      throw new IllegalArgumentException("Can't instantiate a ResourceRequest without a ResourceRequestProto");
+    }
+    this.req = req;
+  }
+
+  /**
+   * Records that one resource has been allocated to this Request.
+   */
+  final void satisfyOne() {
+    this.satisfied += 1;
+    if (this.satisfied > req.getResourceCount()) {
+      throw new IllegalStateException("This request has been oversatisfied.");
+    }
+  }
+
+  /**
+   * @return true if the request is satisfied with this additional unit of
+   * resource, false otherwise.
+   */
+  final boolean isSatisfied() {
+    return this.satisfied == req.getResourceCount();
+  }
+
+  final DriverRuntimeProtocol.ResourceRequestProto getRequestProto() {
+    return this.req;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ResourceRequestQueue.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ResourceRequestQueue.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ResourceRequestQueue.java
new file mode 100644
index 0000000..c2a87ff
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/ResourceRequestQueue.java
@@ -0,0 +1,70 @@
+/**
+ * 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.reef.runtime.local.driver;
+
+import org.apache.reef.annotations.audience.DriverSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Manages a queue of resource requests.
+ */
+@Private
+@DriverSide
+final class ResourceRequestQueue {
+
+  private final BlockingQueue<ResourceRequest> requestQueue = new LinkedBlockingQueue<>();
+
+  /**
+   * Add a request to the end of the queue.
+   *
+   * @param req the request to be added.
+   */
+  final void add(final ResourceRequest req) {
+    this.requestQueue.add(req);
+  }
+
+  /**
+   * @return true if there are outstanding resource requests. false otherwise.
+   */
+  final boolean hasOutStandingRequests() {
+    return !this.requestQueue.isEmpty();
+  }
+
+  /**
+   * Satisfies one resource for the front-most request. If that satisfies the
+   * request, it is removed from the queue.
+   */
+  final synchronized DriverRuntimeProtocol.ResourceRequestProto satisfyOne() {
+    final ResourceRequest req = this.requestQueue.element();
+    req.satisfyOne();
+    if (req.isSatisfied()) {
+      this.requestQueue.poll();
+    }
+    return req.getRequestProto();
+  }
+
+  final synchronized int getNumberOfOutstandingRequests() {
+    return this.requestQueue.size();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/package-info.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/package-info.java
new file mode 100644
index 0000000..d79462d
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * The resource manager for the local resourcemanager
+ */
+package org.apache.reef.runtime.local.driver;

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/GlobalFiles.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/GlobalFiles.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/GlobalFiles.java
new file mode 100644
index 0000000..489054f
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/GlobalFiles.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.runtime.local.driver.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+import java.util.Set;
+
+/**
+ * The names of files that are to be copied to all evaluators.
+ */
+@NamedParameter(doc = "The names of files that are to be copied to all evaluators.")
+public final class GlobalFiles implements Name<Set<String>> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/GlobalLibraries.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/GlobalLibraries.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/GlobalLibraries.java
new file mode 100644
index 0000000..1912829
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/GlobalLibraries.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.runtime.local.driver.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+import java.util.Set;
+
+/**
+ * The names of files that are to be copied to all evaluators.
+ */
+@NamedParameter(doc = "The names of files that are to be copied to all evaluators.")
+public final class GlobalLibraries implements Name<Set<String>> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/LocalFiles.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/LocalFiles.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/LocalFiles.java
new file mode 100644
index 0000000..87226cf
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/LocalFiles.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.runtime.local.driver.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+import java.util.Set;
+
+/**
+ * Created by marku_000 on 2014-07-07.
+ */
+@NamedParameter(doc = "The names of files that are to be kept on the driver only.")
+public final class LocalFiles implements Name<Set<String>> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/LocalLibraries.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/LocalLibraries.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/LocalLibraries.java
new file mode 100644
index 0000000..0aefb2b
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/LocalLibraries.java
@@ -0,0 +1,31 @@
+/**
+ * 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.reef.runtime.local.driver.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+import java.util.Set;
+
+/**
+ * The names of files that are to be kept on the driver only.
+ */
+@NamedParameter(doc = "The names of files that are to be kept on the driver only.")
+public final class LocalLibraries implements Name<Set<String>> {
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/package-info.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/package-info.java
new file mode 100644
index 0000000..fccf5c7
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/driver/parameters/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * The named parameters for the Driver executed on the local runtime
+ */
+package org.apache.reef.runtime.local.driver.parameters;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/LoggingRunnableProcessObserver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/LoggingRunnableProcessObserver.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/LoggingRunnableProcessObserver.java
new file mode 100644
index 0000000..dd0d75e
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/LoggingRunnableProcessObserver.java
@@ -0,0 +1,44 @@
+/**
+ * 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.reef.runtime.local.process;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A RunnableProcessObserver that logs the events/
+ */
+public final class LoggingRunnableProcessObserver implements RunnableProcessObserver {
+  private static final Logger LOG = Logger.getLogger(LoggingRunnableProcessObserver.class.getName());
+
+  @Override
+  public void onProcessStarted(final String processId) {
+    LOG.log(Level.FINE, "Process {0} started.", processId);
+
+  }
+
+  @Override
+  public void onProcessExit(final String processId, final int exitCode) {
+    if (exitCode == 0) {
+      LOG.log(Level.FINE, "Process {0} exited with return code 0.", processId);
+    } else {
+      LOG.log(Level.WARNING, "Process {0} exited with return code {1}.", new Object[]{processId, exitCode});
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/ReefRunnableProcessObserver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/ReefRunnableProcessObserver.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/ReefRunnableProcessObserver.java
new file mode 100644
index 0000000..36ee916
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/ReefRunnableProcessObserver.java
@@ -0,0 +1,125 @@
+/**
+ * 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.reef.runtime.local.process;
+
+import net.jcip.annotations.ThreadSafe;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.proto.ReefServiceProtos;
+import org.apache.reef.runtime.common.driver.api.RuntimeParameters;
+import org.apache.reef.runtime.local.driver.ResourceManager;
+import org.apache.reef.tang.InjectionFuture;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.wake.EventHandler;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * a RunnableProcessObserver that relies events to REEF's ResourceStatusHandler
+ */
+@ThreadSafe
+public final class ReefRunnableProcessObserver implements RunnableProcessObserver {
+  private static final Logger LOG = Logger.getLogger(ReefRunnableProcessObserver.class.getName());
+
+  private final EventHandler<DriverRuntimeProtocol.ResourceStatusProto> resourceStatusHandler;
+  private final InjectionFuture<ResourceManager> resourceManager;
+
+  /**
+   * @param resourceStatusHandler the event handler to inform of resource changes.
+   */
+  @Inject
+  public ReefRunnableProcessObserver(final @Parameter(RuntimeParameters.ResourceStatusHandler.class)
+                                     EventHandler<DriverRuntimeProtocol.ResourceStatusProto> resourceStatusHandler,
+                                     final InjectionFuture<ResourceManager> resourceManager) {
+    this.resourceStatusHandler = resourceStatusHandler;
+    this.resourceManager = resourceManager;
+  }
+
+  @Override
+  public void onProcessStarted(final String processId) {
+    this.onResourceStatus(
+        DriverRuntimeProtocol.ResourceStatusProto.newBuilder()
+            .setIdentifier(processId)
+            .setState(ReefServiceProtos.State.RUNNING)
+            .build()
+    );
+  }
+
+  @Override
+  public void onProcessExit(final String processId, final int exitCode) {
+    // Note that the order here matters: We need to first inform the Driver's event handlers about the process exit
+    // and then release the resources. Otherwise, the Driver might be shutdown because of an idle condition before the
+    // message about the evaluator exit could have been sent and processed.
+    switch (exitCode) {
+      case 0:
+        this.onCleanExit(processId);
+        break;
+      default:
+        this.onUncleanExit(processId, exitCode);
+    }
+    this.resourceManager.get().onEvaluatorExit(processId);
+  }
+
+  /**
+   * Inform REEF of a cleanly exited process.
+   *
+   * @param processId
+   */
+  private void onCleanExit(final String processId) {
+    this.onResourceStatus(
+        DriverRuntimeProtocol.ResourceStatusProto.newBuilder()
+            .setIdentifier(processId)
+            .setState(ReefServiceProtos.State.DONE)
+            .setExitCode(0)
+            .build()
+    );
+  }
+
+  /**
+   * Inform REEF of an unclean process exit
+   *
+   * @param processId
+   * @param exitCode
+   */
+  private void onUncleanExit(final String processId, final int exitCode) {
+    this.onResourceStatus(
+        DriverRuntimeProtocol.ResourceStatusProto.newBuilder()
+            .setIdentifier(processId)
+            .setState(ReefServiceProtos.State.FAILED)
+            .setExitCode(exitCode)
+            .build()
+    );
+  }
+
+  private void onResourceStatus(final DriverRuntimeProtocol.ResourceStatusProto resourceStatus) {
+    LOG.log(Level.INFO, "Sending resource status: {0} ", resourceStatus);
+
+    // Here, we introduce an arbitrary wait. This is to make sure that at the exit of an Evaluator, the last
+    // heartbeat from that Evaluator arrives before this message. This makes sure that the local runtime behaves like
+    // a resource manager with regard to that timing.
+    try {
+      Thread.sleep(100);
+    } catch (final InterruptedException e) {
+      LOG.log(Level.FINEST, "Sleep interrupted. Event will be fired earlier than usual.");
+    }
+    this.resourceStatusHandler.onNext(resourceStatus);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/RunnableProcess.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/RunnableProcess.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/RunnableProcess.java
new file mode 100644
index 0000000..d55e138
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/RunnableProcess.java
@@ -0,0 +1,277 @@
+/**
+ * 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.reef.runtime.local.process;
+
+import org.apache.reef.runtime.common.evaluator.PIDStoreStartHandler;
+import org.apache.reef.util.OSUtils;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+
+/**
+ * A runnable class that encapsulates a process.
+ */
+public final class RunnableProcess implements Runnable {
+
+  private static final Logger LOG = Logger.getLogger(RunnableProcess.class.getName());
+
+  private static final long DESTROY_WAIT_TIME = 100;
+
+  /**
+   * Name of the file used for STDERR redirection.
+   */
+  private final String standardErrorFileName;
+  /**
+   * Name of the file used for STDOUT redirection.
+   */
+  private final String standardOutFileName;
+
+  /**
+   * Command to execute.
+   */
+  private final List<String> command;
+  /**
+   * User supplied ID of this process.
+   */
+  private final String id;
+  /**
+   * The working folder in which the process runs. It is also where STDERR and STDOUT files will be deposited.
+   */
+  private final File folder;
+  /**
+   * The coarse-grained lock for state transition.
+   */
+  private final Lock stateLock = new ReentrantLock();
+  private final Condition doneCond = stateLock.newCondition();
+  /**
+   * This will be informed of process start and stop.
+   */
+  private final RunnableProcessObserver processObserver;
+  /**
+   * The process.
+   */
+  private Process process;
+  /**
+   * The state of the process.
+   */
+  private State state = State.INIT;   // synchronized on stateLock
+
+  /**
+   * @param command               the command to execute.
+   * @param id                    The ID of the process. This is used to name files and in the logs created by this process.
+   * @param folder                The folder in which this will store its stdout and stderr output
+   * @param processObserver       will be informed of process state changes.
+   * @param standardOutFileName   The name of the file used for redirecting STDOUT
+   * @param standardErrorFileName The name of the file used for redirecting STDERR
+   */
+  public RunnableProcess(final List<String> command,
+                         final String id,
+                         final File folder,
+                         final RunnableProcessObserver processObserver,
+                         final String standardOutFileName,
+                         final String standardErrorFileName) {
+    this.processObserver = processObserver;
+    this.command = new ArrayList<>(command);
+    this.id = id;
+    this.folder = folder;
+    assert (this.folder.isDirectory());
+    this.folder.mkdirs();
+    this.standardOutFileName = standardOutFileName;
+    this.standardErrorFileName = standardErrorFileName;
+    LOG.log(Level.FINEST, "RunnableProcess ready.");
+  }
+
+  /**
+   * Checks whether a transition from State 'from' to state 'to' is legal
+   *
+   * @param from
+   * @param to
+   * @return true, if the state transition is legal. False otherwise.
+   */
+  private static boolean isLegal(final State from, final State to) {
+    switch (from) {
+      case INIT:
+        switch (to) {
+          case INIT:
+          case RUNNING:
+          case ENDED:
+            return true;
+          default:
+            return false;
+        }
+      case RUNNING:
+        switch (to) {
+          case ENDED:
+            return true;
+          default:
+            return false;
+        }
+      case ENDED:
+        return false;
+      default:
+        return false;
+    }
+  }
+
+  /**
+   * Runs the configured process.
+   *
+   * @throws java.lang.IllegalStateException if the process is already running or has been running before.
+   */
+  @Override
+  public void run() {
+    this.stateLock.lock();
+    try {
+      if (this.getState() != State.INIT) {
+        throw new IllegalStateException("The RunnableProcess can't be reused");
+      }
+
+      // Setup the stdout and stderr destinations.
+      final File errFile = new File(folder, standardErrorFileName);
+      final File outFile = new File(folder, standardOutFileName);
+
+      // Launch the process
+      try {
+        LOG.log(Level.FINEST, "Launching process \"{0}\"\nSTDERR can be found in {1}\nSTDOUT can be found in {2}",
+            new Object[]{this.id, errFile.getAbsolutePath(), outFile.getAbsolutePath()});
+        this.process = new ProcessBuilder()
+            .command(this.command)
+            .directory(this.folder)
+            .redirectError(errFile)
+            .redirectOutput(outFile)
+            .start();
+        this.setState(State.RUNNING);
+        this.processObserver.onProcessStarted(this.id);
+      } catch (final IOException ex) {
+        LOG.log(Level.SEVERE, "Unable to spawn process \"{0}\" wth command {1}\n Exception:{2}",
+            new Object[]{this.id, this.command, ex});
+      }
+    } finally {
+      this.stateLock.unlock();
+    }
+
+    try {
+      // Wait for its completion
+      final int returnValue = process.waitFor();
+      this.processObserver.onProcessExit(this.id, returnValue);
+      this.stateLock.lock();
+      try {
+        this.setState(State.ENDED);
+        this.doneCond.signalAll();
+      } finally {
+        this.stateLock.unlock();
+      }
+      LOG.log(Level.FINEST, "Process \"{0}\" returned {1}", new Object[]{this.id, returnValue});
+    } catch (final InterruptedException ex) {
+      LOG.log(Level.SEVERE, "Interrupted while waiting for the process \"{0}\" to complete. Exception: {2}",
+          new Object[]{this.id, ex});
+    }
+  }
+
+
+  /**
+   * Cancels the running process if it is running.
+   */
+  public void cancel() {
+    this.stateLock.lock();
+    try {
+      if (this.processIsRunning()) {
+        this.process.destroy();
+        this.doneCond.await(DESTROY_WAIT_TIME, TimeUnit.MILLISECONDS);
+      }
+
+      if (this.processIsRunning()) {
+        LOG.log(Level.WARNING, "The child process survived Process.destroy()");
+        if (OSUtils.isLinux()) {
+          LOG.log(Level.WARNING, "Attempting to kill the process via the kill command line");
+          try {
+            final long pid = readPID();
+            OSUtils.kill(pid);
+          } catch (final IOException | InterruptedException e) {
+            LOG.log(Level.SEVERE, "Unable to kill the process.", e);
+          }
+        }
+      }
+
+    } catch (final InterruptedException ex) {
+      LOG.log(Level.SEVERE, "Interrupted while waiting for the process \"{0}\" to complete. Exception: {2}",
+          new Object[]{this.id, ex});
+    } finally {
+      this.stateLock.unlock();
+    }
+  }
+
+  /**
+   * @return the PID stored in the PID file.
+   * @throws IOException if the file can't be read.
+   */
+  private long readPID() throws IOException {
+    final String PIDFileName = this.folder.getAbsolutePath() + "/" + PIDStoreStartHandler.PID_FILE_NAME;
+    try (final BufferedReader r = new BufferedReader(new FileReader(PIDFileName))) {
+      return Long.valueOf(r.readLine());
+    }
+  }
+
+  private boolean processIsRunning() {
+    return this.getState() == State.RUNNING;
+  }
+
+  /**
+   * @return the current State of the process.
+   */
+  private State getState() {
+    return this.state;
+  }
+
+  /**
+   * Sets a new state for the process.
+   *
+   * @param newState
+   * @throws java.lang.IllegalStateException if the new state is illegal.
+   */
+  private void setState(final State newState) {
+    if (!isLegal(this.state, newState)) {
+      throw new IllegalStateException("Transition from " + this.state + " to " + newState + " is illegal");
+    }
+    this.state = newState;
+  }
+
+  /**
+   * The possible states of a process: INIT, RUNNING, ENDED.
+   */
+  private enum State {
+    // After initialization
+    INIT,
+    // The process is running
+    RUNNING,
+    // The process ended
+    ENDED
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/RunnableProcessObserver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/RunnableProcessObserver.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/RunnableProcessObserver.java
new file mode 100644
index 0000000..fe58b74
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/RunnableProcessObserver.java
@@ -0,0 +1,39 @@
+/**
+ * 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.reef.runtime.local.process;
+
+/**
+ * Observer interface for events fired by RunnableProcess.
+ */
+public interface RunnableProcessObserver {
+  /**
+   * This will be called right after the process is launched.
+   *
+   * @param processId the id of the process that started.
+   */
+  public void onProcessStarted(final String processId);
+
+  /**
+   * This will be called right after the process exited.
+   *
+   * @param exitCode  the return code of the process.
+   * @param processId the id of the process that exited.
+   */
+  public void onProcessExit(final String processId, final int exitCode);
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/package-info.java b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/package-info.java
new file mode 100644
index 0000000..964b6b9
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/main/java/org/apache/reef/runtime/local/process/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+/**
+ * Infrastructure for managing processes.
+ */
+package org.apache.reef.runtime.local.process;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/test/java/org/apache/reef/runtime/local/driver/ResourceRequestQueueTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/test/java/org/apache/reef/runtime/local/driver/ResourceRequestQueueTest.java b/lang/java/reef-runtime-local/src/test/java/org/apache/reef/runtime/local/driver/ResourceRequestQueueTest.java
new file mode 100644
index 0000000..658747d
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/test/java/org/apache/reef/runtime/local/driver/ResourceRequestQueueTest.java
@@ -0,0 +1,63 @@
+/**
+ * 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.reef.runtime.local.driver;
+
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ResourceRequestQueueTest {
+
+  @Test
+  public void testEmptyAfterConstruction() {
+    final ResourceRequestQueue q = new ResourceRequestQueue();
+    Assert.assertFalse("A freshly generated queue should be empty", q.hasOutStandingRequests());
+  }
+
+  @Test
+  public void testNotEmptyAfterInsert() {
+    final ResourceRequestQueue q = new ResourceRequestQueue();
+    q.add(getAlmostSatisfied());
+    Assert.assertTrue("A queue should not be empty after an insert.", q.hasOutStandingRequests());
+  }
+
+  @Test
+  public void testSatisfaction() {
+    final ResourceRequestQueue q = new ResourceRequestQueue();
+    for (int i = 0; i < 1; ++i) {
+      q.add(getAlmostSatisfied());
+      Assert.assertTrue("A queue should not be empty after an insert.", q.hasOutStandingRequests());
+      q.satisfyOne();
+      Assert.assertFalse("The queue should be empty after all requests have been satisfied", q.hasOutStandingRequests());
+    }
+
+    final int nInsert = 10;
+    for (int i = 0; i < nInsert; ++i) {
+      q.add(getAlmostSatisfied());
+    }
+    for (int i = 0; i < nInsert; ++i) {
+      q.satisfyOne();
+    }
+    Assert.assertFalse("The queue should be empty after all requests have been satisfied", q.hasOutStandingRequests());
+  }
+
+  private ResourceRequest getAlmostSatisfied() {
+    return new ResourceRequest(DriverRuntimeProtocol.ResourceRequestProto.newBuilder().setResourceCount(1).setMemorySize(128).build());
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-local/src/test/java/org/apache/reef/runtime/local/driver/ResourceRequestTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-local/src/test/java/org/apache/reef/runtime/local/driver/ResourceRequestTest.java b/lang/java/reef-runtime-local/src/test/java/org/apache/reef/runtime/local/driver/ResourceRequestTest.java
new file mode 100644
index 0000000..3156a02
--- /dev/null
+++ b/lang/java/reef-runtime-local/src/test/java/org/apache/reef/runtime/local/driver/ResourceRequestTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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.reef.runtime.local.driver;
+
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.junit.Assert;
+import org.junit.Test;
+
+public final class ResourceRequestTest {
+
+  @Test()
+  public void testInitializer() {
+    final ResourceRequest rr = get(1);
+    Assert.assertFalse("A fresh request should not be satisfied.", rr.isSatisfied());
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testInitializationWithNull() {
+    final ResourceRequest rr2 = new ResourceRequest(null);
+    Assert.fail("Passing null to the ResourceRequest constructor should throw an IllegalArgumentException.");
+  }
+
+
+  @Test
+  public void testSatisfaction() {
+    final int n = 10;
+    final ResourceRequest rr = get(n);
+    for (int i = 0; i < n; ++i) {
+      rr.satisfyOne();
+    }
+    Assert.assertTrue("A satisfied request should tell so", rr.isSatisfied());
+  }
+
+  @Test(expected = IllegalStateException.class)
+  public void testOverSatisfaction() {
+    final ResourceRequest rr = get(1);
+    rr.satisfyOne();
+    rr.satisfyOne();
+    Assert.fail("Satisfying more than the request should throw an IllegalStateException");
+  }
+
+  private ResourceRequest get(final int n) {
+    return new ResourceRequest(DriverRuntimeProtocol.ResourceRequestProto.newBuilder().setResourceCount(n).setMemorySize(128).build());
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/pom.xml b/lang/java/reef-runtime-mesos/pom.xml
new file mode 100644
index 0000000..a5aa333
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/pom.xml
@@ -0,0 +1,95 @@
+<?xml version="1.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.
+-->
+<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.reef</groupId>
+        <artifactId>reef-project</artifactId>
+        <version>0.11.0-incubating-SNAPSHOT</version>
+    </parent>
+    <name>REEF Runtime for Mesos</name>
+    <artifactId>reef-runtime-mesos</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>reef-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.mesos</groupId>
+            <artifactId>mesos</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-client</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-all</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.avro</groupId>
+            <artifactId>avro</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.avro</groupId>
+                <artifactId>avro-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>schema</goal>
+                        </goals>
+                        <configuration>
+                            <sourceDirectory>${project.basedir}/src/main/avro/</sourceDirectory>
+                            <outputDirectory>${project.basedir}/target/generated-sources/avro/</outputDirectory>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>add-source</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>add-source</goal>
+                        </goals>
+                        <configuration>
+                            <sources>
+                                <source>target/generated-sources/avro</source>
+                            </sources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/avro/EvaluatorControl.avsc
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/avro/EvaluatorControl.avsc b/lang/java/reef-runtime-mesos/src/main/avro/EvaluatorControl.avsc
new file mode 100644
index 0000000..ef4a152
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/avro/EvaluatorControl.avsc
@@ -0,0 +1,47 @@
+/**
+ * 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.
+ */
+[
+  {
+    "namespace": "org.apache.reef.runtime.mesos.util",
+    "type": "record",
+    "name": "EvaluatorLaunch",
+    "fields": [
+      { "name": "identifier", "type": "string" },
+      { "name": "command", "type": "string" }
+    ]
+  },
+  {
+    "namespace": "org.apache.reef.runtime.mesos.util",
+    "type": "record",
+    "name": "EvaluatorRelease",
+    "fields": [
+      { "name": "identifier", "type": "string" }
+    ]
+  },
+  {
+    "namespace": "org.apache.reef.runtime.mesos.util",
+    "type": "record",
+    "name": "EvaluatorControl",
+    "fields": [
+      { "name": "evaluator_launch", "type": ["EvaluatorLaunch", "null"] },
+      { "name": "evaluator_release", "type": ["EvaluatorRelease", "null"] }
+    ]
+  }
+]
+

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/MesosClasspathProvider.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/MesosClasspathProvider.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/MesosClasspathProvider.java
new file mode 100644
index 0000000..cc051d5
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/MesosClasspathProvider.java
@@ -0,0 +1,92 @@
+/**
+ * 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.reef.runtime.mesos;
+
+import net.jcip.annotations.Immutable;
+import org.apache.reef.runtime.common.files.RuntimeClasspathProvider;
+
+import javax.inject.Inject;
+import java.util.Arrays;
+import java.util.List;
+import java.util.logging.Logger;
+
+/**
+ * Access to the classpath according to the REEF file system standard.
+ */
+@Immutable
+public final class MesosClasspathProvider implements RuntimeClasspathProvider {
+  private static final String HADOOP_CONF_DIR = System.getenv("HADOOP_CONF_DIR");
+  private static final String HADOOP_HOME = System.getenv("HADOOP_HOME");
+  private static final String HADOOP_COMMON_HOME = System.getenv("HADOOP_COMMON_HOME");
+  private static final String HADOOP_YARN_HOME = System.getenv("HADOOP_YARN_HOME");
+  private static final String HADOOP_HDFS_HOME = System.getenv("HADOOP_HDFS_HOME");
+  private static final String HADOOP_MAPRED_HOME = System.getenv("HADOOP_MAPRED_HOME");
+
+  // Used when we can't get a classpath from Hadoop
+  private static final String[] LEGACY_CLASSPATH_LIST = new String[]{
+      HADOOP_CONF_DIR,
+      HADOOP_HOME + "/*",
+      HADOOP_HOME + "/lib/*",
+      HADOOP_COMMON_HOME + "/*",
+      HADOOP_COMMON_HOME + "/lib/*",
+      HADOOP_YARN_HOME + "/*",
+      HADOOP_YARN_HOME + "/lib/*",
+      HADOOP_HDFS_HOME + "/*",
+      HADOOP_HDFS_HOME + "/lib/*",
+      HADOOP_MAPRED_HOME + "/*",
+      HADOOP_MAPRED_HOME + "/lib/*",
+      HADOOP_HOME + "/etc/hadoop",
+      HADOOP_HOME + "/share/hadoop/common/*",
+      HADOOP_HOME + "/share/hadoop/common/lib/*",
+      HADOOP_HOME + "/share/hadoop/yarn/*",
+      HADOOP_HOME + "/share/hadoop/yarn/lib/*",
+      HADOOP_HOME + "/share/hadoop/hdfs/*",
+      HADOOP_HOME + "/share/hadoop/hdfs/lib/*",
+      HADOOP_HOME + "/share/hadoop/mapreduce/*",
+      HADOOP_HOME + "/share/hadoop/mapreduce/lib/*"
+  };
+  private final List<String> classPathPrefix;
+  private final List<String> classPathSuffix;
+
+  @Inject
+  MesosClasspathProvider() {
+    this.classPathPrefix = Arrays.asList(LEGACY_CLASSPATH_LIST);
+    this.classPathSuffix = Arrays.asList(LEGACY_CLASSPATH_LIST);
+  }
+
+  @Override
+  public List<String> getDriverClasspathPrefix() {
+    return this.classPathPrefix;
+  }
+
+  @Override
+  public List<String> getDriverClasspathSuffix() {
+    return this.classPathSuffix;
+  }
+
+  @Override
+  public List<String> getEvaluatorClasspathPrefix() {
+    return this.classPathPrefix;
+  }
+
+  @Override
+  public List<String> getEvaluatorClasspathSuffix() {
+    return this.classPathSuffix;
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/client/MesosClientConfiguration.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/client/MesosClientConfiguration.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/client/MesosClientConfiguration.java
new file mode 100644
index 0000000..280f2a6
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/client/MesosClientConfiguration.java
@@ -0,0 +1,68 @@
+/**
+ * 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.reef.runtime.mesos.client;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Public;
+import org.apache.reef.client.REEF;
+import org.apache.reef.client.RunningJob;
+import org.apache.reef.runtime.common.client.REEFImplementation;
+import org.apache.reef.runtime.common.client.RunningJobImpl;
+import org.apache.reef.runtime.common.client.api.JobSubmissionHandler;
+import org.apache.reef.runtime.common.files.RuntimeClasspathProvider;
+import org.apache.reef.runtime.common.launch.REEFMessageCodec;
+import org.apache.reef.runtime.mesos.MesosClasspathProvider;
+import org.apache.reef.runtime.mesos.client.parameters.MasterIp;
+import org.apache.reef.runtime.mesos.client.parameters.RootFolder;
+import org.apache.reef.runtime.mesos.util.HDFSConfigurationConstructor;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.ConfigurationModuleBuilder;
+import org.apache.reef.tang.formats.OptionalParameter;
+import org.apache.reef.tang.formats.RequiredParameter;
+import org.apache.reef.wake.remote.RemoteConfiguration;
+
+/**
+ * A ConfigurationModule for the Mesos resource manager
+ */
+@Public
+@ClientSide
+public class MesosClientConfiguration extends ConfigurationModuleBuilder {
+  /**
+   * The folder in which the sub-folders for REEF drivers, one per job, will be created.
+   * If none is given, a folder "REEF_MESOS_RUNTIME" will be created in the local directory.
+   */
+  public static final OptionalParameter<String> ROOT_FOLDER = new OptionalParameter<>();
+
+  /**
+   * The ip address of Mesos Master
+   */
+  public static final RequiredParameter<String> MASTER_IP = new RequiredParameter<>();
+
+  public static final ConfigurationModule CONF = new MesosClientConfiguration()
+      .bindImplementation(REEF.class, REEFImplementation.class)
+      .bindImplementation(RunningJob.class, RunningJobImpl.class)
+      .bindNamedParameter(RemoteConfiguration.MessageCodec.class, REEFMessageCodec.class)
+      .bindImplementation(JobSubmissionHandler.class, MesosJobSubmissionHandler.class)
+      .bindNamedParameter(RootFolder.class, ROOT_FOLDER)
+      .bindNamedParameter(MasterIp.class, MASTER_IP)
+      .bindConstructor(Configuration.class, HDFSConfigurationConstructor.class)
+      .bindImplementation(RuntimeClasspathProvider.class, MesosClasspathProvider.class)
+      .build();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/client/MesosJobSubmissionHandler.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/client/MesosJobSubmissionHandler.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/client/MesosJobSubmissionHandler.java
new file mode 100644
index 0000000..d43a855
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/client/MesosJobSubmissionHandler.java
@@ -0,0 +1,141 @@
+/**
+ * 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.reef.runtime.mesos.client;
+
+import org.apache.reef.annotations.audience.ClientSide;
+import org.apache.reef.annotations.audience.Private;
+import org.apache.reef.proto.ClientRuntimeProtocol;
+import org.apache.reef.proto.ReefServiceProtos.FileResourceProto;
+import org.apache.reef.runtime.common.client.api.JobSubmissionHandler;
+import org.apache.reef.runtime.common.files.ClasspathProvider;
+import org.apache.reef.runtime.common.files.REEFFileNames;
+import org.apache.reef.runtime.common.launch.JavaLaunchCommandBuilder;
+import org.apache.reef.runtime.common.parameters.JVMHeapSlack;
+import org.apache.reef.runtime.mesos.client.parameters.MasterIp;
+import org.apache.reef.runtime.mesos.client.parameters.RootFolder;
+import org.apache.reef.runtime.mesos.driver.MesosDriverConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Configurations;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.formats.ConfigurationSerializer;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+
+/**
+ * The current implementation runs the driver as a local process, similar to reef-runtime-local.
+ * TODO: run the driver on a slave node in the cluster
+ */
+@Private
+@ClientSide
+final class MesosJobSubmissionHandler implements JobSubmissionHandler {
+  public static final String DRIVER_FOLDER_NAME = "driver";
+
+  private final ConfigurationSerializer configurationSerializer;
+  private final ClasspathProvider classpath;
+  private final REEFFileNames fileNames;
+  private final String rootFolderName;
+  private final String masterIp;
+  private final double jvmSlack;
+
+  @Inject
+  MesosJobSubmissionHandler(final @Parameter(RootFolder.class) String rootFolderName,
+                            final @Parameter(MasterIp.class) String masterIp,
+                            final ConfigurationSerializer configurationSerializer,
+                            final REEFFileNames fileNames,
+                            final ClasspathProvider classpath,
+                            final @Parameter(JVMHeapSlack.class) double jvmSlack) {
+    this.rootFolderName = new File(rootFolderName).getAbsolutePath();
+    this.masterIp = masterIp;
+    this.configurationSerializer = configurationSerializer;
+    this.fileNames = fileNames;
+    this.classpath = classpath;
+    this.jvmSlack = jvmSlack;
+  }
+
+  @Override
+  public void close() {
+  }
+
+  @Override
+  public void onNext(final ClientRuntimeProtocol.JobSubmissionProto jobSubmissionProto) {
+    try {
+      final File jobFolder = new File(new File(this.rootFolderName),
+          "/" + jobSubmissionProto.getIdentifier() + "-" + System.currentTimeMillis() + "/");
+
+      final File driverFolder = new File(jobFolder, DRIVER_FOLDER_NAME);
+      driverFolder.mkdirs();
+
+      final File reefFolder = new File(driverFolder, this.fileNames.getREEFFolderName());
+      reefFolder.mkdirs();
+
+      final File localFolder = new File(reefFolder, this.fileNames.getLocalFolderName());
+      localFolder.mkdirs();
+      for (final FileResourceProto file : jobSubmissionProto.getLocalFileList()) {
+        final Path src = new File(file.getPath()).toPath();
+        final Path dst = new File(driverFolder, this.fileNames.getLocalFolderPath() + "/" + file.getName()).toPath();
+        Files.copy(src, dst);
+      }
+
+      final File globalFolder = new File(reefFolder, this.fileNames.getGlobalFolderName());
+      globalFolder.mkdirs();
+      for (final FileResourceProto file : jobSubmissionProto.getGlobalFileList()) {
+        final Path src = new File(file.getPath()).toPath();
+        final Path dst = new File(driverFolder, this.fileNames.getGlobalFolderPath() + "/" + file.getName()).toPath();
+        Files.copy(src, dst);
+      }
+
+      final Configuration driverConfiguration =
+          Configurations.merge(MesosDriverConfiguration.CONF
+              .set(MesosDriverConfiguration.MESOS_MASTER_IP, this.masterIp)
+              .set(MesosDriverConfiguration.JOB_IDENTIFIER, jobSubmissionProto.getIdentifier())
+              .set(MesosDriverConfiguration.CLIENT_REMOTE_IDENTIFIER, jobSubmissionProto.getRemoteId())
+              .set(MesosDriverConfiguration.JVM_HEAP_SLACK, this.jvmSlack)
+              .set(MesosDriverConfiguration.SCHEDULER_DRIVER_CAPACITY, 1) // must be 1 as there is 1 scheduler at the same time
+              .build(),
+          this.configurationSerializer.fromString(jobSubmissionProto.getConfiguration()));
+      final File runtimeConfigurationFile = new File(driverFolder, this.fileNames.getDriverConfigurationPath());
+      this.configurationSerializer.toFile(driverConfiguration, runtimeConfigurationFile);
+
+      final List<String> launchCommand = new JavaLaunchCommandBuilder()
+          .setErrorHandlerRID(jobSubmissionProto.getRemoteId())
+          .setLaunchID(jobSubmissionProto.getIdentifier())
+          .setConfigurationFileName(this.fileNames.getDriverConfigurationPath())
+          .setClassPath(this.classpath.getDriverClasspath())
+          .setMemory(jobSubmissionProto.getDriverMemory())
+          .build();
+
+      final File errFile = new File(driverFolder, fileNames.getDriverStderrFileName());
+      final File outFile = new File(driverFolder, fileNames.getDriverStdoutFileName());
+
+      new ProcessBuilder()
+          .command(launchCommand)
+          .directory(driverFolder)
+          .redirectError(errFile)
+          .redirectOutput(outFile)
+          .start();
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/client/parameters/MasterIp.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/client/parameters/MasterIp.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/client/parameters/MasterIp.java
new file mode 100644
index 0000000..09c2882
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/client/parameters/MasterIp.java
@@ -0,0 +1,26 @@
+/**
+ * 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.reef.runtime.mesos.client.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+@NamedParameter(doc = "The ip address of Mesos Master", short_name = "master_ip")
+public final class MasterIp implements Name<String> {
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/client/parameters/RootFolder.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/client/parameters/RootFolder.java b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/client/parameters/RootFolder.java
new file mode 100644
index 0000000..8cdc116
--- /dev/null
+++ b/lang/java/reef-runtime-mesos/src/main/java/org/apache/reef/runtime/mesos/client/parameters/RootFolder.java
@@ -0,0 +1,26 @@
+/**
+ * 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.reef.runtime.mesos.client.parameters;
+
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+
+@NamedParameter(doc = "The root folder where logs etc. will be stored.", default_value = "REEF_MESOS_RUNTIME")
+public final class RootFolder implements Name<String> {
+}
\ No newline at end of file