<commit_before>
import org.nakedobjects.application.system.SystemClock;
import org.nakedobjects.application.valueholder.Date;
import org.nakedobjects.container.configuration.Configuration;
import org.nakedobjects.container.configuration.ConfigurationPropertiesLoader;
import org.nakedobjects.distribution.DataFactory;
import org.nakedobjects.distribution.Distribution;
import org.nakedobjects.distribution.ProxyObjectManager;
import org.nakedobjects.distribution.ProxyReflectionFactory;
import org.nakedobjects.distribution.ServerDistribution;
import org.nakedobjects.distribution.SingleResponseUpdateNotifier;
import org.nakedobjects.distribution.java.JavaObjectDataFactory;
import org.nakedobjects.distribution.pipe.NakedObjectsPipe;
import org.nakedobjects.distribution.pipe.PipedClient;
import org.nakedobjects.distribution.pipe.PipedConnection;
import org.nakedobjects.distribution.pipe.PipedServer;
import org.nakedobjects.object.defaults.IdentityAdapterHashMap;
import org.nakedobjects.object.defaults.LocalReflectionFactory;
import org.nakedobjects.object.defaults.ObjectLoaderImpl;
import org.nakedobjects.object.defaults.PojoAdapterHashMap;
import org.nakedobjects.object.persistence.NakedObjectManager;
import org.nakedobjects.object.persistence.NakedObjectStore;
import org.nakedobjects.object.persistence.ObjectStoreLogger;
import org.nakedobjects.object.persistence.OidGenerator;
import org.nakedobjects.object.persistence.defaults.DefaultPersistAlgorithm;
import org.nakedobjects.object.persistence.defaults.LocalObjectManager;
import org.nakedobjects.object.persistence.defaults.SimpleOidGenerator;
import org.nakedobjects.reflector.java.JavaBusinessObjectContainer;
import org.nakedobjects.reflector.java.JavaObjectFactory;
import org.nakedobjects.reflector.java.fixture.JavaFixtureBuilder;
import org.nakedobjects.reflector.java.reflect.JavaAdapterFactory;
import org.nakedobjects.reflector.java.reflect.JavaSpecificationLoader;
import org.nakedobjects.system.AboutNakedObjects;
import org.nakedobjects.system.SplashWindow;
import org.nakedobjects.utility.DebugInfo;
import org.nakedobjects.utility.InfoDebugFrame;
import org.nakedobjects.viewer.ObjectViewingMechanismListener;
import org.nakedobjects.viewer.skylark.SkylarkViewer;
import org.nakedobjects.viewer.skylark.ViewUpdateNotifier;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.PropertyConfigurator;

import exploration.Context;
import fixtures.BookingsFixture;
import fixtures.CitiesFixture;
import fixtures.ClassesFixture;


public abstract class StandaloneClientServer {
    private static final String COMMON_CONFIG = "logging.properties";
    private static final String CLIENT_CONFIG = "client.properties";
    
    protected void init() {
        BasicConfigurator.configure();

        Configuration configuration = new Configuration(new ConfigurationPropertiesLoader(COMMON_CONFIG, true));
        PropertyConfigurator.configure(configuration.getProperties("log4j"));

        AboutNakedObjects.logVersion();

        SplashWindow splash = null;
        boolean noSplash = configuration.getBoolean("nosplash", false);
        if (!noSplash) {
            splash = new SplashWindow();
        }

        try {
	        PipedConnection connection = new PipedConnection();

	        NakedObjectsPipe nakedObjects = new NakedObjectsPipe();

            server(nakedObjects, connection);
            client(nakedObjects, connection);
        } finally {
            if (splash != null) {
                splash.toFront();
                splash.removeAfterDelay(3);
            }
        }
    }

