Hi there,

i am playing around with the Elastic-feature added in X10 2.5.0. Are PlaceLocalHandles supported with Elastic? If so, where is the entry-point of the new place(s)? The code appended throws a NullPointerException, when a place is added. Line 60 to 76 enables Elasticity on the program, but seems overkill for me. Is there a shorter / more elegant solution for this?

The program was started with:
>$ X10_NPLACES=3 X10_FORCEPORTS=7000 x10 ElasticHelloWorld greetings 10

A place was added via:
>$ x10 -DX10_JOIN_EXISTING=localhost:7000 ElasticHelloWorld

Cheers,
Marco
/*
 *  This file is part of the X10 project (http://x10-lang.org).
 *
 *  This file is licensed to You under the Eclipse Public License (EPL);
 *  You may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *      http://www.opensource.org/licenses/eclipse-1.0.php
 *
 *  (C) Copyright IBM Corporation 2014.
 */

class ElasticHelloWorld
{
    var counter:long;
    val msg:String;
    
    public def this(val msg:String)
    {
        Console.OUT.println(here + "Constructor called.");
        this.msg = msg;
        this.counter = 0;
    }

    public def this(val counter:long, val msg:String)
    {
        Console.OUT.println(here + "Constructor called.");
        this.msg = msg;
        this.counter = counter;
    }

    public def run()
    {
        Console.OUT.println(here + "says hello and " + this.msg + " " + 
this.counter++);
    }

    public static def main(val args:Rail[String]):void
    {
        if (args.size < 2)
        {
            Console.OUT.println("Usage: HelloWholeWorld message loopcount");
            return;
        }
        var oldSize:Long = Place.numPlaces();
        var oldWorld:PlaceGroup = Place.places();

        var plh:PlaceLocalHandle[ElasticHelloWorld]
            = PlaceLocalHandle.make[ElasticHelloWorld](Place.places()
                                                       , () =>
                                                         {
                                                             return new 
ElasticHelloWorld(args(0)); 
                                                         });

        for (i:Long in 0..(Long.parse(args(1))))
        {
            try
            {
                val world = Place.places();
                val size:Long = world.numPlaces();
                Console.OUT.println(here + " sees " + size + " places");
                // {
                //     if (size != oldSize)
                //     {
                //         val myPlh = plh;
                //         oldSize = size;
                //         oldWorld = world;
                //         plh = 
PlaceLocalHandle.make[ElasticHelloWorld](oldWorld
                //                                                        , () 
=> 
                //             {
                //                 if (null == myPlh())
                //                 {
                //                     return new ElasticHelloWorld(i, args(0));
                //                 }
                //                 return myPlh();
                //             });
                //     }
                // }
                val myPlh = plh;
                finish for (p in world)
                {
                    at (p) async
                    {
                        myPlh().run();
                    }
                }
            }
            catch (e:DeadPlaceException)
            {
                Console.OUT.println("Got DeadPlaceException from " + e.place + 
" in round "+i);
            }
            System.sleep(10000);
        }
        Console.OUT.println("Goodbye");
    }
}
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to