Java Code Examples for java.rmi.registry.Registry#bind()

The following examples show how to use java.rmi.registry.Registry#bind() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RMIService.java    From pra with MIT License 6 votes vote down vote up
public void startService(int port
		, Remote obj, String bindName) {
	try {
		if (System.getSecurityManager() == null) 
			System.setSecurityManager(new SecurityManager());
		Registry registry = LocateRegistry.getRegistry( port );
		registry.bind(bindName, 
				UnicastRemoteObject.exportObject(obj, 0));
		
		System.err.println(
				"Server ready: bind "+  obj.getClass().getSimpleName()
				+" to "+bindName);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 2
Source File: RmiServer.java    From JavaTutorial with Apache License 2.0 6 votes vote down vote up
/**
 * @param args [0]:绑定端口
 * @throws RemoteException 
 */
public static void main(String[] args) throws RemoteException {
    int port = Integer.parseInt(args[0]);
    UserService userService = new UserServiceImpl();
    Registry registry = createRegistry(port);
    if (null == registry) {
        System.exit(0);
    }
    
    String bindName = "UserService";
    try {
        registry.bind(bindName, userService);
    } catch (AlreadyBoundException e) {
        _logger.info("服务{}已经绑定过", bindName);
    }
    
    _logger.info("RMI Server started, listen port:{}", port);
}
 
Example 3
Source File: DUnitLauncher.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private static void launch() throws URISyntaxException, AlreadyBoundException, IOException, InterruptedException, NotBoundException  {
//    initialize the log writer that hydra uses
    LogWriter log = Log.createLogWriter( "dunit-master", LOG_LEVEL );

    locatorPort = AvailablePortHelper.getRandomAvailableTCPPort();
     
    //create an RMI registry and add an object to share our tests config
    int namingPort = AvailablePortHelper.getRandomAvailableTCPPort();
    Registry registry = LocateRegistry.createRegistry(namingPort);
    Master master = new Master();
    registry.bind(MASTER_PARAM, master);

    final ProcessManager processManager = new ProcessManager(NUM_VMS + 1, namingPort);

    Runtime.getRuntime().addShutdownHook(new Thread() {
      public void run() {
        processManager.killVMs();
      }
    });
    
    //launch the remote VMS
    processManager.launchVMs();
    
    //wait for the VMS to start up
    if(!master.waitForVMs(STARTUP_TIMEOUT)) {
      throw new RuntimeException("VMs did not start up with 30 seconds");
    }
    
    //populate the Host class with our stubs. The tests use this host class
    EclipseDUnitHost host = new EclipseDUnitHost(InetAddress.getLocalHost().getCanonicalHostName(), NUM_VMS);
    host.init(registry);

    initSystemProperties(log);
    
    startLocator(registry);
  }
 
Example 4
Source File: DUnitLauncher.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private static void launch() throws URISyntaxException, AlreadyBoundException, IOException, InterruptedException, NotBoundException  {
//    initialize the log writer that hydra uses
    LogWriter log = Log.createLogWriter( "dunit-master", LOG_LEVEL );

    locatorPort = AvailablePortHelper.getRandomAvailableTCPPort();
     
    //create an RMI registry and add an object to share our tests config
    int namingPort = AvailablePortHelper.getRandomAvailableTCPPort();
    Registry registry = LocateRegistry.createRegistry(namingPort);
    Master master = new Master();
    registry.bind(MASTER_PARAM, master);

    final ProcessManager processManager = new ProcessManager(NUM_VMS + 1, namingPort);

    Runtime.getRuntime().addShutdownHook(new Thread() {
      public void run() {
        processManager.killVMs();
      }
    });
    
    //launch the remote VMS
    processManager.launchVMs();
    
    //wait for the VMS to start up
    if(!master.waitForVMs(STARTUP_TIMEOUT)) {
      throw new RuntimeException("VMs did not start up with 30 seconds");
    }
    
    //populate the Host class with our stubs. The tests use this host class
    EclipseDUnitHost host = new EclipseDUnitHost(InetAddress.getLocalHost().getCanonicalHostName(), NUM_VMS);
    host.init(registry);

    initSystemProperties(log);
    
    startLocator(registry);
  }
 
Example 5
Source File: Server.java    From OpenDA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String getInstance(IStochModelFactory.OutputLevel outputLevel)  {
    String instanceID=null;

 try {
        nModels++;
        instanceID= FactoryBindingID+"_IRmiIStochModel_"+nModels;

        // Create a new model instance
        IStochModelInstance newStochModel = stochModelFactory.getInstance(outputLevel);
        // Create a new server instance and set the new model for this instance
        Server obj = new Server();
        obj.setModel(newStochModel);

        IRmiIStochModel stub = (IRmiIStochModel) UnicastRemoteObject.exportObject(obj, 0);

        // Register this insntance such that it will not be deleted.
        allStochModels.add(stub);

       // Bind the remote object's stub in the registry
     Registry registry = LocateRegistry.getRegistry();
     registry.bind(instanceID, stub);

     System.err.println("Server has created model "+instanceID);
 } catch (Exception e) {
     System.err.println("Server exception when creating new model: " + e.toString());
     e.printStackTrace();
 }
    return instanceID;
}
 
Example 6
Source File: EmptyName.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Registry impl = TestLibrary.createRegistryOnUnusedPort();
    Registry stub = (Registry) RemoteObject.toStub(impl);
    stub.bind("", stub);
    stub.lookup("");
    stub.rebind("", stub);
    stub.lookup("");
    stub.unbind("");
}
 
Example 7
Source File: readTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    try {
        testPkg.Server obj = new testPkg.Server();
        testPkg.Hello stub = (testPkg.Hello) UnicastRemoteObject.exportObject(obj, 0);
        // Bind the remote object's stub in the registry
        Registry registry =
            LocateRegistry.getRegistry(TestLibrary.READTEST_REGISTRY_PORT);
        registry.bind("Hello", stub);

        System.err.println("Server ready");

        // now, let's test client
        testPkg.Client client =
            new testPkg.Client(TestLibrary.READTEST_REGISTRY_PORT);
        String testStubReturn = client.testStub();
        if(!testStubReturn.equals(obj.hello)) {
            throw new RuntimeException("Test Fails : unexpected string from stub call");
        } else {
            System.out.println("Test passed");
        }
        registry.unbind("Hello");

    } catch (Exception e) {
        System.err.println("Server exception: " + e.toString());
        e.printStackTrace();
    }

}
 
