Changeset 2708


Ignore:
Timestamp:
02/17/05 15:26:49 (8 years ago)
Author:
hauma
Message:

Proof of concept for a JavaParty RMI server (ticket:224)

  • Use the JavaParty transparency layer within the middle-tier PartyServer without making it part of the distributed environment. This works along the lines of the "-frontend" switch for regular JavaParty applications (with GUI).
Location:
trunk/jp/src/jp/lang
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/jp/src/jp/lang/PartyClient.java

    r2707 r2708  
    44import java.rmi.registry.LocateRegistry; 
    55 
    6  
     6/** The client-tier application. */ 
    77public class PartyClient { 
    88    public static void main(String[] args) throws Exception { 
  • trunk/jp/src/jp/lang/PartyServer.java

    r2707 r2708  
    11package jp.lang; 
    22 
     3import jp.lang.ApplicationContext; 
     4import jp.lang.Configuration; 
     5import jp.lang.DistributedRuntime; 
     6import jp.lang.RuntimeEnvironment; 
     7import jp.lang.RuntimeManager; 
     8 
    39import jp.lang.PartyConfig; 
    4 import jp.lang.Configuration; 
    5 import jp.lang.RuntimeManager; 
    6 import jp.lang.ApplicationContext; 
    710 
    811 
     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 */ 
    917public class PartyServer extends java.rmi.server.UnicastRemoteObject implements PartyServer_intf { 
    1018    PartyConfig config; 
    11     RuntimeManager rm; 
    12     ApplicationContext context; 
    1319    int size; 
    1420    int nr = 0; 
    1521 
    16     PartyServer(PartyConfig config, RuntimeManager rm) throws java.rmi.RemoteException, jp.lang.ConfigurationException { 
     22    PartyServer(PartyConfig config) throws java.rmi.RemoteException { 
    1723        this.config = config; 
    18         this.rm = rm; 
    19         this.context = rm.allocateContext(); 
    20         this.size = context.getMachineCnt(); 
     24        this.size = jp.lang.DistributedRuntime.getMachineCnt(); 
    2125    } 
    2226 
    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"); 
    2633 
    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++); 
    2837 
    29             if (config.verbose) System.err.println("Loaded worker class"); 
     38        if (config.verbose) System.err.println("Starting party"); 
    3039 
    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(); 
    7043    } 
    7144 
     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     */ 
    7250    public static void main(String[] args) throws Exception { 
    7351        PartyConfig config = new PartyConfig(); 
     
    7755            new Configuration(config.debug, config.host, config.port, config.code); 
    7856 
    79         if (config.verbose) System.err.println("Lookup RuntimeManager"); 
     57        if (config.verbose) System.err.println("Looking up the RuntimeManager"); 
    8058        RuntimeManager rm = configuration.getRuntimeManager(/*timeout=forever*/ 0); 
    8159 
    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"); 
    8370        java.rmi.registry.Registry registry =  
    8471            java.rmi.registry.LocateRegistry.createRegistry( 
    8572                java.rmi.registry.Registry.REGISTRY_PORT); 
    8673         
    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)); 
    8976    } 
    9077} 
  • trunk/jp/src/jp/lang/PartyWorker.java

    r2707 r2708  
    66 
    77 
     8/**  
     9 * The server-tier compute class. Instances of this class reside in 
     10 * the distributed JavaParty environment. 
     11 */ 
    812public remote class PartyWorker { 
    913    int nr; 
     
    1317    } 
    1418 
     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     */ 
    1524    public void party() { 
    1625        System.out.println("party#" + nr + "@work"); 
Note: See TracChangeset for help on using the changeset viewer.