Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add JRebirth-Thread (to improve)

  • Loading branch information...
commit 11156e01f303bd3e8f38f8a8b8b1461af34e3773 1 parent 91fc611
@sbordes sbordes authored
View
1  org.jrebirth/analyzer/.classpath
@@ -3,7 +3,6 @@
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
- <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
View
2  org.jrebirth/analyzer/src/main/java/org/jrebirth/analyzer/JRebirthAnalyzer.java
@@ -34,7 +34,7 @@ public static void main(final String... args) {
* {@inheritDoc}
*/
@Override
- protected Class<? extends Model> getFirstModelClass() {
+ public Class<? extends Model> getFirstModelClass() {
return WorkbenchModel.class;
}
View
3  org.jrebirth/core/.classpath
@@ -1,9 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
- <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
- <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
- <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
View
55 org.jrebirth/core/src/main/java/org/jrebirth/core/application/AbstractApplication.java
@@ -35,7 +35,6 @@
import javafx.application.Application;
import javafx.event.EventHandler;
-import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.SceneBuilder;
import javafx.scene.input.KeyCode;
@@ -44,9 +43,6 @@
import javafx.stage.Stage;
import org.jrebirth.core.exception.CoreException;
-import org.jrebirth.core.facade.GlobalFacade;
-import org.jrebirth.core.facade.impl.GlobalFacadeImpl;
-import org.jrebirth.core.ui.Model;
import org.jrebirth.core.util.ClassUtility;
/**
@@ -64,9 +60,6 @@
*/
public abstract class AbstractApplication<P extends Pane> extends Application implements JRebirthApplication {
- /** The Global Facade object that handle other sub facade. */
- private transient GlobalFacade facade;
-
/** The application primary stage. */
private transient Stage stage;
@@ -79,6 +72,8 @@
/** The eventTracker status. */
private boolean eventTrackerEnabled = true;
+ private JRebirthThread jrebirthThread;
+
/**
* {@inheritDoc}
*/
@@ -87,9 +82,8 @@
public final void init() throws CoreException {
try {
super.init();
- // Build the global facade at startup
- this.facade = new GlobalFacadeImpl(this);
} catch (final Exception e) {
+ // getFacade().getLogger().error("Error while application init phase : " + e.getMessage());
throw new CoreException(e);
}
@@ -112,15 +106,14 @@ public final void start(final Stage primaryStage) {
// Customize the default scene previously created
initializeScene(this.scene);
- // Launch the first UI view
- launchFirstView();
+ JRebirthThread.getThread().launch(this);
// Attach the scene
primaryStage.setScene(this.scene);
primaryStage.show();
} catch (final CoreException ce) {
- getFacade().getLogger().error("Error while starting application : " + ce.getMessage());
+ // getFacade().getLogger().fatal("Error while starting application : " + ce.getMessage());
}
}
@@ -132,10 +125,11 @@ public final void start(final Stage primaryStage) {
public final void stop() throws CoreException {
try {
super.stop();
- this.facade.stop();
- this.facade = null;
+
+ this.jrebirthThread.interrupt();
} catch (final Exception e) {
+ // getFacade().getLogger().error("Error while stoping application : " + e.getMessage());
throw new CoreException(e);
}
}
@@ -195,25 +189,6 @@ public void handle(final KeyEvent event) {
protected abstract void customizeScene(final Scene scene);
/**
- * Launch the first view by adding it into the root node.
- *
- * @throws CoreException if the first class was not found
- */
- @SuppressWarnings("unchecked")
- protected final void launchFirstView() throws CoreException {
-
- final Class<? extends Model> first = getFirstModelClass();
-
- if (first == null) {
- throw new CoreException("No First Model Class defined.");
- }
- final Node firstNode = getFacade().getUiFacade().retrieve(first).getView().getRootNode();
- ((P) this.scene.getRoot()).getChildren().add(firstNode);
-
- firstNode.requestFocus();
- }
-
- /**
* Return the application title.
*
* @return the application title
@@ -252,13 +227,6 @@ protected P buildRootPane() throws CoreException {
}
/**
- * This method must be implemented to declare which UI Model to display first.
- *
- * @return the class of the first UI Model to launch
- */
- protected abstract Class<? extends Model> getFirstModelClass();
-
- /**
* @param loggerEnabled The loggerEnabled to set.
*/
public final void setLoggerEnabled(final boolean loggerEnabled) {
@@ -289,13 +257,6 @@ public final boolean isEventTrackerEnabled() {
}
/**
- * @return Returns the facade.
- */
- public final GlobalFacade getFacade() {
- return this.facade;
- }
-
- /**
* {@inheritDoc}
*/
@Override
View
9 org.jrebirth/core/src/main/java/org/jrebirth/core/application/JRebirthApplication.java
@@ -4,6 +4,8 @@
import javafx.scene.paint.Color;
import javafx.stage.Stage;
+import org.jrebirth.core.ui.Model;
+
/**
* The class <strong>JRebirthApplication</strong>.
*
@@ -47,4 +49,11 @@
*/
Scene getScene();
+ /**
+ * This method must be implemented to declare which UI Model to display first.
+ *
+ * @return the class of the first UI Model to launch
+ */
+ Class<? extends Model> getFirstModelClass();
+
}
View
164 org.jrebirth/core/src/main/java/org/jrebirth/core/application/JRebirthThread.java
@@ -0,0 +1,164 @@
+package org.jrebirth.core.application;
+
+import java.util.List;
+import java.util.Vector;
+
+import javafx.application.Platform;
+import javafx.scene.Node;
+import javafx.scene.layout.Pane;
+
+import org.jrebirth.core.exception.CoreException;
+import org.jrebirth.core.facade.GlobalFacade;
+import org.jrebirth.core.facade.impl.GlobalFacadeImpl;
+import org.jrebirth.core.ui.Model;
+
+/**
+ * The class <strong>JRebirthThread</strong>. TODO To complete
+ *
+ * @author Sébastien Bordes
+ *
+ * @version $Revision$ $Author$
+ * @since $Date$
+ */
+public class JRebirthThread extends Thread {
+
+ private static JRebirthThread jrebirthThread;
+
+ /** The Global Facade object that handle other sub facade. */
+ private transient GlobalFacade facade;
+
+ private transient JRebirthApplication application;
+
+ private final List<Runnable> tasks;
+
+ /**
+ * Build the JRebirth Thread.
+ */
+ private JRebirthThread() {
+ super("JRebirth Thread");
+ setDaemon(true);
+ this.tasks = new Vector<>();
+ }
+
+ public synchronized void runAsap(final Runnable runnable) {
+ this.tasks.add(runnable);
+ }
+
+ /**
+ *
+ * TODO To complete.
+ *
+ * @param application
+ */
+ public void launch(final JRebirthApplication application) {
+ this.application = application;
+ // Build the global facade at startup
+ this.facade = new GlobalFacadeImpl(application);
+
+ start();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void run() {
+
+ try {
+ launchFirstView();
+ } catch (final CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ while (true) {
+ try {
+ // Collections.sort(tasks);
+
+ synchronized (this) {
+ for (final Runnable r : this.tasks) {
+ r.run();
+ }
+ this.tasks.clear();
+ }
+ Thread.sleep(20);
+ } catch (final InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void interrupt() {
+ super.interrupt();
+
+ try {
+ this.facade.stop();
+ this.facade = null;
+ } catch (final CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Launch the first view by adding it into the root node.
+ *
+ * @throws CoreException if the first class was not found
+ */
+ @SuppressWarnings("unchecked")
+ protected final void launchFirstView() throws CoreException {
+
+ final Class<? extends Model> first = this.application.getFirstModelClass();
+
+ if (first == null) {
+ throw new CoreException("No First Model Class defined.");
+ }
+ final Node firstNode = getFacade().getUiFacade().retrieve(first).getView().getRootNode();
+
+ Platform.runLater(new Runnable() {
+
+ @Override
+ public void run() {
+ ((Pane) JRebirthThread.this.application.getScene().getRoot()).getChildren().add(firstNode);
+ firstNode.requestFocus();
+ }
+ });
+ }
+
+ /**
+ * @return Returns the application.
+ */
+ protected JRebirthApplication getApplication() {
+ return this.application;
+ }
+
+ /**
+ * @param application The application to set.
+ */
+ protected void setApplication(final JRebirthApplication application) {
+ this.application = application;
+ }
+
+ /**
+ * @return Returns the facade.
+ */
+ public final GlobalFacade getFacade() {
+ return this.facade;
+ }
+
+ /**
+ * TODO To complete.
+ */
+ public static JRebirthThread getThread() {
+ if (jrebirthThread == null) {
+ jrebirthThread = new JRebirthThread();
+ }
+ return jrebirthThread;
+ }
+
+}
View
10 org.jrebirth/core/src/main/java/org/jrebirth/core/event/AbstractRecord.java
@@ -47,8 +47,10 @@ private OutputStream getOutputStream() {
@Override
public final void record(final String data) {
try {
- getOutputStream().write(data.getBytes());
- getOutputStream().flush();
+ if (getOutputStream() != null) {
+ getOutputStream().write(data.getBytes());
+ getOutputStream().flush();
+ }
} catch (final IOException e) {
// Nothing that we can do
return;
@@ -61,7 +63,9 @@ public final void record(final String data) {
@Override
public void closeOutputStream() throws CoreException {
try {
- getOutputStream().close();
+ if (getOutputStream() != null) {
+ getOutputStream().close();
+ }
} catch (final IOException e) {
throw new CoreException("Impossible to close the output stream", e);
}
View
79 org.jrebirth/core/src/main/java/org/jrebirth/core/link/impl/AbstractReady.java
@@ -5,6 +5,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.jrebirth.core.application.JRebirthThread;
import org.jrebirth.core.command.Command;
import org.jrebirth.core.event.EventType;
import org.jrebirth.core.exception.CoreException;
@@ -85,36 +86,11 @@ public final void unlisten(final WaveType waveType) {
}
/**
- * Build a wave object.
- *
- * @param waveGroup the group of the wave
- * @param waveType the type of the wave
- * @param relatedClass the related class if any
- * @param data wave data
- *
- * @return the wave built
- */
- private Wave createWave(final WaveGroup waveGroup, final WaveType waveType, final Class<?> relatedClass, final WaveData... data) {
- final Wave wave = new WaveImpl();
- wave.setWaveGroup(waveGroup);
- wave.setWaveType(waveType);
- wave.setRelatedClass(relatedClass);
- for (final WaveData wd : data) {
- wave.add(wd.getKey(), wd);
- }
-
- // Track wave creation
- getLocalFacade().getGlobalFacade().trackEvent(EventType.CREATE_WAVE, this.getClass(), wave.getClass());
-
- return wave;
- }
-
- /**
* {@inheritDoc}
*/
@Override
public final void send(final WaveType waveType, final WaveData... waveData) {
- getNotifier().sendWave(createWave(WaveGroup.UNDEFINED, waveType, null, waveData));
+ buildAndSendWave(WaveGroup.UNDEFINED, waveType, null, waveData);
}
/**
@@ -122,7 +98,7 @@ public final void send(final WaveType waveType, final WaveData... waveData) {
*/
@Override
public final void callCommand(final Class<? extends Command> commandClass, final WaveData... data) {
- getNotifier().sendWave(createWave(WaveGroup.CALL_COMMAND, null, commandClass, data));
+ buildAndSendWave(WaveGroup.CALL_COMMAND, null, commandClass, data);
}
/**
@@ -130,7 +106,7 @@ public final void callCommand(final Class<? extends Command> commandClass, final
*/
@Override
public final void returnData(final Class<? extends Command> serviceClass, final WaveData... data) {
- getNotifier().sendWave(createWave(WaveGroup.RETURN_DATA, null, serviceClass, data));
+ buildAndSendWave(WaveGroup.RETURN_DATA, null, serviceClass, data);
}
/**
@@ -138,7 +114,52 @@ public final void returnData(final Class<? extends Command> serviceClass, final
*/
@Override
public final void displayUi(final Class<? extends Model> modelClass, final WaveData... data) {
- getNotifier().sendWave(createWave(WaveGroup.DISPLAY_UI, null, modelClass, data));
+ buildAndSendWave(WaveGroup.DISPLAY_UI, null, modelClass, data);
+ }
+
+ /**
+ * Build a new Wave Object and send it using the JRebirth Thread.
+ *
+ * @param waveGroup the group of the wave
+ * @param waveType the type of the wave
+ * @param relatedClass the related class if any
+ * @param data wave data
+ */
+ private final void buildAndSendWave(final WaveGroup waveGroup, final WaveType waveType, final Class<?> relatedClass, final WaveData... waveData) {
+
+ JRebirthThread.getThread().runAsap(
+ new Runnable() {
+
+ @Override
+ public void run() {
+ getNotifier().sendWave(createWave(waveGroup, waveType, relatedClass, waveData));
+ }
+ });
+ }
+
+ /**
+ * Build a wave object.
+ *
+ * @param waveGroup the group of the wave
+ * @param waveType the type of the wave
+ * @param relatedClass the related class if any
+ * @param data wave data
+ *
+ * @return the wave built
+ */
+ private Wave createWave(final WaveGroup waveGroup, final WaveType waveType, final Class<?> relatedClass, final WaveData... data) {
+ final Wave wave = new WaveImpl();
+ wave.setWaveGroup(waveGroup);
+ wave.setWaveType(waveType);
+ wave.setRelatedClass(relatedClass);
+ for (final WaveData wd : data) {
+ wave.add(wd.getKey(), wd);
+ }
+
+ // Track wave creation
+ getLocalFacade().getGlobalFacade().trackEvent(EventType.CREATE_WAVE, this.getClass(), wave.getClass());
+
+ return wave;
}
/**
View
18 org.jrebirth/core/src/main/java/org/jrebirth/core/ui/View.java
@@ -2,6 +2,8 @@
import javafx.scene.Node;
+import org.jrebirth.core.exception.CoreException;
+
/**
*
* The interface <strong>View</strong>.
@@ -41,8 +43,20 @@
C getController();
/**
- * Start the animation of the view..
+ * Prepare the view by creating all visual nodes.
+ *
+ * @throws CoreException if the preparation fails
+ */
+ void prepare() throws CoreException;
+
+ /**
+ * Start the show animation of the view.
+ */
+ void show();
+
+ /**
+ * Start hide animation of the view.
*/
- void animate();
+ void hide();
}
View
2  org.jrebirth/core/src/main/java/org/jrebirth/core/ui/impl/AbstractFXMLController.java
@@ -22,7 +22,7 @@
* {@inheritDoc}
*/
@Override
- public void setView(View<?, ?, ?> view) {
+ public void setView(final View<?, ?, ?> view) {
this.view = view;
}
View
26 org.jrebirth/core/src/main/java/org/jrebirth/core/ui/impl/AbstractModel.java
@@ -3,7 +3,6 @@
import java.util.HashMap;
import java.util.Map;
-import javafx.application.Platform;
import javafx.scene.Node;
import org.jrebirth.core.event.EventType;
@@ -60,13 +59,13 @@ public final void ready() throws CoreException {
// Initialize inner models (if any)
initializeInnerModels();
- Platform.runLater(new Runnable() {
-
- @Override
- public void run() {
- getView().animate();
- }
- });
+ // Platform.runLater(new Runnable() {
+ //
+ // @Override
+ // public void run() {
+ getView().show();
+ // }
+ // });
}
@@ -76,6 +75,9 @@ public void run() {
* @throws CoreException if the creation of the view fails
*/
protected final void initialize() throws CoreException {
+ // Prepare the current view
+ getView().prepare();
+
// Do custom stuff
customInitialize();
}
@@ -143,12 +145,12 @@ public final V getView() {
/**
* Create the view it was null.
*/
- protected void prepareView() {
- // Build the current view
+ private final void prepareView() {
+ // Build the current view by reflection
try {
- this.view = buildView();
+ this.view = (V) ClassUtility.buildGenericType(this.getClass(), 1, this);
} catch (final CoreException e) {
- throw new CoreRuntimeException("Failure while preparing the view for model " + getClass(), e);
+ throw new CoreRuntimeException("Failure while building the view for model " + getClass(), e);
}
}
View
15 org.jrebirth/core/src/main/java/org/jrebirth/core/ui/impl/AbstractView.java
@@ -62,6 +62,13 @@ public AbstractView(final M model) throws CoreException {
// Manage components controller
this.controller = buildController();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void prepare() throws CoreException {
// Initialize view components
initializeComponents();
@@ -74,7 +81,13 @@ public AbstractView(final M model) throws CoreException {
* {@inheritDoc}
*/
@Override
- public abstract void animate();
+ public abstract void show();
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public abstract void hide();
/**
* Build the root node.
View
10 org.jrebirth/core/src/main/java/org/jrebirth/core/ui/impl/DefaultView.java
@@ -38,7 +38,15 @@ public DefaultView(final M model) throws CoreException {
* {@inheritDoc}
*/
@Override
- public void animate() {
+ public void show() {
+ // Nothing to do generic
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void hide() {
// Nothing to do generic
}
View
1  org.jrebirth/distribution/.gitignore
@@ -0,0 +1 @@
+/target
Please sign in to comment.
Something went wrong with that request. Please try again.