Example 8
Source File: EmptyName.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Registry impl = TestLibrary.createRegistryOnUnusedPort();
    Registry stub = (Registry) RemoteObject.toStub(impl);
    stub.bind("", stub);
    stub.lookup("");
    stub.rebind("", stub);
    stub.lookup("");
    stub.unbind("");
}
 
Example 9
Source File: EmptyName.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Registry impl = TestLibrary.createRegistryOnUnusedPort();
    Registry stub = (Registry) RemoteObject.toStub(impl);
    stub.bind("", stub);
    stub.lookup("");
    stub.rebind("", stub);
    stub.lookup("");
    stub.unbind("");
}
 
Example 10
Source File: InheritedChannelNotServerSocket.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 6261402\n");
    System.setProperty("java.rmi.activation.port",
                       Integer.toString(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT));
    RMID rmid = null;
    Callback obj = null;
    try {
        /*
         * Export callback object and bind in registry.
         */
        System.err.println("export callback object and bind in registry");
        obj = new CallbackImpl();
        Callback proxy =
            (Callback) UnicastRemoteObject.exportObject(obj, 0);
        Registry registry =
            LocateRegistry.createRegistry(
                TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT);
        registry.bind("Callback", proxy);

        /*
         * Start rmid.
         */
        System.err.println("start rmid with inherited channel");
        RMID.removeLog();
        rmid = RMID.createRMID(System.out, System.err, true, true,
                               TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT);
        rmid.addOptions(new String[]{
            "-Djava.nio.channels.spi.SelectorProvider=" +
            "InheritedChannelNotServerSocket$SP"});
        rmid.start();

        /*
         * Get activation system and wait to be notified via callback
         * from rmid's selector provider.
         */
        System.err.println("get activation system");
        ActivationSystem system = ActivationGroup.getSystem();
        System.err.println("ActivationSystem = " + system);
        synchronized (lock) {
            while (!notified) {
                lock.wait();
            }
        }
        System.err.println("TEST PASSED");
    } finally {
        if (obj != null) {
            UnicastRemoteObject.unexportObject(obj, true);
        }
        ActivationLibrary.rmidCleanup(rmid);
    }
}
 
