test/sun/rmi/rmic/newrmic/equivalence/AppleUserImpl.java

Print this page




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.rmi.RemoteException;
  25 import java.rmi.Naming;
  26 import java.rmi.server.UnicastRemoteObject;
  27 import java.rmi.registry.LocateRegistry;

  28 import java.util.Random;
  29 import java.util.ArrayList;
  30 import java.util.Date;
  31 import java.util.logging.Logger;
  32 import java.util.logging.Level;
  33 
  34 /**
  35  * The AppleUserImpl class implements the behavior of the remote
  36  * "apple user" objects exported by the server.  The application server
  37  * passes each of its remote "apple" objects to an apple user, and an
  38  * AppleUserThread is created for each apple.
  39  */
  40 public class AppleUserImpl
  41     extends UnicastRemoteObject
  42     implements AppleUser
  43 {
  44     private static Logger logger = Logger.getLogger("reliability.appleuser");
  45     private static int threadNum = 0;
  46     private static long testDuration = 0;
  47     private static int maxLevel = 7;


 234                     usage();
 235                 }
 236             }
 237             if (durationString == null) {
 238                 durationString = testDuration + " milliseconds";
 239             }
 240         } catch (Throwable t) {
 241             usage();
 242         }
 243 
 244         AppleUserImpl user = null;
 245         try {
 246             user = new AppleUserImpl();
 247         } catch (RemoteException e) {
 248             //TestLibrary.bomb("Failed to create AppleUser", e);
 249         }
 250 
 251         synchronized (user) {
 252             // create new registry and bind new AppleUserImpl in registry
 253             try {
 254                 LocateRegistry.createRegistry(1099); //TestLibrary.REGISTRY_PORT);
 255                 Naming.rebind("rmi://localhost:1099/AppleUser",user);
 256                               //TestLibrary.REGISTRY_PORT + "/AppleUser", user);
 257             } catch (RemoteException e) {
 258                 //TestLibrary.bomb("Failed to bind AppleUser", e);
 259             } catch (java.net.MalformedURLException e) {
 260                 //TestLibrary.bomb("Failed to bind AppleUser", e);
 261             }
 262 
 263             // start the other server if available
 264             try {
 265                 Class app = Class.forName("ApplicationServer");
 266                 server = new Thread((Runnable) app.newInstance());
 267                 logger.log(Level.INFO, "Starting application server " +
 268                     "in same process");
 269                 server.start();
 270             } catch (ClassNotFoundException e) {
 271                 // assume the other server is running in a separate process
 272                 logger.log(Level.INFO, "Application server must be " +
 273                     "started in separate process");
 274             } catch (Exception ie) {
 275                 //TestLibrary.bomb("Could not instantiate server", ie);
 276             }




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.rmi.RemoteException;
  25 import java.rmi.Naming;
  26 import java.rmi.server.UnicastRemoteObject;
  27 import java.rmi.registry.LocateRegistry;
  28 import java.rmi.registry.Registry;
  29 import java.util.Random;
  30 import java.util.ArrayList;
  31 import java.util.Date;
  32 import java.util.logging.Logger;
  33 import java.util.logging.Level;
  34 
  35 /**
  36  * The AppleUserImpl class implements the behavior of the remote
  37  * "apple user" objects exported by the server.  The application server
  38  * passes each of its remote "apple" objects to an apple user, and an
  39  * AppleUserThread is created for each apple.
  40  */
  41 public class AppleUserImpl
  42     extends UnicastRemoteObject
  43     implements AppleUser
  44 {
  45     private static Logger logger = Logger.getLogger("reliability.appleuser");
  46     private static int threadNum = 0;
  47     private static long testDuration = 0;
  48     private static int maxLevel = 7;


 235                     usage();
 236                 }
 237             }
 238             if (durationString == null) {
 239                 durationString = testDuration + " milliseconds";
 240             }
 241         } catch (Throwable t) {
 242             usage();
 243         }
 244 
 245         AppleUserImpl user = null;
 246         try {
 247             user = new AppleUserImpl();
 248         } catch (RemoteException e) {
 249             //TestLibrary.bomb("Failed to create AppleUser", e);
 250         }
 251 
 252         synchronized (user) {
 253             // create new registry and bind new AppleUserImpl in registry
 254             try {
 255                 Registry registry = TestLibrary.createRegistryOnUnusedPort();
 256                 int port = TestLibrary.getRegistryPort(registry);
 257                 Naming.rebind("rmi://localhost:" + port + "/AppleUser",user);
 258             } catch (RemoteException e) {
 259                 //TestLibrary.bomb("Failed to bind AppleUser", e);
 260             } catch (java.net.MalformedURLException e) {
 261                 //TestLibrary.bomb("Failed to bind AppleUser", e);
 262             }
 263 
 264             // start the other server if available
 265             try {
 266                 Class app = Class.forName("ApplicationServer");
 267                 server = new Thread((Runnable) app.newInstance());
 268                 logger.log(Level.INFO, "Starting application server " +
 269                     "in same process");
 270                 server.start();
 271             } catch (ClassNotFoundException e) {
 272                 // assume the other server is running in a separate process
 273                 logger.log(Level.INFO, "Application server must be " +
 274                     "started in separate process");
 275             } catch (Exception ie) {
 276                 //TestLibrary.bomb("Could not instantiate server", ie);
 277             }