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:47:15 UTC

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

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();
+
+}