You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by pe...@apache.org on 2012/01/21 08:28:36 UTC
svn commit: r1234278 [12/29] - in /river/tck: ./ configs/ doc/ doc/api/
doc/api/com/ doc/api/com/sun/ doc/api/com/sun/jini/
doc/api/com/sun/jini/compat/ doc/api/com/sun/jini/compat/admin1/
doc/api/com/sun/jini/compat/admin2/ doc/api/com/sun/jini/compat...
Added: river/tck/src/com/sun/jini/compat/admin1/MahaloAdmin.java
URL: http://svn.apache.org/viewvc/river/tck/src/com/sun/jini/compat/admin1/MahaloAdmin.java?rev=1234278&view=auto
==============================================================================
--- river/tck/src/com/sun/jini/compat/admin1/MahaloAdmin.java (added)
+++ river/tck/src/com/sun/jini/compat/admin1/MahaloAdmin.java Sat Jan 21 07:28:27 2012
@@ -0,0 +1,251 @@
+/*
+ *
+ * Copyright 2005 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.sun.jini.compat.admin1;
+
+import java.rmi.RemoteException;
+import java.rmi.UnmarshalException;
+import java.rmi.server.RMIClassLoader;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import java.io.IOException;
+import java.io.File;
+import java.io.PrintWriter;
+
+import com.sun.jini.compat.harness.SysConfig;
+import com.sun.jini.compat.harness.Config;
+import com.sun.jini.compat.harness.BasicServiceAdmin;
+import com.sun.jini.admin.DestroyAdmin;
+import com.sun.jini.start.ServiceStarter;
+
+import net.jini.core.lookup.ServiceItem;
+import net.jini.core.lookup.ServiceTemplate;
+import net.jini.core.lookup.ServiceID;
+import net.jini.core.transaction.server.TransactionManager;
+
+import net.jini.admin.Administrable;
+import net.jini.admin.JoinAdmin;
+
+/**
+ * This class implements the BasicServiceAdmin interface to automate
+ * the testing of the Mahalo Transaction Manager service from the
+ * Jini(TM) Technology Software Kit (JSK).
+ */
+public class MahaloAdmin implements BasicServiceAdmin {
+
+ private String codebaseString = null;
+ private SysConfig sysConfig = null;
+ private TransactionManager tManager = null;
+ private Config conf;
+ private final static String proxyClassName =
+ "com.sun.jini.mahalo.TxnManagerImpl_Stub";
+
+ /**
+ * Default Constructor with no arguments.
+ */
+ public MahaloAdmin() {
+ }
+
+ /**
+ * Constructor that takes in the codebase for the Mahalo
+ * implementation that is being tested.
+ */
+ public MahaloAdmin(String codebase) {
+ codebaseString = codebase;
+ }
+
+ /**
+ * Takes the Config object for this test run so that the implementation
+ * can get access to property files and and other config information.
+ *
+ * @param conf the Config object for this test run
+ */
+ public void setConfig(Config conf) {
+ this.conf = conf;
+ }
+
+ /**
+ * Properly configures and starts Mahalo. This method sets the
+ * codebase, classpath, policy and log directory for Mahalo. It
+ * then starts Mahalo in a separate VM and using remote administration
+ * configures Mahalo to register in the public group.
+ */
+ public synchronized void start() throws RemoteException {
+ sysConfig = conf.getSysConfig();
+
+ String classpath = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.mahalo.classpath",
+ null);
+ String codebase = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.mahalo.codebase",
+ codebaseString);
+ String policy = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.mahalo.policy",
+ null);
+ String dbdir = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.mahalo.outputDir",
+ "testMahaloDir");
+
+ if (classpath == null || codebase == null || policy == null)
+ throw new RemoteException("Environment Failure: The lookup "+
+ "classpath, codebase and policy "+
+ "must be set by property or commandline");
+
+ try {
+ File dir = new File(dbdir);
+ if(!dir.exists()) {
+ dir.mkdir();
+ }
+ File f = File.createTempFile("TestMahalo", null, dir);
+ String fName = f.getAbsolutePath();
+ f.delete();
+
+ /* Need to set the system property java.class.path
+ * here for it to be set right for mahalo */
+ String oldClasspath = System.getProperty("java.class.path", null);
+ System.setProperty("java.class.path", classpath);
+
+ /* Start the mahalo service implementation that resides in the
+ * package 'com.sun.jini.mahalo' */
+ ServiceStarter.Created c =
+ ServiceStarter.create(codebase, policy, fName,
+ new String[] {""}, // public group
+ null, // locators
+ "com.sun.jini.mahalo.StartMahalo",
+ "com.sun.jini.mahalo.TxnManagerImpl",
+ classpath,
+ "service");
+ tManager = (TransactionManager) (c.proxy);
+
+ //reset the class path
+ System.setProperty("java.class.path", oldClasspath);
+
+ if (conf.getDebugLevel() == Config.ALL) {
+ PrintWriter log = conf.getLog();
+ if (log != null) {
+ log.println("Admin: using MahaloAdmin");
+ log.println("Admin: Mahalo proxy is "
+ + tManager.getClass().getName());
+ log.println("Admin: Mahalo codebase is " + codebase);
+ log.println("Admin: Mahalo classpath is " + classpath);
+ }
+ }
+
+ codebaseString = codebase;
+
+ } catch (Exception e) {
+ throw new RemoteException("Exception while starting Mahalo",e);
+ }
+ }
+
+ /**
+ * Given a list of objects which are ServiceItems this method
+ * determines if any of them are the Mahalo we are testing. It
+ * does this by comparing the class name and the codebase of the
+ * object to the codebase and class name we are looking for. If
+ * they match it returns the matching ServiceItem; otherwise
+ * it returns null.
+ *
+ * @param services the array of ServiceItems that need to be picked from
+ *
+ * @return the ServiceItem for the Mahalo service being tested or null
+ */
+ public synchronized ServiceItem pickService(ServiceItem[] services)
+ throws RemoteException
+ {
+ PrintWriter log = null;
+ if (conf.getDebugLevel() == Config.ALL) {
+ log = conf.getLog();
+ }
+ if (log != null) {
+ log.println("Admin: pickService looking for class "
+ + proxyClassName);
+ log.println(" with codebase " + codebaseString);
+ }
+
+ for(int i = 0; i < services.length; i++) {
+ Object si = services[i].service;
+ String sCodebase = RMIClassLoader.getClassAnnotation(si.getClass());
+
+ if (log != null) {
+ log.println("Admin: pickService found class "
+ + si.getClass().getName());
+ log.println(" with codebase " + sCodebase);
+ }
+
+ if (si.getClass().getName().equals(proxyClassName) &&
+ sCodebase.equals(codebaseString))
+ {
+ return services[i];
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the address of the machine that the Mahalo process is
+ * running on.
+ *
+ * @return the address
+ */
+ public InetAddress getAddress() throws RemoteException {
+ InetAddress ia = null;
+
+ try {
+ ia = InetAddress.getLocalHost();
+ } catch (UnknownHostException uhe) {
+ throw new RemoteException("Couldn't get local host", uhe);
+ }
+ return ia;
+ }
+
+ /**
+ * Provides a service template with the Mahalo's ServiceID to
+ * filter out uninteresting services.
+ *
+ * @return the template
+ */
+ public ServiceTemplate getTemplate() throws RemoteException {
+ return new ServiceTemplate(
+ null,
+ new Class[] { TransactionManager.class },
+ null);
+ }
+
+ /**
+ * Stops the Mahalo service, removes it from activation and removes it's
+ * log directory using remote administration.
+ */
+ public synchronized void stop() throws RemoteException {
+ DestroyAdmin da = (DestroyAdmin) ((Administrable)tManager).getAdmin();
+ try {
+ da.destroy();
+ } catch (UnmarshalException ue) {
+ if (conf.getDebugLevel() == Config.ERROR) {
+ PrintWriter log = conf.getLog();
+ if (log != null) {
+ log.println("Admin: the following exception is allowed:");
+ ue.printStackTrace(log);
+ }
+ }
+ }
+ }
+}
Propchange: river/tck/src/com/sun/jini/compat/admin1/MahaloAdmin.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/tck/src/com/sun/jini/compat/admin1/MercuryAdmin.java
URL: http://svn.apache.org/viewvc/river/tck/src/com/sun/jini/compat/admin1/MercuryAdmin.java?rev=1234278&view=auto
==============================================================================
--- river/tck/src/com/sun/jini/compat/admin1/MercuryAdmin.java (added)
+++ river/tck/src/com/sun/jini/compat/admin1/MercuryAdmin.java Sat Jan 21 07:28:27 2012
@@ -0,0 +1,252 @@
+/*
+ *
+ * Copyright 2005 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.sun.jini.compat.admin1;
+
+import java.rmi.RemoteException;
+import java.rmi.activation.ActivationException;
+import java.rmi.server.RMIClassLoader;
+
+import java.io.IOException;
+import java.io.File;
+import java.io.PrintWriter;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import com.sun.jini.compat.harness.SysConfig;
+import com.sun.jini.compat.harness.Config;
+import com.sun.jini.compat.harness.BasicServiceAdmin;
+import com.sun.jini.admin.DestroyAdmin;
+import com.sun.jini.start.ServiceStarter;
+import com.sun.jini.start.ServiceDestroyer;
+
+import net.jini.core.lookup.ServiceItem;
+import net.jini.core.lookup.ServiceTemplate;
+import net.jini.core.lookup.ServiceID;
+import net.jini.event.EventMailbox;
+
+
+/**
+ * This class implements the BasicServiceAdmin interface to automate
+ * the testing of the Mercury service from the Jini(TM) Technology Helper Services.
+ */
+public class MercuryAdmin implements BasicServiceAdmin {
+
+ private String codebaseString = null;
+ private SysConfig sysConfig = null;
+ private EventMailbox eventMailbox;
+ private Config conf;
+ private ServiceStarter.Created created = null;
+ private final static String proxyClassName =
+ "com.sun.jini.mercury.MailboxProxy";
+
+ /**
+ * Default Constructor with no arguments.
+ */
+ public MercuryAdmin() {
+ }
+
+ /**
+ * Constructor that takes in the codebase for the Mercury
+ * implementation that is being tested.
+ */
+ public MercuryAdmin(String codebase) {
+ codebaseString = codebase;
+ }
+
+ /**
+ * Takes the Config object for this test run so that the implementation
+ * can get access to property files and other config information.
+ *
+ * @param conf the Config object for this test run
+ */
+ public void setConfig(Config conf) {
+ this.conf = conf;
+ }
+
+ /**
+ * Properly configures and starts Mercury. This method sets the
+ * codebase, classpath, policy and log directory for Mercury. It
+ * then starts Mercury in a separate VM and using remote administration
+ * configures Mercury to register in the public group.
+ */
+ public synchronized void start() throws RemoteException {
+ sysConfig = conf.getSysConfig();
+
+ String classpath = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.mercury.classpath",
+ null);
+ String codebase = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.mercury.codebase",
+ codebaseString);
+ String policy = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.mercury.policy",
+ null);
+ String dbdir = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.mercury.outputDir",
+ "testMercuryDir");
+
+ if (classpath == null || codebase == null || policy == null)
+ throw new RemoteException("Environment Failure: The lookup "+
+ "classpath, codebase and policy "+
+ "must be set by property or commandline");
+
+ try {
+ File dir = new File(dbdir);
+ if (!dir.exists()) {
+ dir.mkdir();
+ }
+ File f = File.createTempFile("TestMercury", null, dir);
+ String fName = f.getAbsolutePath();
+ f.delete();
+
+ /* Need to set the system property java.class.path
+ * here for it to be set right for Mercury */
+ String oldClasspath = System.getProperty("java.class.path", null);
+ System.setProperty("java.class.path", classpath);
+
+ /* Start the mercury service implementation that resides in the
+ * package 'com.sun.jini.mercury' */
+ created = ServiceStarter.create(codebase, policy, fName,
+ new String[] {""}, // public group
+ null, // locators
+ "com.sun.jini.mercury.StartMercury",
+ "com.sun.jini.mercury.MailboxImpl",
+ classpath,
+ "service");
+ eventMailbox = (EventMailbox) (created.proxy);
+
+ //reset the class path
+ System.setProperty("java.class.path", oldClasspath);
+
+ if (conf.getDebugLevel() == Config.ALL) {
+ PrintWriter log = conf.getLog();
+ if (log != null) {
+ log.println("Admin: using MercuryAdmin");
+ log.println("Admin: Mercury proxy is "
+ + eventMailbox.getClass().getName());
+ log.println("Admin: Mercury codebase is " + codebase);
+ log.println("Admin: Mercury classpath is " + classpath);
+ }
+ }
+
+ codebaseString = codebase;
+
+ } catch (Exception e) {
+ throw new RemoteException("Exception while starting Mercury",e);
+ }
+ }
+
+ /**
+ * Given a list of objects which are ServiceItems this method
+ * determines if any of them are the Mercury we are testing. It
+ * does this by comparing the class name and the codebase of the
+ * object to the codebase and class name we are looking for. If
+ * they match it returns the matching ServiceItem; otherwise
+ * it returns null.
+ *
+ * @param services the array of ServiceItems that need to be picked from
+ *
+ * @return the ServiceItem for the Mercury service being tested or null
+ */
+ public synchronized ServiceItem pickService(ServiceItem[] services)
+ throws RemoteException
+ {
+ PrintWriter log = null;
+ if (conf.getDebugLevel() == Config.ALL) {
+ log = conf.getLog();
+ }
+ if (log != null) {
+ log.println("Admin: pickService looking for class "
+ + proxyClassName);
+ log.println(" with codebase " + codebaseString);
+ }
+
+ for (int i = 0; i < services.length; i++) {
+ Object si = services[i].service;
+ String sCodebase = RMIClassLoader.getClassAnnotation(si.getClass());
+
+ if (log != null) {
+ log.println("Admin: pickService found class "
+ + si.getClass().getName());
+ log.println(" with codebase " + sCodebase);
+ }
+
+ if (si.getClass().getName().equals(proxyClassName) &&
+ sCodebase.equals(codebaseString))
+ {
+ return services[i];
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the address of the machine that the Mercury process is
+ * running on.
+ *
+ * @return the address
+ */
+ public InetAddress getAddress() throws RemoteException {
+ InetAddress ia = null;
+
+ try {
+ ia = InetAddress.getLocalHost();
+ } catch (UnknownHostException uhe) {
+ throw new RemoteException("Couldn't get local host", uhe);
+ }
+ return ia;
+ }
+
+ /**
+ * Provides a service template with the Mercury's ServiceID to
+ * filter out uninteresting services.
+ *
+ * @return the template
+ */
+ public ServiceTemplate getTemplate() throws RemoteException {
+ return new ServiceTemplate(
+ null,
+ new Class[] { EventMailbox.class },
+ null);
+ }
+
+ /**
+ * Stops the Mercury service, removes it from activation and removes it's
+ * log directory using remote administration.
+ */
+ public synchronized void stop() throws RemoteException {
+ /* this method will make certain the service is unregistered with
+ * activation before returning. This is necessary because asynchronous
+ * destroyAdmins can leave services running and generate spurious
+ * multicast request packets. */
+ try {
+ ServiceDestroyer.destroy(created);
+ } catch (ActivationException ae) {
+ if (conf.getDebugLevel() == Config.ERROR) {
+ PrintWriter log = conf.getLog();
+ if (log != null) {
+ log.println("Warning: Mercury did not shutdown cleanly");
+ ae.printStackTrace(log);
+ }
+ }
+ }
+ }
+}
Propchange: river/tck/src/com/sun/jini/compat/admin1/MercuryAdmin.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/tck/src/com/sun/jini/compat/admin1/NormAdmin.java
URL: http://svn.apache.org/viewvc/river/tck/src/com/sun/jini/compat/admin1/NormAdmin.java?rev=1234278&view=auto
==============================================================================
--- river/tck/src/com/sun/jini/compat/admin1/NormAdmin.java (added)
+++ river/tck/src/com/sun/jini/compat/admin1/NormAdmin.java Sat Jan 21 07:28:27 2012
@@ -0,0 +1,250 @@
+/*
+ *
+ * Copyright 2005 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.sun.jini.compat.admin1;
+
+import java.rmi.RemoteException;
+import java.rmi.UnmarshalException;
+import java.rmi.server.RMIClassLoader;
+
+import java.io.IOException;
+import java.io.File;
+import java.io.PrintWriter;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import com.sun.jini.compat.harness.SysConfig;
+import com.sun.jini.compat.harness.Config;
+import com.sun.jini.compat.harness.BasicServiceAdmin;
+import com.sun.jini.admin.DestroyAdmin;
+import com.sun.jini.start.ServiceStarter;
+
+import net.jini.admin.Administrable;
+import net.jini.admin.JoinAdmin;
+import net.jini.core.lookup.ServiceItem;
+import net.jini.core.lookup.ServiceTemplate;
+import net.jini.core.lookup.ServiceID;
+import net.jini.lease.LeaseRenewalService;
+
+/**
+ * This class implements the BasicServiceAdmin interface to automate
+ * the testing of the Norm service from the Jini(TM) Technology Helper Services.
+ */
+public class NormAdmin implements BasicServiceAdmin {
+
+ private String codebaseString = null;
+ private SysConfig sysConfig = null;
+ private LeaseRenewalService lrs;
+ private Config conf;
+ private final static String proxyClassName =
+ "com.sun.jini.norm.NormServerImpl_Stub";
+
+ /**
+ * Default Constructor with no arguments.
+ */
+ public NormAdmin() {
+ }
+
+ /**
+ * Constructor that takes in the codebase for the Norm
+ * implementation that is being tested.
+ */
+ public NormAdmin(String codebase) {
+ codebaseString = codebase;
+ }
+
+ /**
+ * Takes the Config object for this test run so that the implementation
+ * can get access to property files and other config information.
+ *
+ * @param conf the Config object for this test run
+ */
+ public void setConfig(Config conf) {
+ this.conf = conf;
+ }
+
+ /**
+ * Properly configures and starts Norm. This method sets the
+ * codebase, classpath, policy and log directory for Norm. It
+ * then starts Norm in a separate VM and using remote administration
+ * configures Norm to register in the public group.
+ */
+ public synchronized void start() throws RemoteException {
+ sysConfig = conf.getSysConfig();
+
+ String classpath = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.norm.classpath",
+ null);
+ String codebase = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.norm.codebase",
+ codebaseString);
+ String policy = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.norm.policy",
+ null);
+ String dbdir = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.norm.outputDir",
+ "testNormDir");
+
+ if (classpath == null || codebase == null || policy == null)
+ throw new RemoteException("Environment Failure: The lookup "+
+ "classpath, codebase and policy "+
+ "must be set by property or commandline");
+
+ try {
+ File dir = new File(dbdir);
+ if (!dir.exists()) {
+ dir.mkdir();
+ }
+ File f = File.createTempFile("TestNorm", null, dir);
+ String fName = f.getAbsolutePath();
+ f.delete();
+
+ /* Need to set the system property java.class.path
+ * here for it to be set right for Norm */
+ String oldClasspath = System.getProperty("java.class.path", null);
+ System.setProperty("java.class.path", classpath);
+
+ /* Start the Norm service implementation that resides in the
+ * package 'com.sun.jini.norm' */
+ ServiceStarter.Created c =
+ ServiceStarter.create(codebase, policy, fName,
+ new String[] {""}, // public group
+ null, // locators
+ "com.sun.jini.norm.StartNorm",
+ "com.sun.jini.norm.NormServerImpl",
+ classpath,
+ "service");
+ lrs = (LeaseRenewalService) (c.proxy);
+
+ //reset the class path
+ System.setProperty("java.class.path", oldClasspath);
+
+ if (conf.getDebugLevel() == Config.ALL) {
+ PrintWriter log = conf.getLog();
+ if (log != null) {
+ log.println("Admin: using NormAdmin");
+ log.println("Admin: Norm proxy is "
+ + lrs.getClass().getName());
+ log.println("Admin: Norm codebase is " + codebase);
+ log.println("Admin: Norm classpath is " + classpath);
+ }
+ }
+
+ codebaseString = new String(codebase);
+
+ } catch (Exception e) {
+ throw new RemoteException("Exception while starting Norm",e);
+ }
+ }
+
+ /**
+ * Given a list of objects which are ServiceItems this method
+ * determines if any of them are the Norm we are testing. It
+ * does this by comparing the class name and the codebase of the
+ * object to the codebase and class name we are looking for. If
+ * they match it returns the matching ServiceItem; otherwise
+ * it returns null.
+ *
+ * @param services the array of ServiceItems that need to be picked from
+ *
+ * @return the ServiceItem for the Norm service being tested or null
+ */
+ public synchronized ServiceItem pickService(ServiceItem[] services)
+ throws RemoteException
+ {
+ PrintWriter log = null;
+ if (conf.getDebugLevel() == Config.ALL) {
+ log = conf.getLog();
+ }
+ if (log != null) {
+ log.println("Admin: pickService looking for class "
+ + proxyClassName);
+ log.println(" with codebase " + codebaseString);
+ }
+
+ for (int i = 0; i < services.length; i++) {
+ Object si = services[i].service;
+ String sCodebase = RMIClassLoader.getClassAnnotation(si.getClass());
+
+ if (log != null) {
+ log.println("Admin: pickService found class "
+ + si.getClass().getName());
+ log.println(" with codebase " + sCodebase);
+ }
+
+ if (si.getClass().getName().equals(proxyClassName) &&
+ sCodebase.equals(codebaseString))
+ {
+ return services[i];
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the address of the machine that the Norm process is
+ * running on.
+ *
+ * @return the address
+ */
+ public InetAddress getAddress() throws RemoteException {
+ InetAddress ia = null;
+
+ try {
+ ia = InetAddress.getLocalHost();
+ } catch (UnknownHostException uhe) {
+ throw new RemoteException("Couldn't get local host", uhe);
+ }
+ return ia;
+ }
+
+ /**
+ * Provides a service template with the Norm's ServiceID to
+ * filter out uninteresting services.
+ *
+ * @return the template
+ */
+ public ServiceTemplate getTemplate() throws RemoteException {
+ return new ServiceTemplate(
+ null,
+ new Class[] { LeaseRenewalService.class },
+ null);
+ }
+
+ /**
+ * Stops the Norm service, removes it from activation and removes it's
+ * log directory using remote administration.
+ */
+ public synchronized void stop() throws RemoteException {
+ DestroyAdmin da = (DestroyAdmin) ((Administrable) lrs).getAdmin();
+ try {
+ da.destroy();
+ } catch (UnmarshalException ue) {
+ if (conf.getDebugLevel() == Config.ERROR) {
+ PrintWriter log = conf.getLog();
+ if (log != null) {
+ log.println("Admin: the following exception is allowed:");
+ ue.printStackTrace(log);
+ }
+ }
+ }
+ }
+}
+
Propchange: river/tck/src/com/sun/jini/compat/admin1/NormAdmin.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/tck/src/com/sun/jini/compat/admin1/OutriggerAdmin.java
URL: http://svn.apache.org/viewvc/river/tck/src/com/sun/jini/compat/admin1/OutriggerAdmin.java?rev=1234278&view=auto
==============================================================================
--- river/tck/src/com/sun/jini/compat/admin1/OutriggerAdmin.java (added)
+++ river/tck/src/com/sun/jini/compat/admin1/OutriggerAdmin.java Sat Jan 21 07:28:27 2012
@@ -0,0 +1,249 @@
+/*
+ *
+ * Copyright 2005 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.sun.jini.compat.admin1;
+
+import java.rmi.RemoteException;
+import java.rmi.UnmarshalException;
+import java.rmi.server.RMIClassLoader;
+
+import java.io.IOException;
+import java.io.File;
+import java.io.PrintWriter;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import com.sun.jini.compat.harness.SysConfig;
+import com.sun.jini.compat.harness.Config;
+import com.sun.jini.compat.harness.BasicServiceAdmin;
+import com.sun.jini.admin.DestroyAdmin;
+import com.sun.jini.start.ServiceStarter;
+
+import net.jini.admin.Administrable;
+import net.jini.core.lookup.ServiceItem;
+import net.jini.core.lookup.ServiceTemplate;
+import net.jini.core.lookup.ServiceID;
+import net.jini.space.JavaSpace;
+
+/**
+ * This class implements the BasicServiceAdmin interface to automate
+ * the testing of the Outrigger service from the
+ * Jini(TM) Technology Software Kit (JSK).
+ */
+public class OutriggerAdmin implements BasicServiceAdmin {
+
+ private String codebaseString = null;
+ private SysConfig sysConfig = null;
+ private JavaSpace jSpace;
+ private Config conf;
+ private final static String proxyClassName =
+ "com.sun.jini.outrigger.SpaceProxy";
+
+ /**
+ * Default Constructor with no arguments.
+ */
+ public OutriggerAdmin() {
+ }
+
+ /**
+ * Constructor that takes in the codebase for the Outrigger
+ * implementation that is being tested.
+ */
+ public OutriggerAdmin(String codebase) {
+ codebaseString = codebase;
+ }
+
+ /**
+ * Takes the Config object for this test run so that the implementation
+ * can get access to property files and config information.
+ *
+ * @param conf the Config object for this test run
+ */
+ public void setConfig(Config conf) {
+ this.conf = conf;
+ }
+
+ /**
+ * Properly configures and starts Outrigger. This method sets the
+ * codebase, classpath, policy and log directory for Outrigger. It
+ * then starts Outrigger in a separate VM and using remote administration
+ * configures Outrigger to register in the public group.
+ */
+ public synchronized void start() throws RemoteException {
+ sysConfig = conf.getSysConfig();
+
+ String classpath = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.outrigger.classpath",
+ null);
+ String codebase = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.outrigger.codebase",
+ codebaseString);
+ String policy = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.outrigger.policy",
+ null);
+ String dbdir = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.outrigger.outputDir",
+ "testOutriggerDir");
+
+ if (classpath == null || codebase == null || policy == null)
+ throw new RemoteException("Environment Failure: The lookup "+
+ "classpath, codebase and policy "+
+ "must be set by property or commandline");
+
+ try {
+ File dir = new File(dbdir);
+ if (!dir.exists()) {
+ dir.mkdir();
+ }
+ File f = File.createTempFile("TestOutrigger", null, dir);
+ String fName = f.getAbsolutePath();
+ f.delete();
+
+ /* Need to set the system property java.class.path
+ * here for it to be set right for Outrigger */
+ String oldClasspath = System.getProperty("java.class.path", null);
+ System.setProperty("java.class.path", classpath);
+
+ /* Start the Outrigger service implementation that resides in the
+ * package 'com.sun.jini.outrigger' */
+ ServiceStarter.Created c =
+ ServiceStarter.create(codebase, policy, fName,
+ new String[] {""}, // public group
+ null, // locators
+ "com.sun.jini.outrigger.StartPersistentOutrigger",
+ "com.sun.jini.outrigger.FrontEndSpace",
+ classpath,
+ "service");
+ jSpace = (JavaSpace) (c.proxy);
+
+ //reset the class path
+ System.setProperty("java.class.path", oldClasspath);
+
+ if (conf.getDebugLevel() == Config.ALL) {
+ PrintWriter log = conf.getLog();
+ if (log != null) {
+ log.println("Admin: using OutriggerAdmin");
+ log.println("Admin: Outrigger proxy is "
+ + jSpace.getClass().getName());
+ log.println("Admin: Outrigger codebase is " + codebase);
+ log.println("Admin: Outrigger classpath is " + classpath);
+ }
+ }
+
+ codebaseString = new String(codebase);
+
+ } catch (Exception e) {
+ throw new RemoteException("Exception while starting Outrigger",e);
+ }
+ }
+
+ /**
+ * Given a list of objects which are ServiceItems this method
+ * determines if any of them are the Outrigger we are testing. It
+ * does this by comparing the class name and the codebase of the
+ * object to the codebase and class name we are looking for. If
+ * they match it returns the matching ServiceItem; otherwise
+ * it returns null.
+ *
+ * @param services the array of ServiceItems that need to be picked from
+ *
+ * @return the ServiceItem for the Outrigger service being tested or null
+ */
+ public synchronized ServiceItem pickService(ServiceItem[] services)
+ throws RemoteException
+ {
+ PrintWriter log = null;
+ if (conf.getDebugLevel() == Config.ALL) {
+ log = conf.getLog();
+ }
+ if (log != null) {
+ log.println("Admin: pickService looking for class "
+ + proxyClassName);
+ log.println(" with codebase " + codebaseString);
+ }
+
+ for (int i = 0; i < services.length; i++) {
+ Object si = services[i].service;
+ String sCodebase = RMIClassLoader.getClassAnnotation(si.getClass());
+
+ if (log != null) {
+ log.println("Admin: pickService found class "
+ + si.getClass().getName());
+ log.println(" with codebase " + sCodebase);
+ }
+
+ if (si.getClass().getName().equals(proxyClassName) &&
+ sCodebase.equals(codebaseString))
+ {
+ return services[i];
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the address of the machine that the Outrigger process is
+ * running on.
+ *
+ * @return the address
+ */
+ public InetAddress getAddress() throws RemoteException {
+ InetAddress ia = null;
+
+ try {
+ ia = InetAddress.getLocalHost();
+ } catch (UnknownHostException uhe) {
+ throw new RemoteException("Couldn't get local host", uhe);
+ }
+ return ia;
+ }
+
+ /**
+ * Provides a service template with the Outrigger's ServiceID to
+ * filter out uninteresting services.
+ *
+ * @return the template
+ */
+ public ServiceTemplate getTemplate() throws RemoteException {
+ return new ServiceTemplate(
+ null,
+ new Class[] { JavaSpace.class },
+ null);
+ }
+
+ /**
+ * Stops the Outrigger service, removes it from activation and
+ * removes it's log directory using remote administration.
+ */
+ public synchronized void stop() throws RemoteException {
+ DestroyAdmin da = (DestroyAdmin) ((Administrable)jSpace).getAdmin();
+ try {
+ da.destroy();
+ } catch (UnmarshalException ue) {
+ if (conf.getDebugLevel() == Config.ERROR) {
+ PrintWriter log = conf.getLog();
+ if (log != null) {
+ log.println("Admin: the following exception is allowed:");
+ ue.printStackTrace(log);
+ }
+ }
+ }
+ }
+}
Propchange: river/tck/src/com/sun/jini/compat/admin1/OutriggerAdmin.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/tck/src/com/sun/jini/compat/admin1/ReggieAdmin.java
URL: http://svn.apache.org/viewvc/river/tck/src/com/sun/jini/compat/admin1/ReggieAdmin.java?rev=1234278&view=auto
==============================================================================
--- river/tck/src/com/sun/jini/compat/admin1/ReggieAdmin.java (added)
+++ river/tck/src/com/sun/jini/compat/admin1/ReggieAdmin.java Sat Jan 21 07:28:27 2012
@@ -0,0 +1,252 @@
+/*
+ *
+ * Copyright 2005 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.sun.jini.compat.admin1;
+
+import java.rmi.RemoteException;
+import java.rmi.server.RMIClassLoader;
+
+import java.io.IOException;
+import java.io.File;
+import java.io.PrintWriter;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import com.sun.jini.compat.harness.SysConfig;
+import com.sun.jini.compat.harness.Config;
+import com.sun.jini.compat.harness.BasicServiceAdmin;
+import com.sun.jini.compat.harness.BasicLookupAdmin;
+
+import com.sun.jini.admin.DestroyAdmin;
+import com.sun.jini.start.ServiceStarter;
+
+import net.jini.admin.Administrable;
+
+import net.jini.core.lookup.ServiceRegistrar;
+import net.jini.core.lookup.ServiceItem;
+import net.jini.core.lookup.ServiceTemplate;
+import net.jini.core.lookup.ServiceID;
+import net.jini.core.discovery.LookupLocator;
+
+/**
+ * This class implements the <code>BasicLookupAdmin</code> interface
+ * and the <code>BasicServiceAdmin</code> interface to
+ * automate the testing of the Reggie lookup service implementation, which
+ * is part of the Jini(TM) Technology Software Kit (JSK).
+ */
+public class ReggieAdmin implements BasicServiceAdmin, BasicLookupAdmin {
+
+ private String codebaseString = null;
+ private Config conf = null;
+ private ServiceRegistrar serviceRegistrar = null;
+ private final static String proxyClassName =
+ "com.sun.jini.reggie.RegistrarProxy";
+
+ /**
+ * Default constructor with no arguments.
+ */
+ public ReggieAdmin() {
+ }
+
+ /**
+ * Constructor that takes a codebase for the Reggie
+ * implementation that is being tested.
+ */
+ public ReggieAdmin(String codebase) {
+ codebaseString = codebase;
+ }
+
+ /**
+ * Takes the Config object for this test run so that the implementation
+ * can get access to property files and other config information.
+ *
+ * @param conf the Config object for this test run
+ */
+ public void setConfig(Config conf) {
+ this.conf = conf;
+ }
+
+ /**
+ * This method properly configures and starts a Reggie lookup
+ * service implementation. This method sets the <code>CLASSPATH</code>,
+ * the log directory, the <code>java.rmi.server.codebase</code>
+ * property, and the <code>java.security.policy</code>
+ * property for the lookup service. It starts a Reggie lookup
+ * service in a separate VM as a member of the public group.
+ */
+ public synchronized void start() throws RemoteException {
+ SysConfig sysConfig = conf.getSysConfig();
+
+ String classpath = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.reggie.classpath",
+ null);
+ String codebase = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.reggie.codebase",
+ codebaseString);
+ String policy = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.reggie.policy",
+ null);
+ String dbdir = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.reggie.outputDir",
+ "testReggieDir");
+
+ if (classpath == null || codebase == null || policy == null)
+ throw new RemoteException("Environment Failure: The lookup "+
+ "classpath, codebase and policy "+
+ "must be set by property or commandline");
+
+ try {
+ File dir = new File(dbdir);
+ if (!dir.exists()) {
+ dir.mkdir();
+ }
+ File f = File.createTempFile("TestReggie", null, dir);
+ String fName = f.getAbsolutePath();
+ f.delete();
+
+ /* Start the lookup service implementation that resides in the
+ * package 'com.sun.jini.reggie' */
+ ServiceStarter.Created c = ServiceStarter.create
+ (codebase,
+ policy,
+ fName,
+ new String[] {""}, // public group
+ null, // locators
+ "com.sun.jini.reggie.CreateLookup",
+ "com.sun.jini.reggie.RegistrarImpl",
+ classpath,
+ "lookup");
+ serviceRegistrar = (ServiceRegistrar)(c.proxy);
+
+ if (conf.getDebugLevel() == Config.ALL) {
+ PrintWriter log = conf.getLog();
+ if (log != null) {
+ log.println("Admin: using ReggieAdmin");
+ log.println("Admin: Reggie proxy is "
+ + serviceRegistrar.getClass().getName());
+ log.println("Admin: Reggie codebase is " + codebase);
+ log.println("Admin: Reggie classpath is " + classpath);
+ }
+ }
+
+ codebaseString = codebase;
+
+ } catch (Exception e) {
+ throw new RemoteException("Exception while starting Reggie",e);
+ }
+ }
+
+ /**
+ * Returns the <code>ServiceRegistrar</code> for this lookup. Required
+ * by <code>BasicLookupAdmin</code>.
+ *
+ * @return the <code>ServiceRegistrar</code> for the lookup being tested
+ */
+ public ServiceRegistrar getServiceRegistrar() throws RemoteException {
+ return serviceRegistrar;
+ }
+
+ /**
+ * Given an array of <code>ServiceItem</code> objects, this method
+ * determines if any of them are the lookup service that associated with
+ * this service admin. It does this by comparing the class name and the
+ * codebase of the <code>ServiceItem</code> instances to the codebase
+ * and class name it is looking for. If a match is found, the matching
+ * <code>ServiceItem</code> is returned; if no match is found, then
+ * <code>null</code> is returned.
+ *
+ * @param services the array of <code>ServiceItem</code> objects
+ * from which to choose
+ *
+ * @return the <code>ServiceItem</code> for the Reggie service being
+ * tested, or <code>null</code>
+ */
+ public synchronized ServiceItem pickService(ServiceItem[] services)
+ throws RemoteException
+ {
+ PrintWriter log = null;
+ if (conf.getDebugLevel() == Config.ALL) {
+ log = conf.getLog();
+ }
+ if (log != null) {
+ log.println("Admin: pickService looking for class "
+ + proxyClassName);
+ log.println(" with codebase " + codebaseString);
+ }
+
+ for (int i = 0; i < services.length; i++) {
+ Object si = services[i].service;
+ String sCodebase = RMIClassLoader.getClassAnnotation(si.getClass());
+
+ if (log != null) {
+ log.println("Admin: pickService found class "
+ + si.getClass().getName());
+ log.println(" with codebase " + sCodebase);
+ }
+
+ if (si.getClass().getName().equals(proxyClassName) &&
+ sCodebase.equals(codebaseString))
+ {
+ return services[i];
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the address that Reggie is running on.
+ *
+ * @return the address
+ */
+ public InetAddress getAddress() throws RemoteException {
+ LookupLocator ll = serviceRegistrar.getLocator();
+ InetAddress ia = null;
+
+ try {
+ ia = InetAddress.getByName(ll.getHost());
+ } catch(UnknownHostException uhe) {
+ throw new RemoteException(ll.getHost()+" is not a known host",uhe);
+ }
+ return ia;
+ }
+
+ /**
+ * Provides a service template with the <code>ServiceID</code> of the
+ * lookup service, to filter out uninteresting services.
+ *
+ * @return the template
+ */
+ public ServiceTemplate getTemplate() throws RemoteException {
+ ServiceID sid = null;
+ if (serviceRegistrar != null) {
+ sid = serviceRegistrar.getServiceID();
+ }
+ return new ServiceTemplate(sid, null, null);
+ }
+
+ /**
+ * Destroys the lookup service, and removes its log directory.
+ */
+ public synchronized void stop() throws RemoteException {
+ DestroyAdmin da = (DestroyAdmin)
+ ((Administrable)serviceRegistrar).getAdmin();
+ da.destroy();
+ }
+}
Propchange: river/tck/src/com/sun/jini/compat/admin1/ReggieAdmin.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/tck/src/com/sun/jini/compat/admin1/ReggieServiceAdmin.java
URL: http://svn.apache.org/viewvc/river/tck/src/com/sun/jini/compat/admin1/ReggieServiceAdmin.java?rev=1234278&view=auto
==============================================================================
--- river/tck/src/com/sun/jini/compat/admin1/ReggieServiceAdmin.java (added)
+++ river/tck/src/com/sun/jini/compat/admin1/ReggieServiceAdmin.java Sat Jan 21 07:28:27 2012
@@ -0,0 +1,261 @@
+/*
+ *
+ * Copyright 2005 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.sun.jini.compat.admin1;
+
+import java.rmi.RemoteException;
+import java.rmi.activation.ActivationException;
+import java.rmi.server.RMIClassLoader;
+
+import java.io.IOException;
+import java.io.File;
+import java.io.PrintWriter;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import com.sun.jini.compat.harness.SysConfig;
+import com.sun.jini.compat.harness.Config;
+import com.sun.jini.compat.harness.BasicServiceAdmin;
+
+import com.sun.jini.start.ServiceStarter;
+import com.sun.jini.start.ServiceDestroyer;
+import com.sun.jini.reggie.RegistrarAdmin;
+
+import net.jini.admin.Administrable;
+import net.jini.core.lookup.ServiceRegistrar;
+import net.jini.core.lookup.ServiceItem;
+import net.jini.core.lookup.ServiceTemplate;
+import net.jini.core.lookup.ServiceID;
+import net.jini.core.discovery.LookupLocator;
+
+/**
+ * This class implements the <code>BasicServiceAdmin</code> interface to
+ * automate the testing of the Reggie lookup service implementation, which
+ * is part of the Jini(TM) Technology Software Kit (JSK). This admin treats Reggie as
+ * a service by asking it to join the "public" group.
+ */
+public class ReggieServiceAdmin implements BasicServiceAdmin {
+
+ private String codebaseString = null;
+ private Config conf = null;
+ private ServiceRegistrar serviceRegistrar = null;
+ private ServiceStarter.Created created = null;
+ private final static String proxyClassName =
+ "com.sun.jini.reggie.RegistrarProxy";
+
+ /**
+ * Default constructor with no arguments.
+ */
+ public ReggieServiceAdmin() {
+ }
+
+ /**
+ * Constructor that takes a codebase for the Reggie
+ * implementation that is being tested.
+ */
+ public ReggieServiceAdmin(String codebase) {
+ codebaseString = codebase;
+ }
+
+ /**
+ * Takes the Config object for this test run so that the implementation
+ * can get access to property files and other config information.
+ *
+ * @param conf the Config object for this test run
+ */
+ public void setConfig(Config conf) {
+ this.conf = conf;
+ }
+
+ /**
+ * This method properly configures and starts a Reggie lookup
+ * service implementation. This method sets the <code>CLASSPATH</code>,
+ * the log directory, the <code>java.rmi.server.codebase</code>
+ * property, and the <code>java.security.policy</code>
+ * property for the lookup service. It starts a Reggie lookup
+ * service in a separate VM as a member of the public group and
+ * asks it to join the public group.
+ */
+ public synchronized void start() throws RemoteException {
+ SysConfig sysConfig = conf.getSysConfig();
+
+ String classpath = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.reggieService.classpath",
+ null);
+ String codebase = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.reggieService.codebase",
+ codebaseString);
+ String policy = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.reggieService.policy",
+ null);
+ String dbdir = sysConfig.getStringConfigVal(
+ "com.sun.jini.compat.admin1.reggieService.outputDir",
+ "testReggieDir");
+
+ if (classpath == null || codebase == null || policy == null)
+ throw new RemoteException("Environment Failure: The lookup "+
+ "classpath, codebase and policy "+
+ "must be set by property or commandline");
+
+ try {
+ File dir = new File(dbdir);
+ if (!dir.exists()) {
+ dir.mkdir();
+ }
+ File f = File.createTempFile("TestReggie", null, dir);
+ String fName = f.getAbsolutePath();
+ f.delete();
+
+ /* Start the lookup service implementation that resides in the
+ * package 'com.sun.jini.reggie' */
+ created = ServiceStarter.create(codebase,
+ policy,
+ fName,
+ new String[] {""}, // public group
+ null, // locators
+ "com.sun.jini.reggie.CreateLookup",
+ "com.sun.jini.reggie.RegistrarImpl",
+ classpath,
+ "service");
+ serviceRegistrar = (ServiceRegistrar)(created.proxy);
+
+ RegistrarAdmin reggieAdmin =
+ (RegistrarAdmin)((Administrable)created.proxy).getAdmin();
+ reggieAdmin.addLookupGroups(new String[] {""});
+
+ if (conf.getDebugLevel() == Config.ALL) {
+ PrintWriter log = conf.getLog();
+ if (log != null) {
+ log.println("Admin: using ReggieServiceAdmin");
+ log.println("Admin: ReggieService proxy is "
+ + serviceRegistrar.getClass().getName());
+ log.println("Admin: ReggieService codebase is " + codebase);
+ log.println("Admin: ReggieService classpath is "+classpath);
+ }
+ }
+
+ codebaseString = codebase;
+
+ } catch (Exception e) {
+ throw new RemoteException("Exception while starting Reggie as "
+ + "a service", e);
+ }
+ }
+
+ /**
+ * Given an array of <code>ServiceItem</code> objects, this method
+ * determines if any of them are the lookup service that associated with
+ * this service admin. It does this by comparing the class name and the
+ * codebase of the <code>ServiceItem</code> instances to the codebase
+ * and class name it is looking for. If a match is found, the matching
+ * <code>ServiceItem</code> is returned; if no match is found, then
+ * <code>null</code> is returned.
+ *
+ * @param services the array of <code>ServiceItem</code> objects
+ * from which to choose
+ *
+ * @return the <code>ServiceItem</code> for the Reggie service being
+ * tested, or <code>null</code>
+ */
+ public synchronized ServiceItem pickService(ServiceItem[] services)
+ throws RemoteException
+ {
+ PrintWriter log = null;
+ if (conf.getDebugLevel() == Config.ALL) {
+ log = conf.getLog();
+ }
+ if (log != null) {
+ log.println("Admin: pickService looking for class "
+ + proxyClassName);
+ log.println(" with codebase " + codebaseString);
+ }
+
+ for (int i = 0; i < services.length; i++) {
+ Object si = services[i].service;
+ String sCodebase = RMIClassLoader.getClassAnnotation(si.getClass());
+
+ if (log != null) {
+ log.println("Admin: pickService found class "
+ + si.getClass().getName());
+ log.println(" with codebase " + sCodebase);
+ }
+
+ if (si.getClass().getName().equals(proxyClassName) &&
+ sCodebase.equals(codebaseString))
+ {
+ return services[i];
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the address that the Reggie service is running on.
+ *
+ * @return the address
+ */
+ public InetAddress getAddress() throws RemoteException {
+ InetAddress ia = null;
+
+ try {
+ ia = InetAddress.getLocalHost();
+ } catch (UnknownHostException uhe) {
+ throw new RemoteException("Couldn't get local host", uhe);
+ }
+ return ia;
+ }
+
+ /**
+ * Provides a service template with the <code>ServiceID</code> of the
+ * lookup service, to filter out uninteresting services.
+ *
+ * @return the template
+ */
+ public ServiceTemplate getTemplate() throws RemoteException {
+ ServiceID sid = null;
+ if(serviceRegistrar != null) {
+ sid = serviceRegistrar.getServiceID();
+ }
+ return new ServiceTemplate(sid, null, null);
+ }
+
+ /**
+ * Stops the Reggie service, removes it from activation and removes
+ * it's log directory using remote administration.
+ */
+ public synchronized void stop() throws RemoteException {
+
+ /* this method will make certain the service is unregistered with
+ * activation before returning. This is necessary because asynchronous
+ * destroyAdmins can leave services running and generate spurious
+ * multicast request packets. */
+ try {
+ ServiceDestroyer.destroy(created);
+ } catch (ActivationException ae) {
+ if (conf.getDebugLevel() == Config.ERROR) {
+ PrintWriter log = conf.getLog();
+ if (log != null) {
+ log.println("Warning: Reggie did not shutdown cleanly");
+ ae.printStackTrace(log);
+ }
+ }
+ }
+ }
+}
Propchange: river/tck/src/com/sun/jini/compat/admin1/ReggieServiceAdmin.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/tck/src/com/sun/jini/compat/admin1/TransientServiceAdmin.java
URL: http://svn.apache.org/viewvc/river/tck/src/com/sun/jini/compat/admin1/TransientServiceAdmin.java?rev=1234278&view=auto
==============================================================================
--- river/tck/src/com/sun/jini/compat/admin1/TransientServiceAdmin.java (added)
+++ river/tck/src/com/sun/jini/compat/admin1/TransientServiceAdmin.java Sat Jan 21 07:28:27 2012
@@ -0,0 +1,554 @@
+/*
+ *
+ * Copyright 2005 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.sun.jini.compat.admin1;
+
+import java.rmi.RemoteException;
+import java.rmi.server.RMIClassLoader;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.io.File;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import com.sun.jini.compat.harness.SysConfig;
+import com.sun.jini.compat.harness.Config;
+import com.sun.jini.compat.harness.BasicServiceAdmin;
+
+import net.jini.core.lookup.ServiceItem;
+import net.jini.core.lookup.ServiceTemplate;
+import net.jini.core.lookup.ServiceID;
+
+/**
+ * This class implements the <CODE>BasicServiceAdmin</CODE> interface
+ * to automate the testing of a transient service. A transient service
+ * by definition of this admin is one that is started using the following
+ * command line.<BR>
+ * <blockquote><code>
+ * java -jar -Djava.security.policy=<i>security_policy_file_arg</i><br>
+ *
+ * -Djava.rmi.server.codebase=<i>codebase_arg</i> <br>
+ *
+ * [<i>optional_jvm_options</i>] <i>executable_jar_file</i> <br>
+ * </blockquote></code><br>
+ * Where the arguments are :
+ * <blockquote>
+ * <dl>
+ * <dt><b><code> -jar</code></dt></b>
+ * <dd> <code>-jar</code> is a <code>java</code> command-line option that
+ * tells the interpreter to execute a program encapsulated in a JAR file.
+ * The following links provide more detail on this option.
+ * <blockquote>
+ * <code>
+ * <a href="http://java.sun.com/products/jdk/1.2/docs/tooldocs/solaris/java.html#-jar">
+ * http://java.sun.com/products/jdk/1.2/docs/tooldocs/solaris/java.html#-jar</a>
+ * <a href="http://java.sun.com/products/jdk/1.2/docs/tooldocs/win32/java.html#-jar">
+ * http://java.sun.com/products/jdk/1.2/docs/tooldocs/win32/java.html#-jar</a>
+ * </code>
+ * </blockquote>
+ * <p>
+ * <dt><b><i><code>security_policy_file_arg</code></i></dt></b> <dd> This
+ * argument is used to specify the security policy file that the TransientService
+ * will run under.</dd>
+ * <p>
+ *
+ * <dt><b><i><code>codebase_arg</code></i></dt></b> <dd> This argument is
+ * used to specify the URL of the <code><i>service</i>-dl.jar</code> that will
+ * be downloaded to clients. This JAR file contains the classes required
+ * by clients in order to interact with the TransientService server.</dd>
+ * <p>
+ *
+ * <dt><b><code><i>optional_jvm_options</i></code></dt></b> <dd>These are
+ * optional arguments for the VM that the
+ * TransientService will run in. The following links give more detail on
+ * what arguments can be passed to a VM.</dd>
+ *
+ * <blockquote>
+ * <code>
+ * <a href="http://java.sun.com/products/jdk/1.2/docs/tooldocs/solaris/java.html">
+ * http://java.sun.com/products/jdk/1.2/docs/tooldocs/solaris/java.html</a>
+ *
+ * <a href="http://java.sun.com/products/jdk/1.2/docs/tooldocs/win32/java.html">
+ * http://java.sun.com/products/jdk/1.2/docs/tooldocs/win32/java.html</a>
+ * </code>
+ * </blockquote>
+ *
+ * <dt><b><code><i>executable_jar_file</i></code></dt></b> <dd>This JAR
+ * file contains a program that is identified by the manifest as
+ * having a <code>main</code> method. In this case, this argument would
+ * be the absolute path to the <code><i>service</i>.jar</code> file,
+ * which has its <b>Main-Class</b> attribute. For more
+ * information on the <code>-jar</code> option of the <code>java</code>
+ * command, you can take a look at:
+ *
+ * <blockquote>
+ * <code>
+ * <a href="http://java.sun.com/products/jdk/1.2/docs/tooldocs/solaris/java.html">
+ * http://java.sun.com/products/jdk/1.2/docs/tooldocs/solaris/java.html</a>
+ *
+ * <a href="http://java.sun.com/products/jdk/1.2/docs/tooldocs/win32/java.html">
+ * http://java.sun.com/products/jdk/1.2/docs/tooldocs/win32/java.html</a>
+ *
+ * <a href="http://java.sun.com/products/jdk/1.2/docs/guide/jar/manifest.html">
+ * http://java.sun.com/products/jdk/1.2/docs/guide/jar/manifest.html</a>
+ *
+ * <a href="http://java.sun.com/products/jdk/1.2/docs/tooldocs/solaris/jar.html">
+ * http://java.sun.com/products/jdk/1.2/docs/tooldocs/solaris/jar.html</a>
+ *
+ * <a href="http://java.sun.com/products/jdk/1.2/docs/tooldocs/win32/jar.html">
+ * http://java.sun.com/products/jdk/1.2/docs/tooldocs/win32/jar.html</a>
+ * </code>
+ * </blockquote>
+ * </dl>
+ * </blockquote>
+ *
+ * <P>
+ * Because transient services are not activatable, it is necessary to start
+ * them in a separate VM to avoid codebase and classpath problems in certain
+ * LDJ Kit tests.</P>
+ * <P>
+ * In order to use this Admin several properties must be defined in the
+ * LDJ Kit config file. See the documentation for the <code>start</code> method
+ * below for more information.</P>
+ */
+public class TransientServiceAdmin implements BasicServiceAdmin {
+
+ /**
+ * Codebase passed in via constructor.
+ */
+ private String codebaseString = null;
+
+ /**
+ * Properties files.
+ */
+ private SysConfig sysConfig = null;
+ private Config conf;
+
+ /**
+ * Reference to proxy of service under test.
+ */
+ private Object serviceProxy = null;
+
+ /**
+ * The fully qualified class name of the service proxy.
+ * Loaded from config file property.
+ */
+ private String proxyClassName = null;
+
+ /**
+ * Sub-process of spawned service, valid after <code>exec()</code> call.
+ */
+ private Process proc = null;
+
+
+ /**
+ * Default Constructor with no arguments.
+ */
+ public TransientServiceAdmin() {
+ super();
+ }
+
+ /**
+ * Constructor that takes in the codebase for the service
+ * implementation that is being tested.
+ */
+ public TransientServiceAdmin(String codebase) {
+ codebaseString = codebase;
+ }
+
+ /**
+ * Sets the Config object for this test run that the implementation
+ * can get access to property files and other config information.
+ *
+ * @param conf the Config object for this test run
+ */
+ public void setConfig(Config conf) {
+ this.conf = conf;
+ }
+
+ /**
+ * Properly configures and starts the service. This method sets
+ * the codebase and policy for the service. It then starts the
+ * service in a separate VM. Optional service arguments can be
+ * included after if desired.
+ * <P>Below is a table describing all required and optional properties
+ * used by this admin.</P>
+ * <TABLE BORDER>
+ * <TR BGCOLOR="99CCFF">
+ * <TH>Property</TH><TH>Usage</TH><TH>Status</TH>
+ * </TR>
+ * <TR>
+ * <TD>com.sun.jini.compat.service.proxyclass</TD>
+ * <TD>The fully qualified class name of the service's proxy</TD>
+ * <TD>Mandatory</TD>
+ * </TR>
+ * <TR>
+ * <TD>com.sun.jini.compat.service.jarfile</TD>
+ * <TD>The full path of executable JAR file for starting service</TD>
+ * <TD>Mandatory</TD>
+ * </TR>
+ * <TR>
+ * <TD>com.sun.jini.compat.service.codebase</TD>
+ * <TD>The codebase for any code published by the service under test</TD>
+ * <TD>Mandatory</TD>
+ * </TR>
+ * <TR>
+ * <TD>com.sun.jini.compat.service.policy</TD>
+ * <TD>The location of a policy file for use in starting the service</TD>
+ * <TD>Mandatory</TD>
+ * </TR>
+ * <TR>
+ * <TD>com.sun.jini.compat.service.optional_jvm_args</TD>
+ * <TD>Any additional args passed to the VM (must include -D)</TD>
+ * <TD>Optional</TD>
+ * </TR>
+ * <TR>
+ * <TD>com.sun.jini.compat.service.optional_service_args</TD>
+ * <TD>Any additional arguments passed to the service</TD>
+ * <TD>Optional</TD>
+ * </TR>
+ * <TR>
+ * <TD>com.sun.jini.compat.service.java</TD>
+ * <TD>The full path of the VM that is used to start service</TD>
+ * <TD>Optional</TD>
+ * </TR>
+ * </TABLE>
+ */
+ public synchronized void start() throws RemoteException {
+ sysConfig = conf.getSysConfig();
+
+ // prefix for the transient service properties
+ String prefix = "com.sun.jini.compat.service";
+
+ // get the name of the proxy class for the service under test
+ proxyClassName = sysConfig.getStringConfigVal(
+ prefix + ".proxyclass",
+ null);
+ if (proxyClassName == null)
+ throw new RemoteException("Environment Failure: The "
+ + "property com.sun.jini.compat.service.proxyclass "
+ + "must be set by property or commandline");
+
+ String jarFile = sysConfig.getStringConfigVal(
+ prefix + ".jarfile",
+ null);
+
+ String codebase = sysConfig.getStringConfigVal(
+ prefix + ".codebase",
+ codebaseString);
+ codebaseString = codebase;
+
+ String policy = sysConfig.getStringConfigVal(
+ prefix + ".policy",
+ null);
+
+ if (jarFile == null || codebase == null || policy == null)
+ throw new RemoteException("Environment Failure: The "+
+ "jarfile path, codebase and policy "+
+ "must be set by property or commandline");
+
+ // grab any additional args to the VM
+ String optionalVMArgs = sysConfig.getStringConfigVal(
+ prefix + ".optional_jvm_args",
+ null);
+
+ // grab any additional args for the service itself
+ String optionalServiceArgs = sysConfig.getStringConfigVal(
+ prefix + ".optional_service_args",
+ null);
+
+ // capture the name of the VM to use for exec'ing the service
+ String javaProg = System.getProperty(prefix + ".java");
+ if (javaProg == null) {
+ // Go with the default
+ String javaHome = null;
+
+ try {
+ javaHome = System.getProperty("java.home");
+ } catch (Exception e) {
+ if (conf.getDebugLevel() == Config.ALL) {
+ PrintWriter log = conf.getLog();
+ if (log != null) {
+ log.println("Admin: received an exception while "
+ + "getting java.home property:");
+ e.printStackTrace(log);
+ log.println("Admin: using `java' to spawn backend VM");
+ }
+ }
+ }
+
+ if (javaHome != null) {
+ javaProg = javaHome + File.separator + "bin"
+ + File.separator + "java";
+ } else {
+ javaProg = "java";
+ }
+ }
+
+ // build a command line for exec
+ StringBuffer cmd = new StringBuffer(javaProg + " -jar");
+ cmd.append(" -Djava.security.policy=").append(policy);
+ cmd.append(" -Djava.rmi.server.codebase=").append(codebase);
+ if (optionalVMArgs != null) {
+ cmd.append(" ").append(optionalVMArgs);
+ }
+ cmd.append(" ").append(jarFile);
+ if (optionalServiceArgs != null) {
+ cmd.append(" ").append(optionalServiceArgs);
+ }
+
+ try {
+
+ PrintWriter log = conf.getLog();
+ if (conf.getDebugLevel() == Config.ALL && log != null) {
+ log.println("Admin: using TransientServiceAdmin");
+ log.println("Admin: service proxy is " + proxyClassName);
+ log.println("Admin: service codebase is " + codebase);
+ log.println("Admin: starting service with command:");
+ log.println();
+ log.println(cmd);
+ log.println();
+ }
+
+ // exec the service
+ proc = Runtime.getRuntime().exec(new String(cmd));
+
+ if (conf.getDebugLevel() == Config.ALL && log != null) {
+ // set up to dump output to the screen
+ log.println("Admin: logging service output");
+ bindOutput(log,log);
+ }
+
+ } catch (Exception e) {
+ throw new RemoteException("Exception while starting transient "
+ + "service",e);
+ }
+ }
+
+ /**
+ * Given a list of objects which are ServiceItems this method
+ * determines if any of them are the service we are testing. It
+ * does this by comparing the class name and the codebase of the
+ * object to the codebase and class name we are looking for. If
+ * they match it returns the matching ServiceItem; otherwise
+ * it returns null.
+ *
+ * @param services the array of ServiceItems that need to be picked from
+ *
+ * @return the ServiceItem for the service being tested or null
+ */
+ public synchronized ServiceItem pickService(ServiceItem[] services)
+ throws RemoteException
+ {
+ PrintWriter log = null;
+ if (conf.getDebugLevel() == Config.ALL) {
+ log = conf.getLog();
+ }
+ if (log != null) {
+ log.println("Admin: pickService looking for class "
+ + proxyClassName);
+ log.println(" with codebase " + codebaseString);
+ }
+
+ for(int i = 0; i < services.length; i++) {
+ Object si = services[i].service;
+ String sCodebase = RMIClassLoader.getClassAnnotation(si.getClass());
+
+ if (log != null) {
+ log.println("Admin: pickService found class "
+ + si.getClass().getName());
+ log.println(" with codebase " + sCodebase);
+ }
+
+ if (si.getClass().getName().equals(proxyClassName) &&
+ sCodebase.equals(codebaseString))
+ {
+ serviceProxy = services[i].service;
+ return services[i];
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the address of the machine that the service process is
+ * running on.
+ *
+ * @return the address
+ */
+ public InetAddress getAddress() throws RemoteException {
+ InetAddress ia = null;
+
+ try {
+ ia = InetAddress.getLocalHost();
+ } catch (UnknownHostException uhe) {
+ throw new RemoteException("Couldn't get local host", uhe);
+ }
+ return ia;
+ }
+
+ /**
+ * Provides a service template with the service's ServiceID to
+ * filter out uninteresting services.
+ *
+ * @return the template
+ */
+ public ServiceTemplate getTemplate() throws RemoteException {
+ try {
+ //Class proxyClass = Class.forName(proxyClassName);
+ //Class[] type = new Class[] {proxyClass};
+ return new ServiceTemplate(null, null, null);
+ } catch (Exception ex) {
+ throw new RemoteException("Can not create ServiceTemplate.", ex);
+ }
+ }
+
+ /**
+ * Stops the service, removes it from activation and removes it's
+ * log directory using remote administration.
+ */
+ public synchronized void stop() throws RemoteException {
+ proc.destroy();
+ serviceProxy=null;
+ }
+
+ /**
+ * Attach stdout and stderr to the subprocess.
+ */
+ private void bindOutput() throws IOException {
+ bindOutput(System.out, System.err);
+ }
+
+ /**
+ * Attach the designated streams to the subprocess.
+ */
+ private void bindOutput(OutputStream out, OutputStream err)
+ throws IOException
+ {
+ Thread outThread =
+ new Thread(new Dumper(proc.getInputStream(), out, false),
+ "Out Forwarding Thread: " + proxyClassName);
+
+ Thread errThread =
+ new Thread(new Dumper(proc.getErrorStream(), err, false),
+ "Err Forwarding Thread: " + proxyClassName);
+
+ outThread.start();
+ errThread.start();
+ }
+
+ /**
+ * Attach the designated writers to the subprocess.
+ */
+ private void bindOutput(Writer out, Writer err)
+ throws IOException
+ {
+ Thread outThread =
+ new Thread(new Dumper(proc.getInputStream(), out, false),
+ "Out Forwarding Thread: " + proxyClassName);
+
+ Thread errThread =
+ new Thread(new Dumper(proc.getErrorStream(), err, false),
+ "Err Forwarding Thread: " + proxyClassName);
+
+ outThread.start();
+ errThread.start();
+ }
+
+ /**
+ * Utility class to forward bytes from one stream to another.
+ */
+ private class Dumper implements Runnable {
+ private final InputStream in;
+ private final OutputStream out;
+ private final Writer wrout;
+ private final boolean flush;
+
+ /**
+ * Create a new <code>Dumper</code>
+ * @param in The stream to take bytes from
+ * @param out The stream to dump the bytes to
+ * @param flush If true flush out after each write.
+ */
+ Dumper(InputStream in, OutputStream out, boolean flush) {
+ this.in = in;
+ this.out = out;
+ this.wrout = null;
+ this.flush = flush;
+ }
+
+ /**
+ * Create a new <code>Dumper</code>
+ * @param in The stream to take bytes from
+ * @param out The stream to dump the bytes to
+ * @param flush If true flush out after each write.
+ */
+ Dumper(InputStream in, Writer out, boolean flush) {
+ this.in = in;
+ this.out = null;
+ this.wrout = out;
+ this.flush = flush;
+ }
+
+ /**
+ * Read a bunch of bytes from the associated
+ * <code>InputStream</code> and write them to the associated
+ * <code>OutputStream<code>, repeat until the read returns
+ * EOF, or until there is an <code>IOException</code>
+ */
+ public void run() {
+ byte[] buf = new byte[4096];
+ try {
+ while (true) {
+ final int bytesRead = in.read(buf);
+ if (bytesRead > 0) {
+ if (out != null) {
+ // perform write OutputStream style
+ out.write(buf, 0, bytesRead);
+ if (flush) out.flush();
+ } else {
+ // perform write Writer style
+ char[] chr = new char[buf.length];
+ for(int i = 0; i < buf.length; i++) {
+ chr[i] = (char) buf[i];
+ }
+ wrout.write(chr, 0, bytesRead);
+ if (flush) wrout.flush();
+ }
+ } else if (bytesRead < 0)
+ break;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // Just trying to be nice
+ }
+ }
+ }
+ }
+
+}
Propchange: river/tck/src/com/sun/jini/compat/admin1/TransientServiceAdmin.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/tck/src/com/sun/jini/compat/admin1/package.html
URL: http://svn.apache.org/viewvc/river/tck/src/com/sun/jini/compat/admin1/package.html?rev=1234278&view=auto
==============================================================================
--- river/tck/src/com/sun/jini/compat/admin1/package.html (added)
+++ river/tck/src/com/sun/jini/compat/admin1/package.html Sat Jan 21 07:28:27 2012
@@ -0,0 +1,22 @@
+<!--
+ !
+ ! Copyright 2005, Sun Microsystems, Inc.
+ ! Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">
+ ! Apache License, Version 2.0</a>.
+ !
+ !-->
+<BODY BGCOLOR="white">
+
+This package contains admin implementations for the services that ship
+with the Jini(TM) Technology Starter Kit, v1.2.1.
+
+These classes are provided as examples of how to
+write your own service's admin. Admins are used to automate the testing of a
+program using the Jini Technology Lookup, Discovery, and Join Compatibility Kit.
+
+
+@see <a href="../../../../../../writing-admin.html"><i>Implementing the LDJ Kit Admin Interface</i></a>
+@see <a href="../../../../../../running.html"><i>Running the Jini Technology Lookup, Discovery, and Join Compatibility Kit</i></a>
+
+</BODY>
+</HTML>
Propchange: river/tck/src/com/sun/jini/compat/admin1/package.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: river/tck/src/com/sun/jini/compat/admin2/ExecServiceAdmin.java
URL: http://svn.apache.org/viewvc/river/tck/src/com/sun/jini/compat/admin2/ExecServiceAdmin.java?rev=1234278&view=auto
==============================================================================
--- river/tck/src/com/sun/jini/compat/admin2/ExecServiceAdmin.java (added)
+++ river/tck/src/com/sun/jini/compat/admin2/ExecServiceAdmin.java Sat Jan 21 07:28:27 2012
@@ -0,0 +1,344 @@
+/*
+ *
+ * Copyright 2005 Sun Microsystems, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.sun.jini.compat.admin2;
+
+// java.io
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.io.PrintWriter;
+
+// java.rmi
+import java.rmi.RemoteException;
+import java.rmi.server.RMIClassLoader;
+
+// java.net
+import java.net.InetAddress;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.net.MalformedURLException;
+
+// java.util
+import java.util.List;
+import java.util.ArrayList;
+
+// com.sun.jini.compat
+import com.sun.jini.compat.harness.BasicServiceAdmin;
+import com.sun.jini.compat.harness.BasicLookupAdmin;
+import com.sun.jini.compat.harness.Config;
+import com.sun.jini.compat.harness.SysConfig;
+
+// net.jini
+import net.jini.core.lookup.ServiceRegistrar;
+import net.jini.core.lookup.ServiceItem;
+import net.jini.core.lookup.ServiceTemplate;
+import net.jini.core.lookup.ServiceID;
+import net.jini.core.discovery.LookupLocator;
+
+/**
+ * This class implements the BasicServiceAdmin and BasicLookupAdmin
+ * interfaces to automate the testing of any <b>transient or persistent</b>
+ * programs. Some methods document properties that they support.
+ */
+public class ExecServiceAdmin implements BasicServiceAdmin, BasicLookupAdmin {
+ private static String sID = null;
+ private Config config = null;
+ private Process process;
+
+ /**
+ * Basic no-arg constructor.
+ */
+ public ExecServiceAdmin() {
+ }
+
+ /**
+ * See comments for <code>BasicAdmin</code>.
+ */
+ public void setConfig(Config conf) {
+ config = conf;
+ }
+
+ /**
+ * Returns the address of this host. The program must
+ * be running on this host.
+ *
+ * @return the address of the program
+ */
+ public InetAddress getAddress() throws RemoteException {
+ try {
+ return InetAddress.getLocalHost();
+ } catch(UnknownHostException uhe) {
+ throw new RemoteException("Problem getting local host InetAddress",uhe);
+ }
+ }
+
+ /**
+ * Using the <code>Runtime.exe()</code> method, starts the program(s)
+ * by running the command given by the property
+ * <code>com.sun.jini.compat.admin2.execServiceAdmin.startCommand</code>.
+ *
+ * @throws java.rmi.RemoteException if problem starting the program
+ */
+ public void start() throws RemoteException {
+ try {
+ String command = config.getSysConfig().getStringConfigVal(
+ "com.sun.jini.compat.admin2.execServiceAdmin.startCommand","");
+ process = Runtime.getRuntime().exec(command);
+ bindOutput(process);
+ } catch (Exception e) {
+ throw new RemoteException("Problem starting program",e);
+ }
+ try {
+ Thread.sleep(15000);
+ } catch (InterruptedException ignore) {}
+ }
+
+ /**
+ * Stops the program. This method does not need to wait
+ * for the program to stop. In addition, this method may
+ * be called safely even if the start() method threw an exception
+ * or was never called.
+ *
+ * @throws java.rmi.RemoteException problem stopping the program
+ */
+ public void stop() throws RemoteException {
+ if (process != null) {
+ process.destroy();
+ }
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException ignore) {}
+ }
+
+ /**
+ * Given an array of service proxy objects, this method
+ * returns the first one that contains a proxy that
+ * implements the interface specified by the property
+ * <code>com.sun.jini.compat.admin2.execServiceAdmin.interface</code>.
+ * If the specified interface is not implemented by any of
+ * the listed services, then <code>null</code> is returned.
+ *
+ * @param services the array <code>ServiceItem</code> objects
+ * from which to choose
+ * @return the <code>ServiceItem</code> for the service being tested,
+ * or <code>null</code>
+ */
+ public ServiceItem pickService(ServiceItem[] services)
+ throws RemoteException
+ {
+ String proxyInterface = config.getSysConfig().getStringConfigVal(
+ "com.sun.jini.compat.admin2.execServiceAdmin.interface", null);
+
+ PrintWriter log = null;
+ if (config.getDebugLevel() == Config.ALL) {
+ log = config.getLog();
+ }
+ if (log != null) {
+ log.println("Admin: looking for proxy that implements "
+ + proxyInterface);
+ }
+
+ for (int i = 0; i < services.length; i++) {
+ Class serviceClass = services[i].service.getClass();
+ String codebase = RMIClassLoader.getClassAnnotation(serviceClass);
+ if (log != null) {
+ log.println("Admin: found class "
+ + serviceClass.getName() + " with codebase " + codebase);
+ }
+ try {
+ String codebaseHost = (new URL(codebase)).getHost();
+ String codebaseIP =
+ InetAddress.getByName(codebaseHost).getHostAddress();
+ int codebasePort = (new URL(codebase)).getPort();
+ String thisIP = getAddress().getHostAddress();
+ if (log != null) {
+ log.println("Admin: codebase host:" + codebaseIP
+ + " this host:" + thisIP);
+ }
+ if (codebaseIP.equals(thisIP) && codebasePort != 8080) {
+ ArrayList interfaces = new ArrayList();
+ getSuperinterfaces(interfaces, serviceClass);
+ for (int j = 0; j < interfaces.size(); j++) {
+ Class intf = (Class) interfaces.get(j);
+ if (log != null) {
+ log.println("Admin: proxy implements:"
+ + intf.getName());
+ }
+ if (intf.getName().equals(proxyInterface)) {
+ if (log != null) {
+ log.println("Admin: returning class "
+ + services[i].service.getClass().getName()
+ + " with codebase " + codebase);
+ }
+ return services[i];
+ }
+ }
+ }
+ } catch (MalformedURLException mue) {
+ if (log != null) {
+ log.println("Admin: malformed codebase: " + codebase);
+ log.println("Admin: exception: " + mue);
+ }
+ } catch (UnknownHostException uhe) {
+ if (log != null) {
+ log.println("Admin: exception: " + uhe);
+ }
+ } catch (RemoteException re) {
+ if (log != null) {
+ log.println("Admin: exception: " + re);
+ }
+ }
+ }
+
+ if (log != null) {
+ log.println("Admin: service not found; returning null");
+ }
+ return null;
+ }
+
+ /**
+ * Return a blank <code>ServiceTemplate</code>.
+ *
+ * @return the template
+ */
+ public ServiceTemplate getTemplate() throws RemoteException {
+ return new ServiceTemplate(null, null, null);
+ }
+
+ /**
+ * Returns the ServiceRegistrar from an already started Lookup.
+ * If there are any problems getting the ServiceRegistrar it
+ * throws a RemoteException. It uses a property called:
+ * <code>com.sun.jini.compat.admin2.execServiceAdmin.lookupPort</code>.
+ * Using that port and the address of the lookup provided by
+ * the <code>getAddress</code> method it generates a
+ * <code>LookupLocator</code> to get the
+ * <code>ServiceRegistrar</code> for the lookup service being
+ * tested.
+ *
+ * @return the <code>ServiceRegistrar</code> for the lookup being
+ * tested.
+ */
+ public ServiceRegistrar getServiceRegistrar()
+ throws RemoteException
+ {
+ PrintWriter log = null;
+ if (config.getDebugLevel() == Config.ALL) {
+ log = config.getLog();
+ }
+ SysConfig sys = config.getSysConfig();
+ int port = sys.getIntConfigVal(
+ "com.sun.jini.compat.admin2.execServiceAdmin.lookupPort",-1);
+ String lookupURLString = "jini://"+getAddress();
+ if(port != -1) {
+ lookupURLString = lookupURLString + ":" + port;
+ }
+ lookupURLString = lookupURLString + "/";
+
+ try {
+ if (log != null) {
+ log.println("Admin: attempting to discover "
+ + "lookup service at locator " + lookupURLString);
+ }
+ LookupLocator lLoc = new LookupLocator(lookupURLString);
+ return lLoc.getRegistrar();
+ } catch( Exception e) {
+ throw new RemoteException("Admin: could not get "
+ + "the ServiceRegistrar",e);
+ }
+ }
+
+ /**
+ * Fills the given list with the superinterfaces implemented by
+ * the given class eliminating duplicates.
+ *
+ * @param list the list to fill with interfaces
+ * @param class the class to get the superinterfaces of
+ * @throws NullPointerException if the specified class or list is null
+ **/
+ private static void getSuperinterfaces(List list, Class cl) {
+ Class superclass = cl.getSuperclass();
+ if (superclass != null) {
+ getSuperinterfaces(list, superclass);
+ }
+ Class[] interfaces = cl.getInterfaces();
+ for (int i = 0; i < interfaces.length; i++) {
+ getSuperinterfaces(list, interfaces[i]);
+ }
+ if (cl.isInterface()) {
+ list.add(cl);
+ }
+ }
+
+
+ /*
+ * Attach stdout and stderr to the subprocess.
+ */
+ private void bindOutput(Process proc) throws IOException {
+ (new Thread(new Dumper(proc.getInputStream(), System.out))).start();
+ (new Thread(new Dumper(proc.getErrorStream(), System.err))).start();
+ }
+
+ /**
+ * Utility class to forward bytes from one stream to another.
+ */
+ private class Dumper implements Runnable {
+ private final InputStream in;
+ private final OutputStream out;
+
+ /**
+ * Create a new <code>Dumper</code>
+ * @param in The stream to take bytes from
+ * @param out The stream to dump the bytes to
+ */
+ Dumper(InputStream in, OutputStream out) {
+ this.in = in;
+ this.out = out;
+ }
+
+ /**
+ * Read a bunch of bytes from the associated
+ * <code>InputStream</code> and write them to the associated
+ * <code>OutputStream<code>, repeat until the read returns
+ * EOF, or until there is an <code>IOException</code>
+ */
+ public void run() {
+ byte[] buf = new byte[4096];
+ try {
+ while (true) {
+ final int bytesRead = in.read(buf);
+ if (bytesRead > 0) {
+ out.write(buf, 0, bytesRead);
+ } else if (bytesRead < 0) {
+ break;
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ in.close();
+ } catch (IOException ignore) {
+ }
+ }
+ }
+ } // end of Dumper class
+
+}
Propchange: river/tck/src/com/sun/jini/compat/admin2/ExecServiceAdmin.java
------------------------------------------------------------------------------
svn:eol-style = native