Index: src/Fragmentation/Automation/Makefile.am
===================================================================
--- src/Fragmentation/Automation/Makefile.am	(revision 2e661a0041b96400c1fd8b0f780a60bb0980bd5e)
+++ src/Fragmentation/Automation/Makefile.am	(revision f45c08b2b3e2af3a790d950101ca23b93baa49cc)
@@ -44,4 +44,5 @@
 FRAGMENTATIONOPERATIONSSOURCE = \
   Operations/AsyncOperation.cpp \
+  Operations/OperationQueue.cpp \
   Operations/SyncOperation.cpp \
   Operations/Controllers/CheckResultsOperation.cpp \
@@ -61,4 +62,5 @@
   Operations/AsyncOperation.hpp \
   Operations/Operation.hpp \
+  Operations/OperationQueue.hpp \
   Operations/SyncOperation.hpp \
   Operations/Controllers/CheckResultsOperation.hpp \
Index: src/Fragmentation/Automation/Operations/OperationQueue.cpp
===================================================================
--- src/Fragmentation/Automation/Operations/OperationQueue.cpp	(revision f45c08b2b3e2af3a790d950101ca23b93baa49cc)
+++ src/Fragmentation/Automation/Operations/OperationQueue.cpp	(revision f45c08b2b3e2af3a790d950101ca23b93baa49cc)
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+/*
+ * OperationQueue.cpp
+ *
+ *  Created on: Apr 24, 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 <boost/bind.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <string>
+
+#include "CodePatterns/Log.hpp"
+#include "CodePatterns/Observer/Observer.hpp"
+
+#include "Operations/AsyncOperation.hpp"
+#include "Operations/OperationQueue.hpp"
+#include "WorkerAddress.hpp"
+
+OperationQueue::OperationQueue_t::iterator OperationQueue::findOperation(AsyncOperation *op)
+{
+  OperationQueue_t::iterator iter =
+      std::find_if(queue.begin(), queue.end(),
+          boost::bind(&AsyncOp_ptr::get, boost::lambda::_1) == op);
+  return iter;
+}
+
+void OperationQueue::push_back(AsyncOperation *&op, const WorkerAddress &address)
+{
+  if (op != NULL) {
+    AsyncOp_ptr ptr(op); // this always prevents memory loss
+    queue.push_back( ptr );
+    op = NULL;
+    // only start operation when address is valid
+    if ((!address.host.empty()) && (!address.service.empty()))
+      (*ptr)(address.host, address.service);
+  } else {
+    ELOG(1, "Given operation pointer is NULL.");
+  }
+}
+
+void OperationQueue::remove(AsyncOperation *op, Observer *observer)
+{
+  if (op != NULL) {
+    OperationQueue_t::iterator iter = findOperation(op);
+    if (iter != queue.end()) {
+      // sign off and remove op
+      if (observer != NULL)
+        op->signOff(observer);
+      queue.erase(iter);
+    } else {
+      ELOG(1, "Could not find Operation " << op->getName() << " in operation's queue.");
+    }
+  } else {
+    ELOG(1, "Given operation pointer is NULL.");
+  }
+}
Index: src/Fragmentation/Automation/Operations/OperationQueue.hpp
===================================================================
--- src/Fragmentation/Automation/Operations/OperationQueue.hpp	(revision f45c08b2b3e2af3a790d950101ca23b93baa49cc)
+++ src/Fragmentation/Automation/Operations/OperationQueue.hpp	(revision f45c08b2b3e2af3a790d950101ca23b93baa49cc)
@@ -0,0 +1,65 @@
+/*
+ * OperationQueue.hpp
+ *
+ *  Created on: Apr 24, 2012
+ *      Author: heber
+ */
+
+#ifndef OPERATIONQUEUE_HPP_
+#define OPERATIONQUEUE_HPP_
+
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <boost/shared_ptr.hpp>
+#include <deque>
+
+class AsyncOperation;
+class Observer;
+class OperationQueueTest;
+class WorkerAddress;
+
+/** This class is a container for \ref AsyncOperation's that are kept as shared_ptr
+ * and removed when the operation is done.
+ */
+class OperationQueue
+{
+  //!> grant unit test access to private part
+  friend class OperationQueueTest;
+public:
+  typedef boost::shared_ptr<AsyncOperation> AsyncOp_ptr;
+
+  /** Add an operation to the internal queue and hand over memory responsibility to it,
+   * also the operation is run.
+   *
+   * @param op operation to add, is NULL on return.
+   */
+  void push_back(AsyncOperation *&op, const WorkerAddress &address);
+
+  /** Removes an operation from the queue.
+   *
+   * @param op operation to remove from queue
+   * @param observer observer to sign off from operation, NULL if none to sign off
+   */
+  void remove(AsyncOperation *op, Observer *observer);
+
+private:
+  //!> internal operation to send jobs to workers
+  typedef std::deque<AsyncOp_ptr> OperationQueue_t;
+
+  /** Tiny Helper function to find an operation inside FragmentScheduler::OperationQueue.
+   *
+   * @param op operation to remove from queue
+   * @return iterator to element or to OperationQueue.end()
+   */
+  OperationQueue_t::iterator findOperation(AsyncOperation *op);
+
+private:
+  //!> internal queue with operations
+  OperationQueue_t queue;
+};
+
+#endif /* OPERATIONQUEUE_HPP_ */
Index: src/Fragmentation/Automation/unittests/Makefile.am
===================================================================
--- src/Fragmentation/Automation/unittests/Makefile.am	(revision 2e661a0041b96400c1fd8b0f780a60bb0980bd5e)
+++ src/Fragmentation/Automation/unittests/Makefile.am	(revision f45c08b2b3e2af3a790d950101ca23b93baa49cc)
@@ -8,4 +8,5 @@
   unittests/MPQCCommandJobUnitTest.cpp \
   unittests/MPQCDataUnitTest.cpp \