Example 11
Source File: RmidViaInheritedChannel.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.setProperty("java.rmi.activation.port",
                       Integer.toString(TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT));
    RMID rmid = null;
    Callback obj = null;

    try {
        /*
         * Export callback object and bind in registry.
         */
        System.err.println("export callback object and bind in registry");
        obj = new RmidViaInheritedChannel();
        Callback proxy = (Callback)
            UnicastRemoteObject.exportObject(obj, 0);
        Registry registry =
            LocateRegistry.createRegistry(
                TestLibrary.RMIDVIAINHERITEDCHANNEL_REGISTRY_PORT);
        registry.bind("Callback", proxy);

        /*
         * Start rmid.
         */
        System.err.println("start rmid with inherited channel");
        RMID.removeLog();
        rmid = RMID.createRMID(System.out, System.err, true, false,
                               TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT);
        rmid.addOptions(new String[]{
            "-Djava.nio.channels.spi.SelectorProvider=RmidViaInheritedChannel$RmidSelectorProvider"});
        if (System.getProperty("os.name").startsWith("Windows") &&
            System.getProperty("os.version").startsWith("5."))
        {
            /* Windows XP/2003 or older
             * Need to expand ephemeral range to include RMI test ports
             */
            rmid.addOptions(new String[]{
                "-Djdk.net.ephemeralPortRange.low=1024",
                "-Djdk.net.ephemeralPortRange.high=64000"
            });
        }
        rmid.start();

        /*
         * Get activation system and wait to be notified via callback
         * from rmid's selector provider.
         */
        System.err.println("get activation system");
        ActivationSystem system = ActivationGroup.getSystem();
        System.err.println("ActivationSystem = " + system);
        synchronized (lock) {
            while (!notified) {
                lock.wait();
            }
        }
        System.err.println("TEST PASSED");

    } finally {
        if (obj != null) {
            UnicastRemoteObject.unexportObject(obj, true);
        }
        ActivationLibrary.rmidCleanup(rmid);
    }
}
 
Example 12
Source File: MultipleRegistries.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        RemoteInterface server = null;
        RemoteInterface proxy = null;

        try {
            System.err.println("export object");
            server = new MultipleRegistries();
            proxy =
                (RemoteInterface) UnicastRemoteObject.exportObject(server, 0);

            System.err.println("proxy = " + proxy);

            System.err.println("export registries");
            Registry registryImpl1 = TestLibrary.createRegistryOnUnusedPort();
            int port1 = TestLibrary.getRegistryPort(registryImpl1);
            Registry registryImpl2 = TestLibrary.createRegistryOnUnusedPort();
            int port2 = TestLibrary.getRegistryPort(registryImpl2);
            System.err.println("bind remote object in registries");
            Registry registry1 = LocateRegistry.getRegistry(port1);
            Registry registry2 = LocateRegistry.getRegistry(port2);

            registry1.bind(NAME, proxy);
            registry2.bind(NAME, proxy);

            System.err.println("lookup remote object in registries");

            RemoteInterface remote1 = (RemoteInterface) registry1.lookup(NAME);
            RemoteInterface remote2 = (RemoteInterface) registry2.lookup(NAME);

            System.err.println("invoke methods on remote objects");
            remote1.passObject(remote1);
            remote2.passObject(remote2);

            System.err.println("TEST PASSED");

        } finally {
            if (proxy != null) {
                UnicastRemoteObject.unexportObject(server, true);
            }
        }
    }
 
