Last active
May 30, 2016 22:26
-
-
Save hugithordarson/4d6ae65783ddb7dcd6f1aa7e4a79bc6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package strimillinn.jrebel; | |
import org.apache.cayenne.DataObject; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.zeroturnaround.javarebel.ClassEventListener; | |
import org.zeroturnaround.javarebel.ReloaderFactory; | |
import strimillinn.core.StrimillinnCore; | |
/** | |
* Watches changes to classes, reloads the Cayenne Server Runtime if a DataObject class is changed | |
*/ | |
public class JRebelServerRuntimeReloader implements ClassEventListener { | |
private static final Logger logger = LoggerFactory.getLogger( JRebelServerRuntimeReloader.class ); | |
/** | |
* Start watching changes to classes. Invoke once, at application startup time. | |
*/ | |
public static void register() { | |
ReloaderFactory.getInstance().addClassReloadListener( new JRebelServerRuntimeReloader() ); | |
} | |
/** | |
* Triggered when changes to classes are detected. | |
* | |
* Reloads the Cayenne Server Runtime if the changed class is a subclass of DataObject (by nullifying a lazily initialized variable) | |
*/ | |
@Override | |
public void onClassEvent( int eventType, Class klass ) { | |
if( eventType == ClassEventListener.EVENT_RELOADED ) { | |
if( DataObject.class.isAssignableFrom( klass ) ) { | |
logger.info( "Detected change to DataObject class. Reloading Server Runtime" ); | |
StrimillinnCore._serverRuntime = null; | |
} | |
} | |
} | |
@Override | |
public int priority() { | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment