Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
Refactor LangCore_Actual
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed Nov 19, 2015
1 parent 701a722 commit 3b3fcb0
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 65 deletions.
Original file line number Original file line Diff line number Diff line change
@@ -1,36 +1,36 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2015 Bruno Medeiros and other Contributors. * Copyright (c) 2015 Bruno Medeiros and other Contributors.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Bruno Medeiros - initial API and implementation * Bruno Medeiros - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package melnorme.lang.ide.core.project_model; package melnorme.lang.ide.core.project_model;


import org.junit.Test; import org.junit.Test;


import melnorme.lang.ide.core.LangCore_Actual; import melnorme.lang.ide.core.LangCore_Actual;
import melnorme.lang.ide.core.tests.CommonCoreTest; import melnorme.lang.ide.core.tests.CommonCoreTest;
import melnorme.utilbox.concurrency.LatchRunnable; import melnorme.utilbox.concurrency.LatchRunnable;


public class BundleModelManagerTest extends CommonCoreTest { public class BundleModelManagerTest extends CommonCoreTest {


@Test @Test
public void testShutdown() throws Exception { testShutdown$(); } public void testShutdown() throws Exception { testShutdown$(); }
public void testShutdown$() throws Exception { public void testShutdown$() throws Exception {
BundleModelManager<?> bundleMgr = LangCore_Actual.createBundleModelManager(); BundleModelManager<?> bundleMgr = LangCore_Actual.createBundleModelManager();
bundleMgr.startManager(); bundleMgr.startManager();


final LatchRunnable latchRunnable = new LatchRunnable(); final LatchRunnable latchRunnable = new LatchRunnable();
bundleMgr.getModelAgent().submit(latchRunnable); bundleMgr.getModelAgent().submit(latchRunnable);


latchRunnable.awaitTaskEntry(); latchRunnable.awaitTaskEntry();


// Test that shutdown happens successfully even with pending task, and no log entries are made. // Test that shutdown happens successfully even with pending task, and no log entries are made.
bundleMgr.shutdownManager(); bundleMgr.shutdownManager();
} }


} }
35 changes: 13 additions & 22 deletions plugin_ide.core/src-lang/melnorme/lang/ide/core/LangCore.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*******************************************************************************/ *******************************************************************************/
package melnorme.lang.ide.core; package melnorme.lang.ide.core;


import static melnorme.utilbox.core.Assert.AssertNamespace.assertTrue;

import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Plugin;
Expand Down Expand Up @@ -40,27 +42,24 @@ public static LangCore getInstance() {
return pluginInstance; return pluginInstance;
} }


/* ----------------- Owned singletons: ----------------- */ protected LangCore2 langCore;


protected static final AbstractToolManager toolManager = LangCore_Actual.createToolManagerSingleton(); /* ----------------- Owned singletons: ----------------- */
protected static final SourceModelManager sourceModelManager = LangCore_Actual.createSourceModelManager();
protected static final BundleModelManager<?> bundleManager = LangCore_Actual.createBundleModelManager();
protected static final BuildManager buildManager = LangCore_Actual.createBuildManager();


public static AbstractToolManager getToolManager() { public static AbstractToolManager getToolManager() {
return toolManager; return pluginInstance.langCore.toolManager;
} }
public static SourceModelManager getSourceModelManager() { public static SourceModelManager getSourceModelManager() {
return sourceModelManager; return pluginInstance.langCore.sourceModelManager;
} }
public static BundleModelManager<?> getBundleModelManager() { public static BundleModelManager<?> getBundleModelManager() {
return bundleManager; return pluginInstance.langCore.bundleManager;
} }
public static LangBundleModel getBundleModel() { public static LangBundleModel getBundleModel() {
return bundleManager.getModel(); return pluginInstance.langCore.bundleManager.getModel();
} }
public static BuildManager getBuildManager() { public static BuildManager getBuildManager() {
return buildManager; return pluginInstance.langCore.buildManager;
} }


/* ----------------- ----------------- */ /* ----------------- ----------------- */
Expand All @@ -70,6 +69,8 @@ public static BuildManager getBuildManager() {
@Override @Override
public final void start(BundleContext context) throws Exception { public final void start(BundleContext context) throws Exception {
pluginInstance = this; pluginInstance = this;
LangCore2 langCore2 = new LangCore2();
assertTrue(this.langCore == langCore2);
super.start(context); super.start(context);
doCustomStart(context); doCustomStart(context);
} }
Expand All @@ -88,25 +89,15 @@ public final void initializeAfterUIStart() {
} else { } else {
initializedAfterUI = true; initializedAfterUI = true;


startAgentsAfterUIStart(); langCore.startAgentsAfterUIStart(this);
} }
} }