Example 13
Source File: MultipleRegistries.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        RemoteInterface server = null;
        RemoteInterface proxy = null;

        try {
            System.err.println("export object");
            server = new MultipleRegistries();
            proxy =
                (RemoteInterface) UnicastRemoteObject.exportObject(server, 0);

            System.err.println("proxy = " + proxy);

            System.err.println("export registries");
            Registry registryImpl1 = TestLibrary.createRegistryOnUnusedPort();
            int port1 = TestLibrary.getRegistryPort(registryImpl1);
            Registry registryImpl2 = TestLibrary.createRegistryOnUnusedPort();
            int port2 = TestLibrary.getRegistryPort(registryImpl2);
            System.err.println("bind remote object in registries");
            Registry registry1 = LocateRegistry.getRegistry(port1);
            Registry registry2 = LocateRegistry.getRegistry(port2);

            registry1.bind(NAME, proxy);
            registry2.bind(NAME, proxy);

            System.err.println("lookup remote object in registries");

            RemoteInterface remote1 = (RemoteInterface) registry1.lookup(NAME);
            RemoteInterface remote2 = (RemoteInterface) registry2.lookup(NAME);

            System.err.println("invoke methods on remote objects");
            remote1.passObject(remote1);
            remote2.passObject(remote2);

            System.err.println("TEST PASSED");

        } finally {
            if (proxy != null) {
                UnicastRemoteObject.unexportObject(server, true);
            }
        }
    }
 
Example 14
Source File: RmidViaInheritedChannel.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.setProperty("java.rmi.activation.port",
                       Integer.toString(TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT));
    RMID rmid = null;
    Callback obj = null;

    try {
        /*
         * Export callback object and bind in registry.
         */
        System.err.println("export callback object and bind in registry");
        obj = new RmidViaInheritedChannel();
        Callback proxy = (Callback)
            UnicastRemoteObject.exportObject(obj, 0);
        Registry registry =
            LocateRegistry.createRegistry(
                TestLibrary.RMIDVIAINHERITEDCHANNEL_REGISTRY_PORT);
        registry.bind("Callback", proxy);

        /*
         * Start rmid.
         */
        System.err.println("start rmid with inherited channel");
        RMID.removeLog();
        rmid = RMID.createRMID(System.out, System.err, true, false,
                               TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT);
        rmid.addOptions(new String[]{
            "-Djava.nio.channels.spi.SelectorProvider=RmidViaInheritedChannel$RmidSelectorProvider"});
        if (System.getProperty("os.name").startsWith("Windows") &&
            System.getProperty("os.version").startsWith("5."))
        {
            /* Windows XP/2003 or older
             * Need to expand ephemeral range to include RMI test ports
             */
            rmid.addOptions(new String[]{
                "-Djdk.net.ephemeralPortRange.low=1024",
                "-Djdk.net.ephemeralPortRange.high=64000"
            });
        }
        rmid.start();

        /*
         * Get activation system and wait to be notified via callback
         * from rmid's selector provider.
         */
        System.err.println("get activation system");
        ActivationSystem system = ActivationGroup.getSystem();
        System.err.println("ActivationSystem = " + system);
        synchronized (lock) {
            while (!notified) {
                lock.wait();
            }
        }
        System.err.println("TEST PASSED");

    } finally {
        if (obj != null) {
            UnicastRemoteObject.unexportObject(obj, true);
        }
        ActivationLibrary.rmidCleanup(rmid);
    }
}
 
Example 15
Source File: InheritedChannelNotServerSocket.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 6261402\n");
    System.setProperty("java.rmi.activation.port",
                       Integer.toString(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT));
    RMID rmid = null;
    Callback obj = null;
    try {
        /*
         * Export callback object and bind in registry.
         */
        System.err.println("export callback object and bind in registry");
        obj = new CallbackImpl();
        Callback proxy =
            (Callback) UnicastRemoteObject.exportObject(obj, 0);
        Registry registry =
            LocateRegistry.createRegistry(
                TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT);
        registry.bind("Callback", proxy);

        /*
         * Start rmid.
         */
        System.err.println("start rmid with inherited channel");
        RMID.removeLog();
        rmid = RMID.createRMID(System.out, System.err, true, true,
                               TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT);
        rmid.addOptions(new String[]{
            "-Djava.nio.channels.spi.SelectorProvider=" +
            "InheritedChannelNotServerSocket$SP"});
        rmid.start();

        /*
         * Get activation system and wait to be notified via callback
         * from rmid's selector provider.
         */
        System.err.println("get activation system");
        ActivationSystem system = ActivationGroup.getSystem();
        System.err.println("ActivationSystem = " + system);
        synchronized (lock) {
            while (!notified) {
                lock.wait();
            }
        }
        System.err.println("TEST PASSED");
    } finally {
        if (obj != null) {
            UnicastRemoteObject.unexportObject(obj, true);
        }
        ActivationLibrary.rmidCleanup(rmid);
    }
}
 
