1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
public static void main(String[] args) throws Exception {
// Instanciate a custom Security Manager
System.setSecurityManager(new MySecurityManager());
// Set every environment variables in properties, as well as the
// security policy that shall be added even if a Security Manager has
// been instanciated before
ActivationGroupDesc.CommandEnvironment ace = null;
Properties props = new Properties();
props.put("java.security.policy", System.getenv("MY_HOME") + File.separator + "resources" + File.separator
+ "AllPermissionPolicy");
// The "location" String specifies a URL from where the class
// definition will come when this object is requested (activated).
// Don't forget the trailing slash at the end of the URL
// or your classes won't be found.
String location = System.getProperty("java.rmi.server.codebase");
// The location argument to the ActivationDesc constructor will be used
// to uniquely identify this class; it's location is relative to the
// URL-formatted String, location.
MarshalledObject data = null;
ActivationSystem localActivationSystem = ActivationGroup.getSystem();
// Variables declaration
ActivationGroupID agi = null;
ActivationDesc desc = null;
ActivationGroupDesc groupDesc = null;
try {
// FOR EACH project
File[] projects = (new File(System.getenv("MY_CONF"))).listFiles();
for (int p = 0; p < projects.length; p++) {
if (!projects[p].isFile()) {
String project = projects[p].getName();
File[] subprojects= projects[p].listFiles();
// FOR EACH subproject
for (int m = 0; m < subprojects.length; m++) {
if (!subprojects[m].isFile()) {
String subproject = subprojects[m].getName();
String lookupName = project + subproject + "MyActivableObject";
props.put("PROJECT", project);
props.put("SUBPROJECT", subproject);
// Activation Group Descriptor
groupDesc = new ActivationGroupDesc(props, ace);
agi = localActivationSystem.registerGroup(groupDesc);
// The activation group is what creates the activable object in a JVM
// Sets the activation group for the current JVM
//ActivationGroup.createGroup(agi, groupDesc, 0);
// Once the ActivationGroupDesc has been created, register it
// with the activation system to obtain its ID
desc = new ActivationDesc(agi, "example.MyActivableObject", location, data);
// Register with rmid
MyActivableObjectInterface mri = (MyActivableObjectInterface) Activatable.register(desc);
// Bind the stub to a name in the registry
Naming.rebind("//" + InetAddress.getLocalHost().getHostName() + ":" + MY_RMI_PORT + "/" + lookupName,
mri);
System.out.println(project + "\t" + subproject+ "\tMyActivableObject done.");
}
}
}
}
}
catch (Exception e) {
e.printStackTrace();
System.err.println("Failed to set up start services. " + e.getMessage());
}
System.exit(0);
} |
Partager