    private void server(final NakedObjectsPipe nakedObjects, final PipedConnection connection) {
        final NakedObjectStore objectStore = new ObjectStoreLogger(objectStore(), "server-store.log");
		    
        Runnable runnable = new Runnable() {
            public void run() {
		        final PipedServer server = new PipedServer();
		        server.setConnection(connection);

                nakedObjects.setConfiguration(new Configuration());
                
                JavaBusinessObjectContainer container = new JavaBusinessObjectContainer();
                new SystemClock();


                DataFactory objectDataFactory = new JavaObjectDataFactory();

                SingleResponseUpdateNotifier updateNotifier = new SingleResponseUpdateNotifier();
                updateNotifier.setFactory(objectDataFactory);

                JavaObjectFactory objectFactory = new JavaObjectFactory();
                objectFactory.setContainer(container);

                OidGenerator oidGenerator = new SimpleOidGenerator();

                DefaultPersistAlgorithm persistAlgorithm = new DefaultPersistAlgorithm();
                persistAlgorithm.setOidGenerator(oidGenerator);

                LocalObjectManager localObjectManager = new LocalObjectManager();
                localObjectManager.setObjectStore(objectStore);
                localObjectManager.setPersistAlgorithm(persistAlgorithm);
                localObjectManager.setCheckObjectsForDirtyFlag(true);

                NakedObjectManager objectManager = localObjectManager;
          //      objectManager = new ObjectManagerLogger(objectManager, "server-manager.log");
                nakedObjects.setObjectManager(objectManager);

                LocalReflectionFactory reflectionFactory = new LocalReflectionFactory();

                ObjectLoaderImpl objectLoader = new ObjectLoaderImpl();
                objectLoader.setPojoAdapterMap(new PojoAdapterHashMap());
                objectLoader.setObjectFactory(objectFactory);
                objectLoader.setAdapterFactory(new JavaAdapterFactory());
                objectLoader.setIdentityAdapterMap(new IdentityAdapterHashMap());
                nakedObjects.setObjectLoader(objectLoader);

                nakedObjects.setReflectionFactory(reflectionFactory);

                nakedObjects.setSpecificationLoader(new JavaSpecificationLoader());

                ServerDistribution sd = new ServerDistribution();
                sd.setObjectDataFactory(objectDataFactory);
                
                Distribution serverLogger = sd;
                //serverLogger = new DistributionLogger(serverLogger, "server-connection.log");
                    
                server.setFacade(serverLogger);
                server.setUpdateNotifier(updateNotifier);

                objectManager.addObjectChangedListener(updateNotifier);

                nakedObjects.init();
                
                JavaFixtureBuilder fb = new JavaFixtureBuilder();
                CitiesFixture cities;
                fb.addFixture(cities = new CitiesFixture());
                fb.addFixture(new BookingsFixture(cities));
                fb.addFixture(new ClassesFixture());
                fb.installFixtures();

                InfoDebugFrame debugFrame = new InfoDebugFrame() {
                    private static final long serialVersionUID = 1L;

                    public void dialogClosing() {
                        System.exit(0);
                    }
                };
                DebugInfo debugInfo = objectManager;
                debugFrame.setInfo(debugInfo);
                debugFrame.setBounds(500, 300, 1000, 700);
                debugFrame.refresh();
                debugFrame.show();
                
                updateNotifier.getUpdates();

                server.run();
            }
        };
        Thread serverThread = new Thread(runnable, "server");
        nakedObjects.setServer(serverThread);
        serverThread.start();
    }

    
    private void client(final NakedObjectsPipe nakedObjects, final PipedConnection connection) {
        Configuration configuration = new Configuration(new ConfigurationPropertiesLoader(CLIENT_CONFIG, true));
        nakedObjects.setConfiguration(configuration);
        
        PipedClient client =  new PipedClient();
        client.setConnection(connection);
        
        Distribution clientLogger = client; //new DistributionLogger(client, "client-connection.log");

        Date.setClock(new SystemClock());

        JavaBusinessObjectContainer container = new JavaBusinessObjectContainer();

        JavaObjectFactory objectFactory = new JavaObjectFactory();
        objectFactory.setContainer(container);


        JavaObjectDataFactory objectDataFactory = new JavaObjectDataFactory();

        ProxyObjectManager proxyObjectManager = new ProxyObjectManager();
        proxyObjectManager.setConnection(clientLogger);
        proxyObjectManager.setObjectDataFactory(objectDataFactory);

        NakedObjectManager objectManager = proxyObjectManager; //new ObjectManagerLogger(proxyObjectManager, "client-manager.log");
        nakedObjects.setObjectManager(objectManager);

        ProxyReflectionFactory reflectionFactory = new ProxyReflectionFactory();
        reflectionFactory.setConnection(clientLogger);
        reflectionFactory.setObjectDataFactory(objectDataFactory);<commit_msg>Moved the use of the update notifier into ServerDistribution, so that it can remove objects from the dirty list when doing makePersistent (to avoid duplicate updates and 'made persistent' objects when objects use dirty flags).<commit_after>
import org.nakedobjects.application.system.SystemClock;
import org.nakedobjects.application.valueholder.Date;
import org.nakedobjects.container.configuration.Configuration;
import org.nakedobjects.container.configuration.ConfigurationPropertiesLoader;
import org.nakedobjects.distribution.DataFactory;
import org.nakedobjects.distribution.Distribution;
import org.nakedobjects.distribution.ProxyObjectManager;
import org.nakedobjects.distribution.ProxyReflectionFactory;
import org.nakedobjects.distribution.ServerDistribution;
import org.nakedobjects.distribution.SingleResponseUpdateNotifier;
import org.nakedobjects.distribution.java.JavaDataFactory;
import org.nakedobjects.distribution.pipe.NakedObjectsPipe;
import org.nakedobjects.distribution.pipe.PipedClient;
import org.nakedobjects.distribution.pipe.PipedConnection;
import org.nakedobjects.distribution.pipe.PipedServer;
import org.nakedobjects.object.defaults.IdentityAdapterHashMap;
import org.nakedobjects.object.defaults.LocalReflectionFactory;
import org.nakedobjects.object.defaults.ObjectLoaderImpl;
import org.nakedobjects.object.defaults.PojoAdapterHashMap;
import org.nakedobjects.object.persistence.NakedObjectManager;
import org.nakedobjects.object.persistence.NakedObjectStore;
import org.nakedobjects.object.persistence.ObjectStoreLogger;
import org.nakedobjects.object.persistence.OidGenerator;
import org.nakedobjects.object.persistence.defaults.DefaultPersistAlgorithm;
import org.nakedobjects.object.persistence.defaults.LocalObjectManager;
import org.nakedobjects.object.persistence.defaults.SimpleOidGenerator;
import org.nakedobjects.reflector.java.JavaBusinessObjectContainer;
import org.nakedobjects.reflector.java.JavaObjectFactory;
import org.nakedobjects.reflector.java.fixture.JavaFixtureBuilder;
import org.nakedobjects.reflector.java.reflect.JavaAdapterFactory;
import org.nakedobjects.reflector.java.reflect.JavaSpecificationLoader;
import org.nakedobjects.system.AboutNakedObjects;
import org.nakedobjects.system.SplashWindow;
import org.nakedobjects.utility.DebugInfo;
import org.nakedobjects.utility.InfoDebugFrame;
import org.nakedobjects.viewer.ObjectViewingMechanismListener;
import org.nakedobjects.viewer.skylark.SkylarkViewer;
import org.nakedobjects.viewer.skylark.ViewUpdateNotifier;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.PropertyConfigurator;

import exploration.Context;
import fixtures.BookingsFixture;
import fixtures.CitiesFixture;
import fixtures.ClassesFixture;


public abstract class StandaloneClientServer {
    private static final String COMMON_CONFIG = "logging.properties";
    private static final String CLIENT_CONFIG = "client.properties";
    
    protected void init() {
        BasicConfigurator.configure();

        Configuration configuration = new Configuration(new ConfigurationPropertiesLoader(COMMON_CONFIG, true));
        PropertyConfigurator.configure(configuration.getProperties("log4j"));

        AboutNakedObjects.logVersion();

        SplashWindow splash = null;
        boolean noSplash = configuration.getBoolean("nosplash", false);
        if (!noSplash) {
            splash = new SplashWindow();
        }

        try {
	        PipedConnection connection = new PipedConnection();

	        NakedObjectsPipe nakedObjects = new NakedObjectsPipe();

            server(nakedObjects, connection);
            client(nakedObjects, connection);
        } finally {
            if (splash != null) {
                splash.toFront();
                splash.removeAfterDelay(3);
            }
        }
    }

    private void server(final NakedObjectsPipe nakedObjects, final PipedConnection connection) {
        final NakedObjectStore objectStore = new ObjectStoreLogger(objectStore(), "server-store.log");
		    
        Runnable runnable = new Runnable() {
            public void run() {
		        final PipedServer server = new PipedServer();
		        server.setConnection(connection);

                nakedObjects.setConfiguration(new Configuration());
                
                JavaBusinessObjectContainer container = new JavaBusinessObjectContainer();
                new SystemClock();



                JavaObjectFactory objectFactory = new JavaObjectFactory();
                objectFactory.setContainer(container);

                OidGenerator oidGenerator = new SimpleOidGenerator();

                DefaultPersistAlgorithm persistAlgorithm = new DefaultPersistAlgorithm();
                persistAlgorithm.setOidGenerator(oidGenerator);

                LocalObjectManager localObjectManager = new LocalObjectManager();
                localObjectManager.setObjectStore(objectStore);
                localObjectManager.setPersistAlgorithm(persistAlgorithm);
                localObjectManager.setCheckObjectsForDirtyFlag(true);

                NakedObjectManager objectManager = localObjectManager;
          //      objectManager = new ObjectManagerLogger(objectManager, "server-manager.log");
                nakedObjects.setObjectManager(objectManager);

                LocalReflectionFactory reflectionFactory = new LocalReflectionFactory();

                ObjectLoaderImpl objectLoader = new ObjectLoaderImpl();
                objectLoader.setPojoAdapterMap(new PojoAdapterHashMap());
                objectLoader.setObjectFactory(objectFactory);
                objectLoader.setAdapterFactory(new JavaAdapterFactory());
                objectLoader.setIdentityAdapterMap(new IdentityAdapterHashMap());
                nakedObjects.setObjectLoader(objectLoader);

                nakedObjects.setReflectionFactory(reflectionFactory);

                nakedObjects.setSpecificationLoader(new JavaSpecificationLoader());

                SingleResponseUpdateNotifier updateNotifier = new SingleResponseUpdateNotifier();
             //   updateNotifier.setFactory(dataFactory);


                ServerDistribution sd = new ServerDistribution();
                DataFactory dataFactory = new JavaDataFactory();
                sd.setObjectDataFactory(dataFactory);
                sd.setUpdateNotifier(updateNotifier);
                
                Distribution serverLogger = sd;
                //serverLogger = new DistributionLogger(serverLogger, "server-connection.log");
                    
                server.setFacade(serverLogger);
                //server.setUpdateNotifier(updateNotifier);
                server.setDistribution(sd);

                objectManager.addObjectChangedListener(updateNotifier);

                nakedObjects.init();
                
                JavaFixtureBuilder fb = new JavaFixtureBuilder();
                CitiesFixture cities;
                fb.addFixture(cities = new CitiesFixture());
                fb.addFixture(new BookingsFixture(cities));
                fb.addFixture(new ClassesFixture());
                fb.installFixtures();

                InfoDebugFrame debugFrame = new InfoDebugFrame() {
                    private static final long serialVersionUID = 1L;

                    public void dialogClosing() {
                        System.exit(0);
                    }
                };
                DebugInfo debugInfo = objectManager;
                debugFrame.setInfo(debugInfo);
                debugFrame.setBounds(500, 300, 1000, 700);
                debugFrame.refresh();
                debugFrame.show();
                
                updateNotifier.clearUpdates();

                server.run();
            }
        };
        Thread serverThread = new Thread(runnable, "server");
        nakedObjects.setServer(serverThread);
        serverThread.start();
    }

    
    private void client(final NakedObjectsPipe nakedObjects, final PipedConnection connection) {
        Configuration configuration = new Configuration(new ConfigurationPropertiesLoader(CLIENT_CONFIG, true));
        nakedObjects.setConfiguration(configuration);
        
        PipedClient client =  new PipedClient();
        client.setConnection(connection);
        
        Distribution clientLogger = client; //new DistributionLogger(client, "client-connection.log");

        Date.setClock(new SystemClock());

        JavaBusinessObjectContainer container = new JavaBusinessObjectContainer();

        JavaObjectFactory objectFactory = new JavaObjectFactory();
        objectFactory.setContainer(container);


        JavaDataFactory objectDataFactory = new JavaDataFactory();

        ProxyObjectManager proxyObjectManager = new ProxyObjectManager();
        proxyObjectManager.setConnection(clientLogger);
        proxyObjectManager.setObjectDataFactory(objectDataFactory);

        NakedObjectManager objectManager = proxyObjectManager; //new ObjectManagerLogger(proxyObjectManager, "client-manager.log");
        nakedObjects.setObjectManager(objectManager);

        ProxyReflectionFactory reflectionFactory = new ProxyReflectionFactory();
        reflectionFactory.setConnection(clientLogger);
        reflectionFactory.setObjectDataFactory(objectDataFactory);
{'fraction_non_alphanumeric': 0.07463665173205114, 'fraction_numerical': 0.0020762758168506174, 'mean_word_length': 3.1588275391956375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1786651', 'n_tokens_mistral': 4487, 'n_tokens_neox': 4216, 'n_words': 761}