Example 16
Source File: MultipleRegistries.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        RemoteInterface server = null;
        RemoteInterface proxy = null;

        try {
            System.err.println("export object");
            server = new MultipleRegistries();
            proxy =
                (RemoteInterface) UnicastRemoteObject.exportObject(server, 0);

            System.err.println("proxy = " + proxy);

            System.err.println("export registries");
            Registry registryImpl1 = TestLibrary.createRegistryOnUnusedPort();
            int port1 = TestLibrary.getRegistryPort(registryImpl1);
            Registry registryImpl2 = TestLibrary.createRegistryOnUnusedPort();
            int port2 = TestLibrary.getRegistryPort(registryImpl2);
            System.err.println("bind remote object in registries");
            Registry registry1 = LocateRegistry.getRegistry(port1);
            Registry registry2 = LocateRegistry.getRegistry(port2);

            registry1.bind(NAME, proxy);
            registry2.bind(NAME, proxy);

            System.err.println("lookup remote object in registries");

            RemoteInterface remote1 = (RemoteInterface) registry1.lookup(NAME);
            RemoteInterface remote2 = (RemoteInterface) registry2.lookup(NAME);

            System.err.println("invoke methods on remote objects");
            remote1.passObject(remote1);
            remote2.passObject(remote2);

            System.err.println("TEST PASSED");

        } finally {
            if (proxy != null) {
                UnicastRemoteObject.unexportObject(server, true);
            }
        }
    }
 
Example 17
Source File: RmidViaInheritedChannel.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.setProperty("java.rmi.activation.port",
                       Integer.toString(TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT));
    RMID rmid = null;
    Callback obj = null;

    try {
        /*
         * Export callback object and bind in registry.
         */
        System.err.println("export callback object and bind in registry");
        obj = new RmidViaInheritedChannel();
        Callback proxy = (Callback)
            UnicastRemoteObject.exportObject(obj, 0);
        Registry registry =
            LocateRegistry.createRegistry(
                TestLibrary.RMIDVIAINHERITEDCHANNEL_REGISTRY_PORT);
        registry.bind("Callback", proxy);

        /*
         * Start rmid.
         */
        System.err.println("start rmid with inherited channel");
        RMID.removeLog();
        rmid = RMID.createRMID(System.out, System.err, true, false,
                               TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT);
        rmid.addOptions(new String[]{
            "-Djava.nio.channels.spi.SelectorProvider=RmidViaInheritedChannel$RmidSelectorProvider"});
        if (System.getProperty("os.name").startsWith("Windows") &&
            System.getProperty("os.version").startsWith("5."))
        {
            /* Windows XP/2003 or older
             * Need to expand ephemeral range to include RMI test ports
             */
            rmid.addOptions(new String[]{
                "-Djdk.net.ephemeralPortRange.low=1024",
                "-Djdk.net.ephemeralPortRange.high=64000"
            });
        }
        rmid.start();

        /*
         * Get activation system and wait to be notified via callback
         * from rmid's selector provider.
         */
        System.err.println("get activation system");
        ActivationSystem system = ActivationGroup.getSystem();
        System.err.println("ActivationSystem = " + system);
        synchronized (lock) {
            while (!notified) {
                lock.wait();
            }
        }
        System.err.println("TEST PASSED");

    } finally {
        if (obj != null) {
            UnicastRemoteObject.unexportObject(obj, true);
        }
        ActivationLibrary.rmidCleanup(rmid);
    }
}
 