+  unittests/OperationQueueUnitTest.cpp \
   unittests/SystemCommandJobUnitTest.cpp \
   unittests/WorkerAddressUnitTest.cpp \
@@ -18,4 +19,5 @@
   unittests/MPQCCommandJobUnitTest.hpp \
   unittests/MPQCDataUnitTest.hpp \
+  unittests/OperationQueueUnitTest.hpp \
   unittests/SystemCommandJobUnitTest.hpp \
   unittests/WorkerAddressUnitTest.hpp \
@@ -28,4 +30,5 @@
   MPQCCommandJobUnitTest \
   MPQCDataUnitTest \
+  OperationQueueUnitTest \
   SystemCommandJobUnitTest \
   WorkerAddressUnitTest \
@@ -110,4 +113,16 @@
   ${CodePatterns_LIBS}
 
+OperationQueueUnitTest_LDFLAGS = ${CodePatterns_LIBS} $(CPPUNIT_LIBS) -ldl
+OperationQueueUnitTest_CPPFLAGS = ${BOOST_CPPFLAGS} $(CPPUNIT_CFLAGS) ${CodePatterns_CFLAGS}
+OperationQueueUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
+  unittests/OperationQueueUnitTest.cpp \
+  unittests/OperationQueueUnitTest.hpp \
+  unittests/stubs/AsyncOperationStub.hpp
+OperationQueueUnitTest_LDADD = \
+  libMolecuilderFragmentationOperations.la \
+  libMolecuilderFragmentationAutomationHelper.la \
+  $(BOOST_SYSTEM_LDFLAGS) $(BOOST_SYSTEM_LIBS) \
+  ${CodePatterns_LIBS}
+
 SystemCommandJobUnitTest_LDFLAGS = ${CodePatterns_LIBS} $(CPPUNIT_LIBS) -ldl
 SystemCommandJobUnitTest_CPPFLAGS = ${BOOST_CPPFLAGS} $(CPPUNIT_CFLAGS) ${CodePatterns_CFLAGS}
