Index: src/Fragmentation/Automation/Controller/Commands/WorkOnJobOperation.cpp
===================================================================
--- src/Fragmentation/Automation/Controller/Commands/WorkOnJobOperation.cpp	(revision 95454a7757cb2e73de8ed370a8d7b2ea5103e000)
+++ src/Fragmentation/Automation/Controller/Commands/WorkOnJobOperation.cpp	(revision 95454a7757cb2e73de8ed370a8d7b2ea5103e000)
@@ -0,0 +1,117 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C) 2012 University of Bonn. All rights reserved.
+ * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
+ */
+
+/*
+ * WorkOnJobOperation.cpp
+ *
+ *  Created on: 22.02.2012
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+// boost asio needs specific operator new
+#include <boost/asio.hpp>
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include "WorkOnJobOperation.hpp"
+
+#include <boost/bind.hpp>
+#include "CodePatterns/Info.hpp"
+#include "CodePatterns/Log.hpp"
+#include "Jobs/FragmentJob.hpp"
+#include "Jobs/MPQCCommandJob.hpp"
+#include "Jobs/SystemCommandJob.hpp"
+#include "Results/FragmentResult.hpp"
+
+FragmentResult::ptr WorkOnJobOperation::EmptyResult( new FragmentResult(JobId::NoJob, std::string("EmptyResult")) );
+
+/// Handle completion of a connect operation.
+void WorkOnJobOperation::handle_connect(const boost::system::error_code& e,
+    boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
+{
+  Info info(__FUNCTION__);
+  if (!e)
+  {
+    // Successfully established connection. Start operation to read the list
+    // of jobs. The connection::async_read() function will automatically
+    // decode the data that is read from the underlying socket.
+    LOG(1, "INFO: Receiving a job ...");
+    connection_.async_read(job,
+      boost::bind(&WorkOnJobOperation::handle_ReceiveJob, this,
+      boost::asio::placeholders::error));
+  } else if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator()) {
+    // Try the next endpoint.
+    connection_.socket().close();
+    boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
+    connection_.socket().async_connect(endpoint,
+      boost::bind(&WorkOnJobOperation::handle_connect, this,
+      boost::asio::placeholders::error, ++endpoint_iterator));
+  } else {
+    // An error occurred. Log it and return. Since we are not starting a new
+    // operation the io_service will run out of work to do and the client will
+    // exit.
+    exitflag = ErrorFlag;
+    ELOG(1, e.message());
+  }
+}
+
+/// Callback function when job has been received.
+void WorkOnJobOperation::handle_ReceiveJob(const boost::system::error_code& e)
+{
+  Info info(__FUNCTION__);
+  if (!e)
+  {
+    LOG(1, "INFO: Received job #" << job->getId() << ".");
+    if (job->getId() != JobId::NoJob) {
+      // Print out the data that was received.
+      std::cout << "Job id: " << job->getId() << "\n";
+
+      // do something .. right now: wait
+      LOG(1, "INFO: Calculating job #" << job->getId() << " ...");
+      FragmentResult::ptr result(job->Work());
+
+      // write the result to the server
+      LOG(1, "INFO: Sending result for job #" << job->getId() << " ...");
+      connection_.async_write(result,
+        boost::bind(&WorkOnJobOperation::handle_SendResult, this,
+        boost::asio::placeholders::error));
+
+    } else {
+      std::cout << "The server has no job for me." << std::endl;
+      // send out empty result
+      LOG(1, "INFO: Sending empty result ...");
+      connection_.async_write(EmptyResult,
+        boost::bind(&WorkOnJobOperation::handle_SendResult, this,
+        boost::asio::placeholders::error));
+      exitflag = ErrorFlag;
+    }
+  }
+  else
+  {
+    // An error occurred.
+    exitflag = ErrorFlag;
+    ELOG(1, e.message());
+  }
+
+  // Since we are not starting a new operation the io_service will run out of
+  // work to do and the client will exit.
+}
+
+/// Callback function when result has been sent.
+void WorkOnJobOperation::handle_SendResult(const boost::system::error_code& e)
+{
+  Info info(__FUNCTION__);
+  // Nothing to do.
+  LOG(1, "INFO: Job #" << job->getId() << " calculated and sent.");
+  // erase job
+  job.reset();
+}
Index: src/Fragmentation/Automation/Controller/Commands/WorkOnJobOperation.hpp
===================================================================
--- src/Fragmentation/Automation/Controller/Commands/WorkOnJobOperation.hpp	(revision 95454a7757cb2e73de8ed370a8d7b2ea5103e000)
+++ src/Fragmentation/Automation/Controller/Commands/WorkOnJobOperation.hpp	(revision 95454a7757cb2e73de8ed370a8d7b2ea5103e000)
@@ -0,0 +1,72 @@
+/*
+ * WorkOnJobOperation.hpp
+ *
+ *  Created on: 22.02.2012
+ *      Author: heber
+ */
+
+#ifndef WORKONJOBOPERATION_HPP_
+#define WORKONJOBOPERATION_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include <boost/asio.hpp>
+#include <string>
+#include <vector>
+
+#include "Connection.hpp"
+
+#include "Controller/Commands/Operation.hpp"
+#include "Jobs/FragmentJob.hpp"
+#include "Results/FragmentResult.hpp"
+
+class WorkOnJobOperation : public Operation  {
+public:
+  /// Constructor for class WorkOnJobOperation.
+  WorkOnJobOperation(Connection &_connection) :
+    Operation(std::string("workonjob"),_connection) {}
+  /// Destructor for class WorkOnJobOperation
+  ~WorkOnJobOperation() {}
+
+public:
+  enum {
+    OkFlag = 0,
+    ErrorFlag = 1
+  };
+
+  /** Returns the flag of the handled operation.
+   *
+   */
+  size_t getFlag() const
+  {
+    return exitflag;
+  }
+
+protected:
+  // virtual function pointer to the connection handler
+  void handle_connect(const boost::system::error_code& e,
+      boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
+
+  /// Callback function when job has been received.
+  void handle_ReceiveJob(const boost::system::error_code& e);
+
+  /// Callback function when result has been sent.
+  void handle_SendResult(const boost::system::error_code& e);
+
+private:
+  // static entity of an empty result
+  static FragmentResult::ptr EmptyResult;
+
+  /// The data received from the server.
+  FragmentJob::ptr job;
+
+  /// exit flag
+  size_t exitflag;
+};
+
+
+#endif /* WORKONJOBOPERATION_HPP_ */
Index: src/Fragmentation/Automation/FragmentWorker.cpp
===================================================================
--- src/Fragmentation/Automation/FragmentWorker.cpp	(revision 8036b77b383d40bbb7e818ed0a8809eba5794745)
+++ src/Fragmentation/Automation/FragmentWorker.cpp	(revision 95454a7757cb2e73de8ed370a8d7b2ea5103e000)
@@ -39,6 +39,4 @@
 #include "FragmentWorker.hpp"
 
-FragmentResult::ptr FragmentWorker::EmptyResult( new FragmentResult(JobId::NoJob, std::string("EmptyResult")) );
-
 /** Helper function to enforce binding of FragmentWorker to possible derived
  * FragmentJob classes.
@@ -55,102 +53,10 @@
     const std::string& service) :
   connection_(io_service),
-  result(JobId::IllegalJob),
-  Exitflag(OkFlag)
+  operation(connection_)
 {
     Info info(__FUNCTION__);
-  // Resolve the host name into an IP address.
-  boost::asio::ip::tcp::resolver resolver(io_service);
-  boost::asio::ip::tcp::resolver::query query(host, service);
-  boost::asio::ip::tcp::resolver::iterator endpoint_iterator =
-    resolver.resolve(query);
-  boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
 
-  // Start an asynchronous connect operation.
-  std::cout << "Connecting to endpoint " << endpoint << std::endl;
-  connection_.socket().async_connect(endpoint,
-    boost::bind(&FragmentWorker::handle_connect, this,
-      boost::asio::placeholders::error, ++endpoint_iterator));
+    // launch operation
+    operation(host, service);
 }
 
-/// Handle completion of a connect operation.
-void FragmentWorker::handle_connect(const boost::system::error_code& e,
-    boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
-{
-  Info info(__FUNCTION__);
-  if (!e)
-  {
-    // Successfully established connection. Start operation to read the list
-    // of jobs. The connection::async_read() function will automatically
-    // decode the data that is read from the underlying socket.
-    LOG(1, "INFO: Receiving a job ...");
-    connection_.async_read(job,
-      boost::bind(&FragmentWorker::handle_ReceiveJob, this,
-      boost::asio::placeholders::error));
-  } else if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator()) {
-    // Try the next endpoint.
-    connection_.socket().close();
-    boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
-    connection_.socket().async_connect(endpoint,
-      boost::bind(&FragmentWorker::handle_connect, this,
-      boost::asio::placeholders::error, ++endpoint_iterator));
-  } else {
-    // An error occurred. Log it and return. Since we are not starting a new
-    // operation the io_service will run out of work to do and the client will
-    // exit.
-    Exitflag = ErrorFlag;
-    ELOG(1, e.message());
-  }
-}
-
-/// Callback function when job has been received.
-void FragmentWorker::handle_ReceiveJob(const boost::system::error_code& e)
-{
-  Info info(__FUNCTION__);
-  if (!e)
-  {
-    LOG(1, "INFO: Received job #" << job->getId() << ".");
-    if (job->getId() != JobId::NoJob) {
-      // Print out the data that was received.
-      std::cout << "Job id: " << job->getId() << "\n";
-
-      // do something .. right now: wait
-      LOG(1, "INFO: Calculating job #" << job->getId() << " ...");
-      FragmentResult::ptr result(job->Work());
-
-      // write the result to the server
-      LOG(1, "INFO: Sending result for job #" << job->getId() << " ...");
-      connection_.async_write(result,
-        boost::bind(&FragmentWorker::handle_SendResult, this,
-        boost::asio::placeholders::error));
-
-    } else {
-      std::cout << "The server has no job for me." << std::endl;
-      // send out empty result
-      LOG(1, "INFO: Sending empty result ...");
-      connection_.async_write(EmptyResult,
-        boost::bind(&FragmentWorker::handle_SendResult, this,
-        boost::asio::placeholders::error));
-      Exitflag = NoJobFlag;
-    }
-  }
-  else
-  {
-    // An error occurred.
-    Exitflag = ErrorFlag;
-    ELOG(1, e.message());
-  }
-
-  // Since we are not starting a new operation the io_service will run out of
-  // work to do and the client will exit.
-}
-
-/// Callback function when result has been sent.
-void FragmentWorker::handle_SendResult(const boost::system::error_code& e)
-{
-  Info info(__FUNCTION__);
-  // Nothing to do.
-  LOG(1, "INFO: Job #" << job->getId() << " calculated and sent.");
-  // erase job
-  job.reset();
-}
-
Index: src/Fragmentation/Automation/FragmentWorker.hpp
===================================================================
--- src/Fragmentation/Automation/FragmentWorker.hpp	(revision 8036b77b383d40bbb7e818ed0a8809eba5794745)
+++ src/Fragmentation/Automation/FragmentWorker.hpp	(revision 95454a7757cb2e73de8ed370a8d7b2ea5103e000)
@@ -18,4 +18,5 @@
 #include "Connection.hpp"
 #include "Jobs/FragmentJob.hpp"
+#include "Controller/Commands/WorkOnJobOperation.hpp"
 
 /** Receives a job from Server to execute and return FragmentResult.
@@ -29,10 +30,4 @@
       const std::string& host, const std::string& service);
 
-  enum Exitflag_t {
-    OkFlag = 0,
-    NoJobFlag = 1,
-    ErrorFlag = 255
-  };
-
   /** Returns the flag of the handled operation.
    *
@@ -40,33 +35,13 @@
   size_t getExitflag() const
   {
-    return Exitflag;
+    return operation.getExitflag();
   }
 
-protected:
-  /// Handle completion of a connect operation.
-  void handle_connect(const boost::system::error_code& e,
-      boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
-
-  /// Callback function when job has been received.
-  void handle_ReceiveJob(const boost::system::error_code& e);
-
-  /// Callback function when result has been sent.
-  void handle_SendResult(const boost::system::error_code& e);
-
 private:
-  // static entity of an empty result
-  static FragmentResult::ptr EmptyResult;
-
   /// The Connection to the server.
   Connection connection_;
 
-  /// The data received from the server.
-  FragmentJob::ptr job;
-
-  /// The result created to be sent to the server.
-  FragmentResult result;
-
-  /// exit flag to give at program exit
-  enum Exitflag_t Exitflag;
+  //!> operation that handles connection, getting, and working on job.
+  WorkOnJobOperation operation;
 };
 
Index: src/Fragmentation/Automation/Makefile.am
===================================================================
--- src/Fragmentation/Automation/Makefile.am	(revision 8036b77b383d40bbb7e818ed0a8809eba5794745)
+++ src/Fragmentation/Automation/Makefile.am	(revision 95454a7757cb2e73de8ed370a8d7b2ea5103e000)
@@ -96,4 +96,5 @@
 
 WORKERSOURCE = \
+  Controller/Commands/WorkOnJobOperation.cpp \
   FragmentWorker.cpp \
   Worker.cpp
@@ -101,4 +102,5 @@
 WORKERHEADER = \
   Connection.hpp \
+  Controller/Commands/WorkOnJobOperation.hpp \
   FragmentWorker.hpp
 