Example 18
Source File: MultipleRegistries.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        RemoteInterface server = null;
        RemoteInterface proxy = null;

        try {
            System.err.println("export object");
            server = new MultipleRegistries();
            proxy =
                (RemoteInterface) UnicastRemoteObject.exportObject(server, 0);

            System.err.println("proxy = " + proxy);

            System.err.println("export registries");
            Registry registryImpl1 = TestLibrary.createRegistryOnUnusedPort();
            int port1 = TestLibrary.getRegistryPort(registryImpl1);
            Registry registryImpl2 = TestLibrary.createRegistryOnUnusedPort();
            int port2 = TestLibrary.getRegistryPort(registryImpl2);
            System.err.println("bind remote object in registries");
            Registry registry1 = LocateRegistry.getRegistry(port1);
            Registry registry2 = LocateRegistry.getRegistry(port2);

            registry1.bind(NAME, proxy);
            registry2.bind(NAME, proxy);

            System.err.println("lookup remote object in registries");

            RemoteInterface remote1 = (RemoteInterface) registry1.lookup(NAME);
            RemoteInterface remote2 = (RemoteInterface) registry2.lookup(NAME);

            System.err.println("invoke methods on remote objects");
            remote1.passObject(remote1);
            remote2.passObject(remote2);

            System.err.println("TEST PASSED");

        } finally {
            if (proxy != null) {
                UnicastRemoteObject.unexportObject(server, true);
            }
        }
    }
 
Example 19
Source File: CacheServerLauncherJUnitTest.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testRebalance() throws Exception {
  String testName = "testRebalance";

  this.cacheserverDirName = "CacheServerLauncherJUnitTest_"+testName;
  String logName = testName+".log";
  String cacheXmlName = testName+".xml";

  Registry registry = LocateRegistry.createRegistry(controllerNamingPort);
  RebalanceStatus status = new RebalanceStatus();
  registry.bind(REBALANCE_STATUS_BINDING, status);
  try {

    File dir = new File(this.cacheserverDirName);
    dir.mkdir();

    createCacheXml(dir, cacheXmlName, serverPort, true);

    // connect local member and create PR...
    Properties props = new Properties();
    props.setProperty(DistributionConfig.MCAST_PORT_NAME, ""+mcastPort);
    DistributedSystem system = DistributedSystem.connect(props);
    Cache cache = CacheFactory.create(system);
    AttributesFactory factory = new AttributesFactory();
    factory.setPartitionAttributes(new PartitionAttributesFactory()
        //.setLocalMaxMemory(localMaxMemory)
        //.setTotalNumBuckets(numBuckets)
        //.setRedundantCopies(redundantCopies)
        //.setColocatedWith(colocatedWith)
        .create());

    RegionAttributes attrs = factory.create();
    Region pr = cache.createRegion("PartitionedRegion", attrs);

    // create 6 different buckets...
    int createdBuckets = 6;
    for (int i = 0; i < createdBuckets; i++) {
      pr.put(Integer.valueOf(i), Integer.valueOf(i));
    }

    // assert that there are 6 local buckets
    PartitionedRegionDataStore dataStore
        = ((PartitionedRegion)pr).getDataStore();
    assertEquals(createdBuckets, dataStore.getBucketsManaged());

    execAndValidate(new String[] {
        "start",
        "-J-D"+CONTROLLER_NAMING_PORT_PROP+"="+controllerNamingPort,
        "-J-D"+CACHESERVER_NAMING_PORT_PROP+"="+cacheserverNamingPort,
        "-J-Xmx"+Runtime.getRuntime().maxMemory(),
        "mcast-port="+mcastPort,
        "log-file="+logName,
        "cache-xml-file="+cacheXmlName,
        "-dir="+this.cacheserverDirName,
        "-classpath="+JTESTS,
        "-rebalance"
        },
        "CacheServer pid: \\d+ status: running");

    assertTrue(status.waitForRebalancingToStart(10*1000));

    assertTrue(status.waitForRebalancingToFinish(10*1000));

    // assert that there are 3 local buckets AFTER the rebalance
    assertEquals(createdBuckets/2, dataStore.getBucketsManaged());

    execAndValidate(new String[] { "status", "-dir="+dir },
        "CacheServer pid: \\d+ status: running");

    execAndValidate(new String[] { "stop", "-dir="+dir },
        ".*The CacheServer has stopped\\.");

  } finally {
    UnicastRemoteObject.unexportObject(status, true);
    UnicastRemoteObject.unexportObject(registry, true);
  }
}