Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.rmi.registry.LocateRegistry;
- import java.rmi.registry.Registry;
- import java.math.BigDecimal;
- import compute.Compute;
- import java.util.Properties;
- import java.io.FileInputStream;
- public class ComputePi {
- private static String sysPropsFile = "uk/org/client/Properties.txt";
- private static String clientPolicyFileDefault = "uk/org/client/client.policy";
- public static void run( String regHost, String precision ) {
- setSystemProps();
- if(System.getSecurityManager() == null) {
- System.setSecurityManager(new SecurityManager());
- }
- try {
- String name = "Compute";
- Registry registry = LocateRegistry.getRegistry(regHost);
- Compute comp = (Compute) registry.lookup(name);
- Pi task = new Pi(Integer.parseInt(precision));
- BigDecimal pi = comp.executeTask(task);
- System.out.println(pi);
- } catch(Exception e) {
- System.err.println("ComputePi exception.");
- e.printStackTrace();
- }
- }
- /**
- Normally set at runtime, these properties
- tell the app where things are and what to use for RMI
- **/
- public static void setSystemProps() {
- Properties p = new Properties(System.getProperties());
- try {
- // Find the sys props file
- String f = Thread.currentThread().getContextClassLoader().getResource(sysPropsFile).getFile();
- // Loads the sys props from a file
- FileInputStream propFile = new FileInputStream( f );
- p.load(propFile);
- } catch(Exception e) {
- System.err.println("Error: Failed to load client properties.");
- e.printStackTrace();
- System.err.println("Setting default properties...");
- // Set defaults
- p.setProperty("java.rmi.server.codebase","http://10.0.0.243:9876/smartmeters/classes/");
- }
- // Find the client policy
- String clientPolicyFile = p.getProperty("java.security.policy");
- try {
- // Find the sys props file
- String cf = Thread.currentThread().getContextClassLoader().getResource(clientPolicyFileDefault).getFile();
- if(cf==null)
- System.err.println("Warning: Failed to find the client policy file.");
- else
- clientPolicyFile = cf;
- } catch(Exception e) {
- e.printStackTrace();
- }
- p.setProperty("java.security.policy",clientPolicyFile);
- // set the system properties
- System.setProperties(p);
- // display new properties
- //System.getProperties().list(System.out);
- }
- public static void testThisThing() {
- System.out.println("COMPUTEPI.TEST SUCCESS!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement