package net.dempsy;

import net.dempsy.cluster.ClusterInfoException;
import net.dempsy.cluster.ClusterInfoSessionFactory;
import net.dempsy.config.Cluster;
import net.dempsy.config.Node;
import net.dempsy.messages.Adaptor;
import net.dempsy.messages.Dispatcher;

public class DispatcherFactory {

    private final NodeManager nodeManager;
    private Dispatcher dispatcher = null;

    private class DummyAdaptor implements Adaptor {
        @Override
        public void setDispatcher(final Dispatcher dispatcher) {
            DispatcherFactory.this.dispatcher = dispatcher;
        }

        @Override
        public void start() {}

        @Override
        public void stop() {}
    }

    @SuppressWarnings("resource")
    public DispatcherFactory(final Cluster clusterDef, final ClusterInfoSessionFactory sessionFactory, final String appName) throws ClusterInfoException {
        clusterDef.setAdaptor(new DummyAdaptor());

        nodeManager = new NodeManager()
            .node(
                new Node.Builder(appName)
                    .clusters(clusterDef)
                    .build())
            .collaborator(sessionFactory.createSession())
            .start();
    }

    public void close() {
        nodeManager.close();
    }

    public Dispatcher dispatcher() {
        return dispatcher;
    }
}

@@ -254,16 +254,55 @@
 patcher;
+%0Aimport net.dempsy.util.QuietCloseable;
 %0A%0Apublic
@@ -326,16 +326,42 @@
 Factory 
+implements QuietCloseable 
 %7B%0A%0A    p
@@ -1245,32 +1245,46 @@
 start();%0A    %7D%0A%0A
+    @Override%0A
     public void 

Make DispatcherFactory a closeable.