Classes | |
interface | Platform |
Platform. More... | |
class | PlatformLowLevelException |
Platform low level exception. More... | |
interface | PlatformManager |
Platform Manager. More... | |
class | PlatformNotAvailableException |
Platform not available exception. More... | |
interface | Process |
Process. More... | |
interface | ProcessEvent |
Process event. More... | |
interface | ProcessInfo |
ProcessInfo. More... | |
interface | ProcessListEvent |
Process list event. More... | |
interface | ProcessListObserver |
Process list observer. More... | |
interface | ProcessObserver |
Process observer. More... | |
class | ProcessOptions |
ProcessOptions. More... | |
enum | ProcessStatus |
Detailed Description
To work with Deepsy Platform service it is necessary to use DeepsyPlatformManager located in com.gmv.its.deepsy.platformmanager for getting the initial PlatformManager object.
DeepsyPlatformManager.getInstance has an optional parameter indicating the ip address of remote service. For instance:
PlatformManager is an AutoCloseable interface. An object that may hold resources (such as file or socket handles) until it is closed. The close() method of an AutoCloseable object is called automatically when exiting a try-with-resources block for which the object has been declared in the resource specification header. This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur. To obtain a platform object:
If this object is not inside a try with resources block, it is recommended to call to platformManager.close() in order to finalize properly;
Service availability
To detect service availability the DeepsyPlatformManager implements Manager interface which provides methods for getting availability and subscribing to availability events.
Examples
-
Getting list of processes
For getting the list of processes to getProcesses method of Platform.package com.gmv.its.dpyjavaexamples.platform;import java.util.List;public class GetListOfProcessesApp {public static void main(String[] args) {Platform platform;platform = platformManager.getPlatform();List<Process> processList = platform.getProcesses();for (Process p : processList) {System.out.println(p.getName());ProcessInfo info = p.getInfo();System.out.println("\t- Status: " + info.getStatus());System.out.println("\t- Seconds running: " + info.getSecondsRunning());System.out.println("\t- Retries: " + info.getNumberOfRetries());System.out.println("\t- MTBF: " + info.getMtbf());ProcessOptions opt = p.getOptions();System.out.println("\t- ProcessPath: " + opt.getProcessPath());System.out.println("\t- Executable: " + opt.getProcessExec());System.out.println("\t- Args: " + opt.getArgs());System.out.println("\t- Relaunch: " + opt.getRelaunch());System.out.println("\t- DelayOnLaunch (seconds): " + opt.getDelayOnLaunch());System.out.println("\t- Critical (seconds): " + opt.getCritical());System.out.println("\t- PreScriptPath: " + opt.getPreScriptPath());System.out.println("\t- PostScriptPath: " + opt.getPostScriptPath());}} catch (Exception e) {e.printStackTrace();}}}
-
Add/Start/Stop/Delete a process
package com.gmv.its.dpyjavaexamples.platform;import java.util.Arrays;public class ManageAprocessApp {public static void main(String[] args) {Platform platform = platformManager.getPlatform();System.out.println("Adding \"ping\" process with a preScript and post script");ProcessOptions options = new ProcessOptions("ping", "/bin/", Arrays.asList("127.0.0.1"), true, 0, false, "/mntDAT/myPreScriptPath.sh", "/mntDAT/myPostScript.sh");Process myProcess = platform.addProcess("processTest", options);System.out.println("Starting \"ping\" process ");myProcess.start();System.out.println("Stopping \"ping\" process ");myProcess.stop();System.out.println("Deleting \"ping\" process ");platform.delProcess(myProcess);} catch (Exception e) {e.printStackTrace();}}}
-
Subscribe to events
There are 2 types of events in the platform system:- ProcessListEvent : This event happens when a process is added to or removed from the platform. To receive this kind of events, it is necessary to subscribe to the Platform object with an object implementing interface ProcessListObserver
- ProcessEvent : This event happens when a process is started, stopped or relaunched. To receive this kind of events, it is necessary to subscribe to the Process object with an object extending abstract class ProcessObserver
This example subscribes to every event.
package com.gmv.its.dpyjavaexamples.platform;import java.util.List;class MyProcessObserver implements ProcessObserver {}}class MyPlatformObserver implements ProcessListObserver {MyProcessObserver myProcessObserver;MyPlatformObserver(MyProcessObserver processObserver) {myProcessObserver = processObserver;}if (event.getAction() == ProcessListAction.ADDED) {try {event.getProcess().subscribe(myProcessObserver);} catch (CannotSubscribeException e) {e.printStackTrace();}} else {try {event.getProcess().unSubscribe(myProcessObserver);} catch (ObserverNotSubscribedException e) {e.printStackTrace();}}}}public class PlatformEventsApp {public static void main(String[] args) {MyProcessObserver myProcessObserver = new MyProcessObserver();MyPlatformObserver myPlatformObserver = new MyPlatformObserver(myProcessObserver);Platform platform = platformManager.getPlatform();platform.subscribe(myPlatformObserver);System.out.println("Subscribed to platform manager events");for (Process p : platform.getProcesses()) {p.subscribe(myProcessObserver);}System.out.println("Subscribed to existing processes events");Thread.sleep(50000);} catch (Exception e) {e.printStackTrace();}}}