Changeset 2708
- Timestamp:
- 02/17/05 15:26:49 (8 years ago)
- Location:
- trunk/jp/src/jp/lang
- Files:
-
- 3 edited
-
PartyClient.java (modified) (1 diff)
-
PartyServer.java (modified) (2 diffs)
-
PartyWorker.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/jp/src/jp/lang/PartyClient.java
r2707 r2708 4 4 import java.rmi.registry.LocateRegistry; 5 5 6 6 /** The client-tier application. */ 7 7 public class PartyClient { 8 8 public static void main(String[] args) throws Exception { -
trunk/jp/src/jp/lang/PartyServer.java
r2707 r2708 1 1 package jp.lang; 2 2 3 import jp.lang.ApplicationContext; 4 import jp.lang.Configuration; 5 import jp.lang.DistributedRuntime; 6 import jp.lang.RuntimeEnvironment; 7 import jp.lang.RuntimeManager; 8 3 9 import jp.lang.PartyConfig; 4 import jp.lang.Configuration;5 import jp.lang.RuntimeManager;6 import jp.lang.ApplicationContext;7 10 8 11 12 /** 13 * The middle-tier server. Instances of this class live outside the 14 * distributed JavaParty environment and mediate between client-tier 15 * applications and server-tier compute objects. 16 */ 9 17 public class PartyServer extends java.rmi.server.UnicastRemoteObject implements PartyServer_intf { 10 18 PartyConfig config; 11 RuntimeManager rm;12 ApplicationContext context;13 19 int size; 14 20 int nr = 0; 15 21 16 PartyServer(PartyConfig config , RuntimeManager rm) throws java.rmi.RemoteException, jp.lang.ConfigurationException {22 PartyServer(PartyConfig config) throws java.rmi.RemoteException { 17 23 this.config = config; 18 this.rm = rm; 19 this.context = rm.allocateContext(); 20 this.size = context.getMachineCnt(); 24 this.size = jp.lang.DistributedRuntime.getMachineCnt(); 21 25 } 22 26 23 public void gotoParty() throws ClassNotFoundException, java.rmi.RemoteException { 24 try { 25 if (config.verbose) System.err.println("Request for party"); 27 /** 28 * The RMI-style remote method declared in {@link 29 * PartyServer_intf}. 30 */ 31 public void gotoParty() { 32 if (config.verbose) System.err.println("Request for party"); 26 33 27 rm.getClassObject("jp.lang.PartyWorker"); 34 // Create a new worker object within the cluster. This uses 35 // regular JavaParty-style remote object creation. 36 PartyWorker worker = new PartyWorker(nr++); 28 37 29 if (config.verbose) System.err.println("Loaded worker class");38 if (config.verbose) System.err.println("Starting party"); 30 39 31 // Lookup the workers class. 32 PartyWorker_class_intf workerClassIntf = (PartyWorker_class_intf) 33 rm.getConstructorObject("jp.lang.PartyWorker", (nr++) % size); 34 35 if (config.verbose) System.err.println("Creating PartyWorker"); 36 37 // Create a new worker. 38 PartyWorker_instance_intf worker; 39 40 // The code is different for JavaParty/RMI and JavaParty/KaRMI: 41 // <%ifeq(@rmi.package@, uka.karmi.rmi)> 42 43 // In JavaParty/KaRMI, the per class factory method 44 // returns a bare remote reference instead of a stub 45 // object. 46 uka.karmi.rmi.server.UnicastRemoteClientRef workerRef = 47 (uka.karmi.rmi.server.UnicastRemoteClientRef) workerClassIntf._new(nr); 48 49 // Construct stub from worker reference locally. 50 worker = new PartyWorker_instance_impl_KStub(); 51 ((PartyWorker_instance_impl_KStub) worker)._KARMI_setRemoteClientRef(workerRef); 52 53 // <%> 54 55 worker = (PartyWorker_instance_intf) workerClassIntf._new(nr); 56 // <%/ifeq> 57 58 59 if (config.verbose) System.err.println("Starting party"); 60 61 // Start the work at the party 62 worker.party(); 63 } catch (@rmi.package@.RemoteException ex) { 64 // Translate the exceptions. 65 throw new java.rmi.RemoteException(ex.getMessage()); 66 } catch (jp.lang.MovedException ex) { 67 // Of course, this should not happen. 68 throw new java.rmi.RemoteException("worker escaped!"); 69 } 40 // Invoke the compute method on a server object within the 41 // distributed JavaParty environment. 42 worker.party(); 70 43 } 71 44 45 /** 46 * The main method of the middle-tier server. Contacts the 47 * JavaParty environment and exports a regular RMI-style server 48 * object to a local registry. 49 */ 72 50 public static void main(String[] args) throws Exception { 73 51 PartyConfig config = new PartyConfig(); … … 77 55 new Configuration(config.debug, config.host, config.port, config.code); 78 56 79 if (config.verbose) System.err.println("Look upRuntimeManager");57 if (config.verbose) System.err.println("Looking up the RuntimeManager"); 80 58 RuntimeManager rm = configuration.getRuntimeManager(/*timeout=forever*/ 0); 81 59 82 if (config.verbose) System.err.println("Creating local registry"); 60 // Initialize the JavaParty transparency layer (outside the 61 // distributed runtime environment). This is the trick used to 62 // get the "-frontend" switch in jpinvite normally to 63 // work. The current virtual machine can use all services of 64 // the connected runtime environment without being part of it 65 // itself. 66 ApplicationContext context = rm.allocateContext(); 67 jp.lang.RuntimeEnvironment.init(rm, context); 68 69 if (config.verbose) System.err.println("Creating the local RMI registry"); 83 70 java.rmi.registry.Registry registry = 84 71 java.rmi.registry.LocateRegistry.createRegistry( 85 72 java.rmi.registry.Registry.REGISTRY_PORT); 86 73 87 if (config.verbose) System.err.println("Binding PartyServer");88 registry.bind("PartyServer", new PartyServer(config , rm));74 if (config.verbose) System.err.println("Binding the PartyServer in the registry"); 75 registry.bind("PartyServer", new PartyServer(config)); 89 76 } 90 77 } -
trunk/jp/src/jp/lang/PartyWorker.java
r2707 r2708 6 6 7 7 8 /** 9 * The server-tier compute class. Instances of this class reside in 10 * the distributed JavaParty environment. 11 */ 8 12 public remote class PartyWorker { 9 13 int nr; … … 13 17 } 14 18 19 /** 20 * A JavaParty-style transparent remote method. This method is 21 * invoked from the client-tier application in {@link PartyClient} 22 * throug the middle-tier {@link PartyServer}. 23 */ 15 24 public void party() { 16 25 System.out.println("party#" + nr + "@work");
Note: See TracChangeset
for help on using the changeset viewer.