/**
* Start core agents, and do other initizaliation after UI is started.
*/
public void startAgentsAfterUIStart() {
bundleManager.startManager();
}

@Override @Override
public final void stop(BundleContext context) throws Exception { public final void stop(BundleContext context) throws Exception {
doCustomStop(context); doCustomStop(context);


buildManager.dispose(); langCore.shutdown();
bundleManager.shutdownManager();
sourceModelManager.dispose();
toolManager.shutdownNow();


super.stop(context); super.stop(context);
pluginInstance = null; pluginInstance = null;
Expand Down
33 changes: 33 additions & 0 deletions plugin_ide.core/src-lang/melnorme/lang/ide/core/LangCore2.java
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2014 Bruno Medeiros and other Contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Bruno Medeiros - initial API and implementation
*******************************************************************************/
package melnorme.lang.ide.core;

public class LangCore2 extends LangCore_Actual {

public LangCore2() {
}

protected void shutdown() {
buildManager.dispose();
bundleManager.shutdownManager();
sourceModelManager.dispose();
toolManager.shutdownNow();
}

/**
* Start core agents, and do other initizaliation after UI is started.
* @param langCore TODO
*/
public void startAgentsAfterUIStart(LangCore langCore) {
bundleManager.startManager();
}

}
39 changes: 31 additions & 8 deletions plugin_ide.core/src/melnorme/lang/ide/core/LangCore_Actual.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import LANG_PROJECT_ID.ide.core.engine.LANGUAGE_SourceModelManager; import LANG_PROJECT_ID.ide.core.engine.LANGUAGE_SourceModelManager;
import LANG_PROJECT_ID.ide.core.operations.LANGUAGE_BuildManager; import LANG_PROJECT_ID.ide.core.operations.LANGUAGE_BuildManager;
import LANG_PROJECT_ID.ide.core.operations.LANGUAGE_ToolManager; import LANG_PROJECT_ID.ide.core.operations.LANGUAGE_ToolManager;
import melnorme.lang.ide.core.operations.AbstractToolManager;
import melnorme.lang.ide.core.operations.build.BuildManager; import melnorme.lang.ide.core.operations.build.BuildManager;
import melnorme.lang.ide.core.project_model.LangBundleModel; import melnorme.lang.ide.core.project_model.LangBundleModel;


Expand All @@ -18,25 +19,47 @@ public class LangCore_Actual {


public static final String LANGUAGE_NAME = "Lang"; public static final String LANGUAGE_NAME = "Lang";


public static LANGUAGE_ToolManager createToolManagerSingleton() {
return new LANGUAGE_ToolManager(); public static LangCore2 instance;

/* ----------------- Owned singletons: ----------------- */

protected final AbstractToolManager toolManager;
protected final LANGUAGE_BundleModelManager bundleManager;
protected final BuildManager buildManager;
protected final LANGUAGE_SourceModelManager sourceModelManager;

public LangCore_Actual() {
instance = (LangCore2) this;
LangCore.pluginInstance.langCore = instance;

toolManager = createToolManagerSingleton();
bundleManager = createBundleModelManager();
buildManager = createBuildManager(bundleManager.getModel());
sourceModelManager = createSourceModelManager();
} }


public static LANGUAGE_SourceModelManager createSourceModelManager() { public static LANGUAGE_ToolManager createToolManagerSingleton() {
return new LANGUAGE_SourceModelManager(); return new LANGUAGE_ToolManager();
} }


public static LANGUAGE_BundleModelManager createBundleModelManager() { public static LANGUAGE_BundleModelManager createBundleModelManager() {
return new LANGUAGE_BundleModelManager(); return new LANGUAGE_BundleModelManager();
} }
public static LANGUAGE_BundleModel getBundleModel() { public static BuildManager createBuildManager(LangBundleModel bundleModel) {
return (LANGUAGE_BundleModel) LangCore.getBundleModel(); return new LANGUAGE_BuildManager(bundleModel);
} }
public static BuildManager createBuildManager() {
return new LANGUAGE_BuildManager(getBundleModel()); public static LANGUAGE_SourceModelManager createSourceModelManager() {
return new LANGUAGE_SourceModelManager();
} }




/* ----------------- ----------------- */

public static LANGUAGE_BundleModel getBundleModel() {
return instance.bundleManager.getModel();
}
public static class LANGUAGE_BundleModel extends LangBundleModel { public static class LANGUAGE_BundleModel extends LangBundleModel {


} }
Expand Down

0 comments on commit 3b3fcb0

Please sign in to comment.