package ora.example; import java.io.File; import ora.core.base.ElementManager; import ora.core.base.ElementManagerInterface; import ora.core.base.PersistenceConfiguration; import ora.core.referenceAnalyser.impl.ObjectReferencesCore; import ora.core.referenceAnalyser.impl.ObjectReferencesExceptSunsUIPackages; import ora.core.referenceAnalyser.interfaces.AnalyserInterface; import ora.core.remote.Command; import ora.core.remote.Session; import ora.core.remote.client.DataClient; import ora.core.remote.client.ElementManager_businessDelegate; import ora.core.remote.server.DataController; import ora.demo.objects.Customer; import ora.gui.Visualizer; import ora.gui.helper.MemoryThread; import ora.util.RuleManager; /** * Examples how to use ora */ public class Try { private static int remotePort = 11111; /** * This method analyses given object and save analyser results into given * file * * @param obj * @param filename * @return resulting file * @throws Exception */ public File takeSnapshotOfMyObjectInFile(Object obj, String filename) throws Exception { AnalyserInterface or = new ObjectReferencesExceptSunsUIPackages(); or.addAndAnalyseRootObject(obj); File file = new File(filename); or.save(file, (PersistenceConfiguration.PC_CONFIG)); return file; } /** * * @param file * @throws Exception */ public void showSavedSnapshot(File file) throws Exception { ElementManagerInterface em = new ElementManager(); em.load(file, PersistenceConfiguration.PC_BINXML); Visualizer vis = new Visualizer(em); vis.start(); } /** * This method registers given file for remote access through clients * @param file * @return key of the instance to be used for determination of the session. * @throws Exception */ public String registerFileForRemoteAccess(File file) throws Exception { DataController instance = DataController.getInstance(remotePort); String key = instance.register(file); return key; } /** * This method analyses object and shows it in visualizer * * @param obj * @throws Exception */ public void showMyObject(Object obj) throws Exception { AnalyserInterface or = new ObjectReferencesExceptSunsUIPackages(); or.addAndAnalyseRootObject(obj); Visualizer vis = new Visualizer(or); vis.start(); } /** * This method analyses given object and registers it for remote access through clients * @param obj * @return key of the instance to be used for determination of the session. * @throws Exception */ public String registerObjectForRemoteAccess(Object obj) throws Exception { AnalyserInterface or = new ObjectReferencesCore("Try",RuleManager.getAnalyserRulesUrl("LightWeightAnalyserRules")); or.addAndAnalyseRootObject(obj); DataController instance = DataController.getInstance(remotePort); String key = instance.register(or); return key; } /** * This method activates remote memory feature providing ability to monitor memory load remotely. * @return key of the instance to be used for determination of the session. * @throws Exception */ public String activateRemoteMemoryFeature() throws Exception { DataController instance = DataController.getInstance(remotePort); String key = instance.register(new MemoryThread()); return key; } /** * This method starts the empty visualizing component * * @throws Exception */ public void startGui() throws Exception { Visualizer vis = new Visualizer(new ElementManager()); vis.start(); } /** * Sample main method processing certain relevant methods * @param args * @throws Exception */ public static void main(String[] args) throws Exception { Customer customer = new Customer();//Create any object, e.g. Customer... Try tryObj = new Try();//Instanciate this class String key = tryObj.registerObjectForRemoteAccess(customer);//Register customer object DataClient client = new DataClient(new Session("localhost", remotePort, Session.PROTOCOL_PLAINSOCKET, key));//Get remote client ready ElementManager_businessDelegate emb = new ElementManager_businessDelegate(client);//Instanciate BD with Dataclient emb.remoteload();//initiate load, means retrieving of provided data emb.fireCommand(Command.SHUTDOWN_COMMAND);//Shutdown remote server File savedFile = File.createTempFile("save", "ora");//Create tempfile savedFile.deleteOnExit();//Ensure its temp only emb.save(savedFile, (PersistenceConfiguration.PC_CONFIG));//Persist loaded data... tryObj.showSavedSnapshot(savedFile);//Show (incl. load) persisted data... } }