Index: src/Fragmentation/Automation/unittests/OperationQueueUnitTest.cpp
===================================================================
--- src/Fragmentation/Automation/unittests/OperationQueueUnitTest.cpp	(revision f45c08b2b3e2af3a790d950101ca23b93baa49cc)
+++ src/Fragmentation/Automation/unittests/OperationQueueUnitTest.cpp	(revision f45c08b2b3e2af3a790d950101ca23b93baa49cc)
@@ -0,0 +1,113 @@
+/*
+ * 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.
+ */
+
+/*
+ * OperationQueueUnitTest.cpp
+ *
+ *  Created on: Apr 24, 2012
+ *      Author: heber
+ */
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+
+#include "OperationQueueUnitTest.hpp"
+
+#include "CodePatterns/Assert.hpp"
+
+#include "Operations/OperationQueue.hpp"
+#include "stubs/AsyncOperationStub.hpp"
+#include "WorkerAddress.hpp"
+
+#ifdef HAVE_TESTRUNNER
+#include "UnitTestMain.hpp"
+#endif /*HAVE_TESTRUNNER*/
+
+/********************************************** Test classes **************************************/
+
+// Registers the fixture into the 'registry'
+CPPUNIT_TEST_SUITE_REGISTRATION( OperationQueueTest );
+
+void OperationQueueTest::setUp()
+{
+  // Throw assertions
+  ASSERT_DO(Assert::Throw);
+
+  queue = new OperationQueue;
+  conn = new Connection(io_service);
+  address = new WorkerAddress("", ""); // address is invalid in sense of OperationQueue to prevent connect
+
+  op = new AsyncOperationStub(std::string("AsyncOperationStub"), *conn);
+  otherop = new AsyncOperationStub(std::string("AsyncOperationStub"), *conn);
+}
+
+
+void OperationQueueTest::tearDown()
+{
+  delete conn;
+  delete queue;
+  delete address;
+
+  // if op and otherop are pushed, then they are NULL, hence we may call delete on them
+  delete op;
+  delete otherop;
+}
+
+/** UnitTest for findOperation
+ */
+void OperationQueueTest::findTest()
+{
+  AsyncOperation *backup = op; // we need backup as op is NULL'ed
+  AsyncOperation *otherbackup = otherop; // we need otherbackup as otherop is NULL'ed
+  // queue is empty
+  CPPUNIT_ASSERT( queue->findOperation(op) == queue->queue.end() );
+  CPPUNIT_ASSERT( queue->findOperation(otherop) == queue->queue.end() );
+
+  // insert ptr
+  queue->push_back(op, *address);
+  CPPUNIT_ASSERT( queue->findOperation(backup) != queue->queue.end() );
+  CPPUNIT_ASSERT( queue->findOperation(otherop) == queue->queue.end() );
+
+  // insert otherptr
+  queue->push_back(otherop, *address);
+  CPPUNIT_ASSERT( queue->findOperation(backup) != queue->queue.end() );
+  CPPUNIT_ASSERT( queue->findOperation(otherbackup) != queue->queue.end() );
+}
+
+/** UnitTest for push_back
+ */
+void OperationQueueTest::push_backTest()
+{
+  AsyncOperation *backup = op; // we need backup as op is NULL'ed
+  queue->push_back(op,* address);
+  CPPUNIT_ASSERT_EQUAL( (size_t)1, queue->queue.size() );
+  CPPUNIT_ASSERT_EQUAL( backup, queue->queue.begin()->get() );
+
+  queue->push_back(otherop, *address);
+  CPPUNIT_ASSERT_EQUAL( (size_t)2, queue->queue.size() );
+  CPPUNIT_ASSERT_EQUAL( backup, queue->queue.begin()->get() );
+}
+
+/** UnitTest for remove
+ */
+void OperationQueueTest::removeTest()
+{
+  // insert op
+  AsyncOperation *backup = op; // we need backup as op is NULL'ed
+  queue->push_back(op, *address);
+  CPPUNIT_ASSERT( queue->queue.begin() != queue->queue.end() );
+
+  // remove op
+  queue->remove(backup, NULL);
+  CPPUNIT_ASSERT( queue->queue.begin() == queue->queue.end() );
+}
Index: src/Fragmentation/Automation/unittests/OperationQueueUnitTest.hpp
===================================================================
--- src/Fragmentation/Automation/unittests/OperationQueueUnitTest.hpp	(revision f45c08b2b3e2af3a790d950101ca23b93baa49cc)
+++ src/Fragmentation/Automation/unittests/OperationQueueUnitTest.hpp	(revision f45c08b2b3e2af3a790d950101ca23b93baa49cc)
@@ -0,0 +1,53 @@
+/*
+ * OperationQueueUnitTest.hpp
+ *
+ *  Created on: Apr 24, 2012
+ *      Author: heber
+ */
+
+#ifndef OPERATIONQUEUEUNITTEST_HPP_
+#define OPERATIONQUEUEUNITTEST_HPP_
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <boost/asio.hpp>
+
+class AsyncOperation;
+class Connection;
+class OperationQueue;
+class WorkerAddress;
+
+/********************************************** Test classes **************************************/
+
+
+class OperationQueueTest : public CppUnit::TestFixture
+{
+    CPPUNIT_TEST_SUITE( OperationQueueTest) ;
+    CPPUNIT_TEST ( push_backTest );
+    CPPUNIT_TEST ( removeTest );
+    CPPUNIT_TEST ( findTest );
+    CPPUNIT_TEST_SUITE_END();
+
+public:
+      void setUp();
+      void tearDown();
+      void findTest();
+      void push_backTest();
+      void removeTest();
+
+private:
+
+      OperationQueue *queue;
+      Connection *conn;
+      AsyncOperation *op;
+      AsyncOperation *otherop;
+      boost::asio::io_service io_service;
+      WorkerAddress *address;
+};
+
+#endif /* OPERATIONQUEUEUNITTEST_HPP_ */
Index: src/Fragmentation/Automation/unittests/stubs/AsyncOperationStub.hpp
===================================================================
--- src/Fragmentation/Automation/unittests/stubs/AsyncOperationStub.hpp	(revision f45c08b2b3e2af3a790d950101ca23b93baa49cc)
+++ src/Fragmentation/Automation/unittests/stubs/AsyncOperationStub.hpp	(revision f45c08b2b3e2af3a790d950101ca23b93baa49cc)
@@ -0,0 +1,39 @@
+/*
+ * AsyncOperationStub.hpp
+ *
+ *  Created on: Apr 24, 2012
+ *      Author: heber
+ */
+
+#ifndef ASYNCOPERATIONSTUB_HPP_
+#define ASYNCOPERATIONSTUB_HPP_
+
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <boost/asio.hpp>
+
+#include "Operations/AsyncOperation.hpp"
+
+
+class Connection;
+
+class AsyncOperationStub : public AsyncOperation
+{
+public:
+  AsyncOperationStub(const std::string &_name, Connection &_conn) :
+    AsyncOperation(_name, _conn)
+  {}
+protected:
+  void handle_connect(const boost::system::error_code& e,
+      boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
+  {
+    AsyncOperation::handle_FinishOperation(e);
+  }
+};
+
+
+#endif /* ASYNCOPERATIONSTUB_HPP_ */
