提交 cdcd340a 编写于 作者: L lancea

8190439: Removal of newrmic

Reviewed-by: rriggs, alanb, mchung
上级 77c21248
......@@ -139,21 +139,6 @@ public class Main implements sun.rmi.rmic.Constants {
*/
public synchronized boolean compile(String argv[]) {
/*
* Handle internal option to use the new (and incomplete) rmic
* implementation. This option is handled here, rather than
* in parseArgs, so that none of the arguments will be nulled
* before delegating to the new implementation.
*/
// disable the -Xnew option as per JDK-8146299 and JDK-8145980
// to allow further discussion how to progress with this feature
//for (int i = 0; i < argv.length; i++) {
// if (argv[i].equals("-Xnew")) {
// return (new sun.rmi.rmic.newrmic.Main(out,
// program)).compile(argv);
// }
//}
if (!parseArgs(argv)) {
return false;
}
......
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.rmi.rmic.newrmic;
import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.RootDoc;
import java.io.File;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static sun.rmi.rmic.newrmic.Constants.*;
/**
* The environment for an rmic compilation batch.
*
* A BatchEnvironment contains a RootDoc, which is the entry point
* into the doclet environment for the associated rmic compilation
* batch. A BatchEnvironment collects the source files generated
* during the batch's execution, for eventual source code compilation
* and, possibly, deletion. Errors that occur during generation
* activity should be reported through the BatchEnvironment's "error"
* method.
*
* A protocol-specific generator class may require the use of a
* particular BatchEnvironment subclass for enhanced environment
* functionality. A BatchEnvironment subclass must declare a
* public constructor with one parameter of type RootDoc.
*
* WARNING: The contents of this source file are not part of any
* supported API. Code that depends on them does so at its own risk:
* they are subject to change or removal without notice.
*
* @author Peter Jones
**/
public class BatchEnvironment {
private final RootDoc rootDoc;
/** cached ClassDoc for certain types used by rmic */
private final ClassDoc docRemote;
private final ClassDoc docException;
private final ClassDoc docRemoteException;
private final ClassDoc docRuntimeException;
private boolean verbose = false;
private final List<File> generatedFiles = new ArrayList<File>();
/**
* Creates a new BatchEnvironment with the specified RootDoc.
**/
public BatchEnvironment(RootDoc rootDoc) {
this.rootDoc = rootDoc;
/*
* Initialize cached ClassDoc for types used by rmic. Note
* that any of these could be null if the boot class path is
* incorrect, which could cause a NullPointerException later.
*/
docRemote = rootDoc().classNamed(REMOTE);
docException = rootDoc().classNamed(EXCEPTION);
docRemoteException = rootDoc().classNamed(REMOTE_EXCEPTION);
docRuntimeException = rootDoc().classNamed(RUNTIME_EXCEPTION);
}
/**
* Returns the RootDoc for this environment.
**/
public RootDoc rootDoc() {
return rootDoc;
}
public ClassDoc docRemote() { return docRemote; }
public ClassDoc docException() { return docException; }
public ClassDoc docRemoteException() { return docRemoteException; }
public ClassDoc docRuntimeException() { return docRuntimeException; }
/**
* Sets this environment's verbosity status.
**/
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}
/**
* Returns this environment's verbosity status.
**/
public boolean verbose() {
return verbose;
}
/**
* Adds the specified file to the list of source files generated
* during this batch.
**/
public void addGeneratedFile(File file) {
generatedFiles.add(file);
}
/**
* Returns the list of files generated during this batch.
**/
public List<File> generatedFiles() {
return Collections.unmodifiableList(generatedFiles);
}
/**
* Outputs the specified (non-error) message.
**/
public void output(String msg) {
rootDoc.printNotice(msg);
}
/**
* Reports an error using the specified resource key and text
* formatting arguments.
**/
public void error(String key, String... args) {
rootDoc.printError(Resources.getText(key, args));
}
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.rmi.rmic.newrmic;
/**
* Constants potentially useful to all rmic generators.
*
* WARNING: The contents of this source file are not part of any
* supported API. Code that depends on them does so at its own risk:
* they are subject to change or removal without notice.
*
* @author Peter Jones
**/
public final class Constants {
private Constants() { throw new AssertionError(); }
/*
* fully-qualified names of types used by rmic
*/
public static final String REMOTE = "java.rmi.Remote";
public static final String EXCEPTION = "java.lang.Exception";
public static final String REMOTE_EXCEPTION = "java.rmi.RemoteException";
public static final String RUNTIME_EXCEPTION = "java.lang.RuntimeException";
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.rmi.rmic.newrmic;
import com.sun.javadoc.ClassDoc;
import java.io.File;
import java.util.Set;
/**
* The interface to rmic back end implementations. Classes that
* implement this interface correspond to the various generation modes
* of rmic (JRMP, IIOP, IDL, etc.).
*
* A Generator instance corresponds to a particular rmic compilation
* batch, and its instance state represents the generator-specific
* command line options for that batch. Main will instantiate a
* generator class when the command line arguments indicate selection
* of the corresponding generation mode. Main will then invoke the
* "parseArgs" method to allow the generator to process any
* generator-specific command line options and set its instance state
* accordingly.
*
* WARNING: The contents of this source file are not part of any
* supported API. Code that depends on them does so at its own risk:
* they are subject to change or removal without notice.
*
* @author Peter Jones
**/
public interface Generator {
/**
* Processes the command line options specific to this generator.
* Processed options are set to null in the specified array.
* Returns true if successful or false if an error occurs. Errors
* are output to the specific Main instance.
**/
public boolean parseArgs(String[] args, Main main);
/**
* Returns the most specific environment class required by this
* generator.
**/
public Class<? extends BatchEnvironment> envClass();
/**
* Returns the names of the classes that must be available through
* the doclet API in order for this generator to function.
**/
public Set<String> bootstrapClassNames();
/**
* Generates the protocol-specific rmic output files for the
* specified remote class. This method is invoked once for each
* class or interface specified on the command line for the rmic
* compilation batch associated with this instance.
*
* Any generated source files (to be compiled with javac) are
* passed to the addGeneratedFile method of the specified
* BatchEnvironment.
**/
public void generate(BatchEnvironment env,
ClassDoc inputClass,
File destDir);
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.rmi.rmic.newrmic;
import java.io.Writer;
import java.io.BufferedWriter;
import java.io.IOException;
/**
* A BufferedWriter that supports automatic indentation of lines of
* text written to the underlying Writer.
*
* Methods are provided for compact/convenient indenting in and out,
* writing text, and writing lines of text in various combinations.
*
* WARNING: The contents of this source file are not part of any
* supported API. Code that depends on them does so at its own risk:
* they are subject to change or removal without notice.
*
* @author Peter Jones
**/
public class IndentingWriter extends BufferedWriter {
/** number of spaces to change indent when indenting in or out */
private final int indentStep;
/** number of spaces to convert into tabs (use MAX_VALUE to disable) */
private final int tabSize;
/** true if the next character written is the first on a line */
private boolean beginningOfLine = true;
/** current number of spaces to prepend to lines */
private int currentIndent = 0;
/**
* Creates a new IndentingWriter that writes indented text to the
* given Writer. Use the default indent step of four spaces.
**/
public IndentingWriter(Writer out) {
this(out, 4);
}
/**
* Creates a new IndentingWriter that writes indented text to the
* given Writer and uses the supplied indent step.
**/
public IndentingWriter(Writer out, int indentStep) {
this(out, indentStep, 8);
}
/**
* Creates a new IndentingWriter that writes indented text to the
* given Writer and uses the supplied indent step and tab size.
**/
public IndentingWriter(Writer out, int indentStep, int tabSize) {
super(out);
if (indentStep < 0) {
throw new IllegalArgumentException("negative indent step");
}
if (tabSize < 0) {
throw new IllegalArgumentException("negative tab size");
}
this.indentStep = indentStep;
this.tabSize = tabSize;
}
/**
* Writes a single character.
**/
public void write(int c) throws IOException {
checkWrite();
super.write(c);
}
/**
* Writes a portion of an array of characters.
**/
public void write(char[] cbuf, int off, int len) throws IOException {
if (len > 0) {
checkWrite();
}
super.write(cbuf, off, len);
}
/**
* Writes a portion of a String.
**/
public void write(String s, int off, int len) throws IOException {
if (len > 0) {
checkWrite();
}
super.write(s, off, len);
}
/**
* Writes a line separator. The next character written will be
* preceded by an indent.
**/
public void newLine() throws IOException {
super.newLine();
beginningOfLine = true;
}
/**
* Checks if an indent needs to be written before writing the next
* character.
*
* The indent generation is optimized (and made consistent with
* certain coding conventions) by condensing groups of eight
* spaces into tab characters.
**/
protected void checkWrite() throws IOException {
if (beginningOfLine) {
beginningOfLine = false;
int i = currentIndent;
while (i >= tabSize) {
super.write('\t');
i -= tabSize;
}
while (i > 0) {
super.write(' ');
i--;
}
}
}
/**
* Increases the current indent by the indent step.
**/
protected void indentIn() {
currentIndent += indentStep;
}
/**
* Decreases the current indent by the indent step.
**/
protected void indentOut() {
currentIndent -= indentStep;
if (currentIndent < 0)
currentIndent = 0;
}
/**
* Indents in.
**/
public void pI() {
indentIn();
}
/**
* Indents out.
**/
public void pO() {
indentOut();
}
/**
* Writes string.
**/
public void p(String s) throws IOException {
write(s);
}
/**
* Ends current line.
**/
public void pln() throws IOException {
newLine();
}
/**
* Writes string; ends current line.
**/
public void pln(String s) throws IOException {
p(s);
pln();
}
/**
* Writes string; ends current line; indents in.
**/
public void plnI(String s) throws IOException {
p(s);
pln();
pI();
}
/**
* Indents out; writes string.
**/
public void pO(String s) throws IOException {
pO();
p(s);
}
/**
* Indents out; writes string; ends current line.
**/
public void pOln(String s) throws IOException {
pO(s);
pln();
}
/**
* Indents out; writes string; ends current line; indents in.
*
* This method is useful for generating lines of code that both
* end and begin nested blocks, like "} else {".
**/
public void pOlnI(String s) throws IOException {
pO(s);
pln();
pI();
}
/**
* Writes object.
**/
public void p(Object o) throws IOException {
write(o.toString());
}
/**
* Writes object; ends current line.
**/
public void pln(Object o) throws IOException {
p(o.toString());
pln();
}
/**
* Writes object; ends current line; indents in.
**/
public void plnI(Object o) throws IOException {
p(o.toString());
pln();
pI();
}
/**
* Indents out; writes object.
**/
public void pO(Object o) throws IOException {
pO();
p(o.toString());
}
/**
* Indents out; writes object; ends current line.
**/
public void pOln(Object o) throws IOException {
pO(o.toString());
pln();
}
/**
* Indents out; writes object; ends current line; indents in.
*
* This method is useful for generating lines of code that both
* end and begin nested blocks, like "} else {".
**/
public void pOlnI(Object o) throws IOException {
pO(o.toString());
pln();
pI();
}
}
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.rmi.rmic.newrmic;
import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
/**
* Provides resource support for rmic.
*
* WARNING: The contents of this source file are not part of any
* supported API. Code that depends on them does so at its own risk:
* they are subject to change or removal without notice.
*
* @author Peter Jones
**/
public final class Resources {
private static ResourceBundle resources = null;
private static ResourceBundle resourcesExt = null;
static {
try {
resources =
ResourceBundle.getBundle("sun.rmi.rmic.resources.rmic");
} catch (MissingResourceException e) {
// gracefully handle this later
}
try {
resourcesExt =
ResourceBundle.getBundle("sun.rmi.rmic.resources.rmicext");
} catch (MissingResourceException e) {
// OK if this isn't found
}
}
private Resources() { throw new AssertionError(); }
/**
* Returns the text of the rmic resource for the specified key
* formatted with the specified arguments.
**/
public static String getText(String key, String... args) {
String format = getString(key);
if (format == null) {
format = "missing resource key: key = \"" + key + "\", " +
"arguments = \"{0}\", \"{1}\", \"{2}\"";
}
return MessageFormat.format(format, (Object[]) args);
}
/**
* Returns the rmic resource string for the specified key.
**/
private static String getString(String key) {
if (resourcesExt != null) {
try {
return resourcesExt.getString(key);
} catch (MissingResourceException e) {
}
}
if (resources != null) {
try {
return resources.getString(key);
} catch (MissingResourceException e) {
return null;
}
}
return "missing resource bundle: key = \"" + key + "\", " +
"arguments = \"{0}\", \"{1}\", \"{2}\"";
}
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.rmi.rmic.newrmic.jrmp;
/**
* Constants specific to the JRMP rmic generator.
*
* WARNING: The contents of this source file are not part of any
* supported API. Code that depends on them does so at its own risk:
* they are subject to change or removal without notice.
*
* @author Peter Jones
**/
final class Constants {
private Constants() { throw new AssertionError(); }
/*
* fully-qualified names of types used by rmic
*/
static final String REMOTE_OBJECT = "java.rmi.server.RemoteObject";
static final String REMOTE_STUB = "java.rmi.server.RemoteStub";
static final String REMOTE_REF = "java.rmi.server.RemoteRef";
static final String OPERATION = "java.rmi.server.Operation";
static final String SKELETON = "java.rmi.server.Skeleton";
static final String SKELETON_MISMATCH_EXCEPTION =
"java.rmi.server.SkeletonMismatchException";
static final String REMOTE_CALL = "java.rmi.server.RemoteCall";
static final String MARSHAL_EXCEPTION = "java.rmi.MarshalException";
static final String UNMARSHAL_EXCEPTION = "java.rmi.UnmarshalException";
static final String UNEXPECTED_EXCEPTION = "java.rmi.UnexpectedException";
/*
* stub protocol versions
*/
enum StubVersion { V1_1, VCOMPAT, V1_2 };
/*
* serialVersionUID for all stubs that can use 1.2 protocol
*/
static final long STUB_SERIAL_VERSION_UID = 2;
/*
* version number used to seed interface hash computation
*/
static final int INTERFACE_HASH_STUB_VERSION = 1;
}
/*
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.rmi.rmic.newrmic.jrmp;
import com.sun.javadoc.ClassDoc;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import sun.rmi.rmic.newrmic.BatchEnvironment;
import sun.rmi.rmic.newrmic.Generator;
import sun.rmi.rmic.newrmic.IndentingWriter;
import sun.rmi.rmic.newrmic.Main;
import sun.rmi.rmic.newrmic.Resources;
import static sun.rmi.rmic.newrmic.jrmp.Constants.*;
/**
* JRMP rmic back end; generates source code for JRMP stub and
* skeleton classes.
*
* WARNING: The contents of this source file are not part of any
* supported API. Code that depends on them does so at its own risk:
* they are subject to change or removal without notice.
*
* @author Peter Jones
**/
public class JrmpGenerator implements Generator {
private static final Map<String,StubVersion> versionOptions =
new HashMap<String,StubVersion>();
static {
versionOptions.put("-v1.1", StubVersion.V1_1);
versionOptions.put("-vcompat", StubVersion.VCOMPAT);
versionOptions.put("-v1.2", StubVersion.V1_2);
}
private static final Set<String> bootstrapClassNames =
new HashSet<String>();
static {
bootstrapClassNames.add("java.lang.Exception");
bootstrapClassNames.add("java.rmi.Remote");
bootstrapClassNames.add("java.rmi.RemoteException");
bootstrapClassNames.add("java.lang.RuntimeException");
};
/** version of the JRMP stub protocol to generate code for */
private StubVersion version = StubVersion.V1_2; // default is -v1.2
/**
* Creates a new JrmpGenerator.
**/
public JrmpGenerator() { }
/**
* The JRMP generator recognizes command line options for
* selecting the JRMP stub protocol version to generate classes
* for. Only one such option is allowed.
**/
public boolean parseArgs(String[] args, Main main) {
String explicitVersion = null;
for (int i = 0; i < args.length; i++) {
String arg = args[i];
if (versionOptions.containsKey(arg)) {
if (explicitVersion != null && !explicitVersion.equals(arg)) {
main.error("rmic.cannot.use.both", explicitVersion, arg);
return false;
}
explicitVersion = arg;
version = versionOptions.get(arg);
args[i] = null;
}
}
return true;
}
/**
* The JRMP generator does not require an environment class more
* specific than BatchEnvironment.
**/
public Class<? extends BatchEnvironment> envClass() {
return BatchEnvironment.class;
}
public Set<String> bootstrapClassNames() {
return Collections.unmodifiableSet(bootstrapClassNames);
}
/**
* Generates the source file(s) for the JRMP stub class and
* (optionally) skeleton class for the specified remote
* implementation class.
**/
public void generate(BatchEnvironment env,
ClassDoc inputClass,
File destDir)
{
RemoteClass remoteClass = RemoteClass.forClass(env, inputClass);
if (remoteClass == null) {
return; // an error must have occurred
}
StubSkeletonWriter writer =
new StubSkeletonWriter(env, remoteClass, version);
File stubFile = sourceFileForClass(writer.stubClassName(), destDir);
try {
IndentingWriter out = new IndentingWriter(
new OutputStreamWriter(new FileOutputStream(stubFile)));
writer.writeStub(out);
out.close();
if (env.verbose()) {
env.output(Resources.getText("rmic.wrote",
stubFile.getPath()));
}
env.addGeneratedFile(stubFile);
} catch (IOException e) {
env.error("rmic.cant.write", stubFile.toString());
return;
}
File skeletonFile =
sourceFileForClass(writer.skeletonClassName(), destDir);
if (version == StubVersion.V1_1 ||
version == StubVersion.VCOMPAT)
{
try {
IndentingWriter out = new IndentingWriter(
new OutputStreamWriter(
new FileOutputStream(skeletonFile)));
writer.writeSkeleton(out);
out.close();
if (env.verbose()) {
env.output(Resources.getText("rmic.wrote",
skeletonFile.getPath()));
}
env.addGeneratedFile(skeletonFile);
} catch (IOException e) {
env.error("rmic.cant.write", skeletonFile.toString());
return;
}
} else {
/*
* If skeleton files are not being generated for this run,
* delete old skeleton source or class files for this
* remote implementation class that were (presumably) left
* over from previous runs, to avoid user confusion from
* extraneous or inconsistent generated files.
*/
File skeletonClassFile =
classFileForClass(writer.skeletonClassName(), destDir);
skeletonFile.delete(); // ignore failures (no big deal)
skeletonClassFile.delete();
}
}
/**
* Returns the File object to be used as the source file for a
* class with the specified binary name, with the specified
* destination directory as the top of the package hierarchy.
**/
private File sourceFileForClass(String binaryName, File destDir) {
return fileForClass(binaryName, destDir, ".java");
}
/**
* Returns the File object to be used as the class file for a
* class with the specified binary name, with the supplied
* destination directory as the top of the package hierarchy.
**/
private File classFileForClass(String binaryName, File destDir) {
return fileForClass(binaryName, destDir, ".class");
}
private File fileForClass(String binaryName, File destDir, String ext) {
int i = binaryName.lastIndexOf('.');
String classFileName = binaryName.substring(i + 1) + ext;
if (i != -1) {
String packageName = binaryName.substring(0, i);
String packagePath = packageName.replace('.', File.separatorChar);
File packageDir = new File(destDir, packagePath);
/*
* Make sure that the directory for this package exists.
* We assume that the caller has verified that the top-
* level destination directory exists, so we need not
* worry about creating it unintentionally.
*/
if (!packageDir.exists()) {
packageDir.mkdirs();
}
return new File(packageDir, classFileName);
} else {
return new File(destDir, classFileName);
}
}
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.rmi.rmic.newrmic.jrmp;
import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.MethodDoc;
import com.sun.javadoc.Parameter;
import com.sun.javadoc.Type;
/**
* Provides static utility methods.
*
* WARNING: The contents of this source file are not part of any
* supported API. Code that depends on them does so at its own risk:
* they are subject to change or removal without notice.
*
* @author Peter Jones
**/
final class Util {
private Util() { throw new AssertionError(); }
/**
* Returns the binary name of the class or interface represented
* by the specified ClassDoc.
**/
static String binaryNameOf(ClassDoc cl) {
String flat = cl.name().replace('.', '$');
String packageName = cl.containingPackage().name();
return packageName.equals("") ? flat : packageName + "." + flat;
}
/**
* Returns the method descriptor for the specified method.
*
* See section 4.3.3 of The Java Virtual Machine Specification
* Second Edition for the definition of a "method descriptor".
**/
static String methodDescriptorOf(MethodDoc method) {
String desc = "(";
Parameter[] parameters = method.parameters();
for (int i = 0; i < parameters.length; i++) {
desc += typeDescriptorOf(parameters[i].type());
}
desc += ")" + typeDescriptorOf(method.returnType());
return desc;
}
/**
* Returns the descriptor for the specified type, as appropriate
* for either a parameter or return type in a method descriptor.
**/
private static String typeDescriptorOf(Type type) {
String desc;
ClassDoc classDoc = type.asClassDoc();
if (classDoc == null) {
/*
* Handle primitive types.
*/
String name = type.typeName();
if (name.equals("boolean")) {
desc = "Z";
} else if (name.equals("byte")) {
desc = "B";
} else if (name.equals("char")) {
desc = "C";
} else if (name.equals("short")) {
desc = "S";
} else if (name.equals("int")) {
desc = "I";
} else if (name.equals("long")) {
desc = "J";
} else if (name.equals("float")) {
desc = "F";
} else if (name.equals("double")) {
desc = "D";
} else if (name.equals("void")) {
desc = "V";
} else {
throw new AssertionError(
"unrecognized primitive type: " + name);
}
} else {
/*
* Handle non-array reference types.
*/
desc = "L" + binaryNameOf(classDoc).replace('.', '/') + ";";
}
/*
* Handle array types.
*/
int dimensions = type.dimension().length() / 2;
for (int i = 0; i < dimensions; i++) {
desc = "[" + desc;
}
return desc;
}
/**
* Returns a reader-friendly string representation of the
* specified method's signature. Names of reference types are not
* package-qualified.
**/
static String getFriendlyUnqualifiedSignature(MethodDoc method) {
String sig = method.name() + "(";
Parameter[] parameters = method.parameters();
for (int i = 0; i < parameters.length; i++) {
if (i > 0) {
sig += ", ";
}
Type paramType = parameters[i].type();
sig += paramType.typeName() + paramType.dimension();
}
sig += ")";
return sig;
}
/**
* Returns true if the specified type is void.
**/
static boolean isVoid(Type type) {
return type.asClassDoc() == null && type.typeName().equals("void");
}
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.util.*;
import java.io.*;
/**
* Object interface for agent
*/
public interface Agent extends Serializable, Runnable {
/**
* Run method controls the execution of agent and is called by servers.
*/
void run();
/**
* getInfo method is called by home server to collect the information
* that the agent has collected.
*/
Vector getInfo();
/**
* getErrors returns String of errors encountered by Agent
*/
String getErrors();
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.rmi.*;
/**
* Define the remote interface
*/
public interface AgentServer extends Remote {
/**
* Accepts the agent, creates new thread and starts it.
*/
void accept (Agent agent)
throws RemoteException; //, InvalidAgentException;
/**
* Method for home server to accept agent returning home and
* report gathered information to STDOUT.
*/
void returnHome (Agent agent)
throws RemoteException; //, InvalidAgentException;
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.rmi.*;
import java.rmi.server.*;
import java.util.*;
import java.io.*;
/**
* Server accepts agents and could test for validity. Acts as both a home
* server and a regular server. The agent will jump to this host and
* the server will create a thread and allow the agent to run inside of
* it. The agent just queries the system.properties for machine info.
*/
public class AgentServerImpl
extends UnicastRemoteObject
implements AgentServer
{
/**
* Constructor
*
* @exception RemoteException If a network problem occurs.
*/
public AgentServerImpl() throws RemoteException {
// Could use to set up state of server
}
/**
* Instantiates Agent Server Implementation and sets security
* manager
*/
public static void main(String args[]) {
// Set the security Manager
//System.setSecurityManager(new MyRMISecurityManager());
try {
AgentServerImpl server = new AgentServerImpl();
Naming.rebind("/AgentServer", server);
System.out.println("Ready to receive agents.");
System.err.println("DTI_DoneInitializing");
} catch (Exception e) {
System.err.println("DTI_Error");
System.err.println("Did not establish server");
e.printStackTrace();
}
}
/**
* Remote method called by Agent to have server accept it.
*/
public synchronized void accept(Agent agent)
throws RemoteException //, InvalidAgentException
{
Thread t;
// Could check validity of agent here
// checkValid(agent);
// Create new thread to run agent
t = new Thread(agent);
System.out.println("Agent Accepted: " + t);
// Start agent
t.start();
}
/**
* Remote method called by Agent to return to final server.
*/
public synchronized void returnHome(Agent agent)
throws RemoteException //, InvalidAgentException
{
Enumeration info = null;
boolean bErrorsOccurred = false;
// Could check validity of agent here
// checkValid(agent);
// Grab and print collected info from agent
info = agent.getInfo().elements();
System.out.println("Collected information:");
while (info.hasMoreElements()) {
System.out.println(" " + (String) info.nextElement());
}
System.out.println("\nErrors:");
System.out.println(agent.getErrors());
if(!(agent.getErrors()).equals(""))
bErrorsOccurred = true;
if(bErrorsOccurred)
{
System.err.println("DTI_Error");
System.err.println("DTI_DoneExecuting");
}
else
{
System.err.println("DTI_DoneExecuting");
}
}
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
public interface Apple extends java.rmi.Remote {
public void notify(AppleEvent[] e) throws java.rmi.RemoteException;
public Orange newOrange(String name) throws java.rmi.RemoteException;
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.util.Date;
/**
* The AppleEvent class is simply an object to be passed back to a
* remote objct exported by an applet to verify proper object
* serialization.
*/
public class AppleEvent implements java.io.Serializable {
public static final int BUY = 0;
public static final int EAT = 1;
public static final int THROW = 2;
private int what;
private java.util.Date when;
public AppleEvent(int what)
{
this.what = what;
this.when = new Date();
}
public String toString()
{
String desc = "[";
switch (what) {
case BUY:
desc += "BUY";
break;
case EAT:
desc += "EAT";
break;
case THROW:
desc += "THROW";
break;
}
desc += " @ " + when + "]";
return desc;
}
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.logging.Logger;
import java.util.logging.Level;
/**
* The AppleImpl class implements the behavior of the remote "apple"
* objects exported by the application.
*/
public class AppleImpl
extends UnicastRemoteObject
implements Apple
{
private static Logger logger = Logger.getLogger("reliability.apple");
private String name;
public AppleImpl(String name) throws RemoteException {
this.name = name;
}
/**
* Receive an array of AppleEvent objects.
*/
public void notify(AppleEvent[] events) {
try {
String threadName = Thread.currentThread().getName();
logger.log(Level.FINEST,
threadName + ": " + toString() + ".notify: BEGIN");
for (int i = 0; i < events.length; ++ i) {
logger.log(Level.FINEST,
threadName + ": " + toString() +
".notify(): events[" + i + "] = " +
events[i].toString());
}
logger.log(Level.FINEST,
threadName + ": " + toString() + ".notify(): END");
} catch (RuntimeException e) {
logger.log(Level.SEVERE, toString() + ".notify():", e);
throw e;
}
}
/**
* Return a newly created and exported orange implementation.
*/
public Orange newOrange(String name) throws RemoteException {
try {
String threadName = Thread.currentThread().getName();
logger.log(Level.FINEST,
threadName + ": " + toString() +
".newOrange(" + name + "): BEGIN");
Orange orange = new OrangeImpl(name);
logger.log(Level.FINEST,
threadName + ": " + toString() +
".newOrange(" + name + "): END");
return orange;
} catch (RuntimeException e) {
logger.log(Level.SEVERE, toString() + ".newOrange():", e);
throw e;
}
}
public String toString() {
return name;
}
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface AppleUser extends Remote {
public void startTest() throws RemoteException;
public void reportException(Exception status) throws RemoteException;
public void useApple(Apple apple) throws RemoteException;
}
/*
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.rmi.RemoteException;
import java.rmi.Naming;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Random;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Logger;
import java.util.logging.Level;
/**
* The AppleUserImpl class implements the behavior of the remote
* "apple user" objects exported by the server. The application server
* passes each of its remote "apple" objects to an apple user, and an
* AppleUserThread is created for each apple.
*/
public class AppleUserImpl
extends UnicastRemoteObject
implements AppleUser
{
private static Logger logger = Logger.getLogger("reliability.appleuser");
private static int threadNum = 0;
private static long testDuration = 0;
private static int maxLevel = 7;
private static Thread server = null;
private static Exception status = null;
private static Random random = new Random();
public AppleUserImpl() throws RemoteException {
}
/**
* Allows the other server process to indicate that it is ready
* to start "juicing".
*/
public synchronized void startTest() throws RemoteException {
this.notifyAll();
}
/**
* Allows the other server process to report an exception to this
* process and thereby terminate the test.
*/
public void reportException(Exception status) throws RemoteException {
synchronized (AppleUserImpl.class) {
this.status = status;
AppleUserImpl.class.notifyAll();
}
}
/**
* "Use" supplied apple object. Create an AppleUserThread to
* stress it out.
*/
public synchronized void useApple(Apple apple) throws RemoteException {
String threadName = Thread.currentThread().getName();
logger.log(Level.FINEST,
threadName + ": AppleUserImpl.useApple(): BEGIN");
AppleUserThread t =
new AppleUserThread("AppleUserThread-" + (++threadNum), apple);
t.start();
logger.log(Level.FINEST,
threadName + ": AppleUserImpl.useApple(): END");
}
/**
* The AppleUserThread class repeatedly invokes calls on its associated
* Apple object to stress the RMI system.
*/
class AppleUserThread extends Thread {
Apple apple;
public AppleUserThread(String name, Apple apple) {
super(name);
this.apple = apple;
}
public void run() {
int orangeNum = 0;
long stopTime = System.currentTimeMillis() + testDuration;
Logger logger = Logger.getLogger("reliability.appleuserthread");
try {
do { // loop until stopTime is reached
/*
* Notify apple with some apple events. This tests
* serialization of arrays.
*/
int numEvents = Math.abs(random.nextInt() % 5);
AppleEvent[] events = new AppleEvent[numEvents];
for (int i = 0; i < events.length; ++ i) {
events[i] = new AppleEvent(orangeNum % 3);
}
apple.notify(events);
/*
* Request a new orange object be created in
* the application server.
*/
Orange orange = apple.newOrange(
"Orange(" + getName() + ")-" + (++orangeNum));
/*
* Create a large message of random ints to pass to orange.
*/
int msgLength = 1000 + Math.abs(random.nextInt() % 3000);
int[] message = new int[msgLength];
for (int i = 0; i < message.length; ++ i) {
message[i] = random.nextInt();
}
/*
* Invoke recursive call on the orange. Base case
* of recursion inverts messgage.
*/
OrangeEchoImpl echo = new OrangeEchoImpl(
"OrangeEcho(" + getName() + ")-" + orangeNum);
int[] response = orange.recurse(echo, message,
2 + Math.abs(random.nextInt() % (maxLevel + 1)));
/*
* Verify message was properly inverted and not corrupted
* through all the recursive method invocations.
*/
if (response.length != message.length) {
throw new RuntimeException(
"ERROR: CORRUPTED RESPONSE: " +
"wrong length of returned array " + "(should be " +
message.length + ", is " + response.length + ")");
}
for (int i = 0; i < message.length; ++ i) {
if (~message[i] != response[i]) {
throw new RuntimeException(
"ERROR: CORRUPTED RESPONSE: " +
"at element " + i + "/" + message.length +
" of returned array (should be " +
Integer.toHexString(~message[i]) + ", is " +
Integer.toHexString(response[i]) + ")");
}
}
try {
Thread.sleep(Math.abs(random.nextInt() % 10) * 1000);
} catch (InterruptedException e) {
}
} while (System.currentTimeMillis() < stopTime);
} catch (Exception e) {
status = e;
}
synchronized (AppleUserImpl.class) {
AppleUserImpl.class.notifyAll();
}
}
}
private static void usage() {
System.out.println("Usage: AppleUserImpl [-hours <hours> | " +
"-seconds <seconds>]");
System.out.println(" [-maxLevel <maxLevel>]");
System.out.println(" hours The number of hours to run the juicer.");
System.out.println(" The default is 0 hours.");
System.out.println(" seconds The number of seconds to run the juicer.");
System.out.println(" The default is 0 seconds.");
System.out.println(" maxLevel The maximum number of levels to ");
System.out.println(" recurse on each call.");
System.out.println(" The default is 7 levels.");
//TestLibrary.bomb("Bad argument");
}
/**
* Entry point for the "juicer" server process. Create and export
* an apple user implementation in an rmiregistry running on localhost.
*/
public static void main(String[] args)
{
//TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
long startTime = 0;
String durationString = null;
// parse command line args
try {
for (int i = 0; i < args.length ; i++ ) {
String arg = args[i];
if (arg.equals("-hours")) {
if (durationString != null) {
usage();
}
i++;
int hours = Integer.parseInt(args[i]);
durationString = hours + " hours";
testDuration = hours * 60 * 60 * 1000;
} else if (arg.equals("-seconds")) {
if (durationString != null) {
usage();
}
i++;
long seconds = Long.parseLong(args[i]);
durationString = seconds + " seconds";
testDuration = seconds * 1000;
} else if (arg.equals("-maxLevel")) {
i++;
maxLevel = Integer.parseInt(args[i]);
} else {
usage();
}
}
if (durationString == null) {
durationString = testDuration + " milliseconds";
}
} catch (Throwable t) {
usage();
}
AppleUserImpl user = null;
try {
user = new AppleUserImpl();
} catch (RemoteException e) {
//TestLibrary.bomb("Failed to create AppleUser", e);
}
synchronized (user) {
int port = -1;
// create new registry and bind new AppleUserImpl in registry
try {
Registry registry = TestLibrary.createRegistryOnEphemeralPort();
port = TestLibrary.getRegistryPort(registry);
Naming.rebind("rmi://localhost:" + port + "/AppleUser",user);
} catch (RemoteException e) {
//TestLibrary.bomb("Failed to bind AppleUser", e);
} catch (java.net.MalformedURLException e) {
//TestLibrary.bomb("Failed to bind AppleUser", e);
}
// start the other server if available
try {
Class app = Class.forName("ApplicationServer");
java.lang.reflect.Constructor appConstructor =
app.getDeclaredConstructor(new Class[] {Integer.TYPE});
server = new Thread((Runnable) appConstructor.newInstance(port));
} catch (ClassNotFoundException e) {
// assume the other server is running in a separate process
logger.log(Level.INFO, "Application server must be " +
"started in separate process");
} catch (Exception ie) {
//TestLibrary.bomb("Could not instantiate server", ie);
}
// wait for other server to call startTest method
try {
logger.log(Level.INFO, "Waiting for application server " +
"process to start");
user.wait();
} catch (InterruptedException ie) {
//TestLibrary.bomb("AppleUserImpl interrupted", ie);
}
}
startTime = System.currentTimeMillis();
logger.log(Level.INFO, "Test starting");
// wait for exception to be reported or first thread to complete
try {
logger.log(Level.INFO, "Waiting " + durationString + " for " +
"test to complete or exception to be thrown");
synchronized (AppleUserImpl.class) {
AppleUserImpl.class.wait();
}
if (status != null) {
//TestLibrary.bomb("juicer server reported an exception", status);
} else {
logger.log(Level.INFO, "TEST PASSED");
}
} catch (Exception e) {
logger.log(Level.INFO, "TEST FAILED");
//TestLibrary.bomb("unexpected exception", e);
} finally {
logger.log(Level.INFO, "Test finished");
long actualDuration = System.currentTimeMillis() - startTime;
logger.log(Level.INFO, "Test duration was " +
(actualDuration/1000) + " seconds " +
"(" + (actualDuration/3600000) + " hours)");
}
}
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
public interface Callback extends Remote
{
void callback() throws RemoteException;
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.rmi.*;
/**
* Remote interface for the Compute Server
*/
public interface ComputeServer extends Remote {
/**
* Called by the task and passes itself as an object
*/
Object compute(Task task) throws RemoteException;
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.rmi.*;
import java.rmi.server.*;
import java.io.*;
/**
* Class accepts a task and runs it in its own space.
*/
public class ComputeServerImpl
extends UnicastRemoteObject
implements ComputeServer
{
public ComputeServerImpl() throws RemoteException
{
}
/**
* Accepts task and runs it
*/
public Object compute(Task task) {
return task.run();
}
/**
* Binds compute server and waits for tasks
*/
public static void main(String args[]) throws Exception
{
// use the default, restrictive security manager
System.setSecurityManager(new RMISecurityManager());
Naming.rebind("/ComputeServer", new ComputeServerImpl());
System.out.println("Ready to receive tasks.");
System.err.println("DTI_DoneInitializing");
}
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// RMI Activation Functional Test
import java.rmi.*;
import java.rmi.activation.*;
// CountInterface
public interface CountInterface extends Remote {
public void ping() throws RemoteException;
public int incrementCount() throws RemoteException;
public int decrementCount() throws RemoteException;
public int getCount() throws RemoteException;
public int getClassCount() throws RemoteException;
public String getProperty(String s) throws RemoteException;
public void exit() throws RemoteException;
// Methods specific to dealing with activatable objects
public boolean unexportObject(boolean b) throws RemoteException;
public ActivationID getActivationID() throws RemoteException;
public ActivationGroupID getCurrentGroupID() throws RemoteException;
public void inactive()
throws RemoteException, UnknownObjectException, ActivationException;
public void register()
throws RemoteException, UnknownObjectException, ActivationException;
public void unregister()
throws RemoteException, UnknownObjectException, ActivationException;
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// RMI Activation Functional Test
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.activation.*;
import java.util.*;
// CountServerImpl
public class CountServerImpl
extends Activatable
implements CountInterface {
private static final String PROG_NAME = "CountServerImpl";
private static final String SERVER_OBJECT = "CountServer";
private static final String CLASS_NAME = "activation.CountServerImpl";
private static final String POLICY_FILE = "policy_file";
private static final String USER_DIR =
System.getProperty("user.dir").replace('\\', '/');
private static final String CODE_LOCATION = "file:"+USER_DIR+"/";
private static final MarshalledObject DATA = null;
private static ActivationDesc ACTIVATION_DESC = null;
// Class variable
private static int classCount = 0;
// Instance variable
private int instanceCount;
private TestInterface ref;
public CountServerImpl(ActivationID id, MarshalledObject data)
throws RemoteException {
super(id, 0);
instanceCount = 0;
classCount++;
if (data != null) {
try {
ref = (TestInterface)data.get();
ref.ping(SERVER_OBJECT);
}
catch (Exception e) {
System.err.println("Exception: " + e);
}
}
}
public void ping() throws RemoteException {}
public int getCount() throws RemoteException {
return instanceCount;
}
public int incrementCount() throws RemoteException {
return ++instanceCount;
}
public int decrementCount() throws RemoteException {
return --instanceCount;
}
public int getClassCount() throws RemoteException {
return classCount;
}
public String getProperty(String s) throws RemoteException {
return System.getProperty(s);
}
public void exit() throws RemoteException {
System.exit(0);
}
public boolean unexportObject(boolean force) {
boolean succeeded = false;
try {
succeeded = Activatable.unexportObject(this, force);
}
catch (Exception e) {
System.err.println("Exception: " + e);
e.printStackTrace();
}
return succeeded;
}
public ActivationID getActivationID() throws RemoteException {
return super.getID();
}
public void inactive()
throws RemoteException, ActivationException, UnknownObjectException {
//ShutDown s = new ShutDown(super.getID(),this,ShutDown.NORMAL_SHUTDOWN);
}
public void unregister()
throws RemoteException, ActivationException, UnknownObjectException {
unregister(super.getID());
}
public void register()
throws RemoteException, ActivationException, UnknownObjectException {
register(ACTIVATION_DESC);
}
public ActivationGroupID getCurrentGroupID() throws RemoteException {
return ActivationGroup.currentGroupID();
}
private static void setup() {
try {
CountInterface rsi; // Remote server interface
System.setSecurityManager(new RMISecurityManager());
rsi = (CountInterface)Activatable.register(ACTIVATION_DESC);
System.out.println("Got stub for "+SERVER_OBJECT+" implementation");
Naming.rebind(SERVER_OBJECT, rsi);
System.out.println("Exported "+SERVER_OBJECT+" implementation");
} catch (Exception e) {
System.err.println("Exception: " + e);
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
Properties props = new Properties();
props.setProperty("java.security.policy", POLICY_FILE);
ActivationGroupDesc agd = new ActivationGroupDesc(props, null);
ActivationGroupID agid = ActivationGroup.getSystem().registerGroup(agd);
ACTIVATION_DESC = new ActivationDesc(agid,
CLASS_NAME, CODE_LOCATION, DATA, false);
}
catch (Exception e) {
System.err.println("Exception: " + e);
e.printStackTrace();
}
setup();
}
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// RMI Activation Functional Test
import java.rmi.*;
import java.rmi.activation.*;
// DayTimeInterface
public interface DayTimeInterface extends Remote {
public void ping() throws RemoteException;
public java.util.Date getDayTime() throws java.rmi.RemoteException;
public void exit() throws RemoteException;
public ActivationID getActivationID() throws RemoteException;
public ActivationGroupID getCurrentGroupID() throws RemoteException;
public void inactive()
throws RemoteException, UnknownObjectException, ActivationException;
public void register()
throws RemoteException, UnknownObjectException, ActivationException;
public void unregister()
throws RemoteException, UnknownObjectException, ActivationException;
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// RMI Activation Functional Test
import java.rmi.*;
import java.rmi.activation.*;
import java.util.*;
// DayTimeServerImpl
public class DayTimeServerImpl
extends Activatable
implements DayTimeInterface {
private static final String PROG_NAME = "DayTimeServerImpl";
private static final String SERVER_OBJECT = "DayTimeServer";
private static final String CLASS_NAME = "activation.DayTimeServerImpl";
private static final String POLICY_FILE = "policy_file";
private static final String USER_DIR =
System.getProperty("user.dir").replace('\\', '/');
private static final String CODE_LOCATION = "file:"+USER_DIR+"/";
private static final MarshalledObject DATA = null;
private static ActivationDesc ACTIVATION_DESC = null;
private TestInterface ref;
public void ping() throws RemoteException {}
public ActivationID getActivationID() throws RemoteException {
return super.getID();
}
public DayTimeServerImpl(ActivationID id, MarshalledObject data)
throws RemoteException {
super(id, 0);
if (data != null) {
try {
ref = (TestInterface)data.get();
ref.ping(SERVER_OBJECT);
}
catch (Exception e) {
System.err.println("Exception: " + e);
}
}
}
public Date getDayTime() throws RemoteException {
return new Date();
}
public void exit() throws RemoteException {
System.exit(0);
}
public void inactive()
throws RemoteException, ActivationException, UnknownObjectException {
//ShutDown s = new ShutDown(super.getID(),this,ShutDown.NORMAL_SHUTDOWN);
}
public void unregister()
throws RemoteException, ActivationException, UnknownObjectException {
unregister(super.getID());
}
public void register()
throws RemoteException, ActivationException, UnknownObjectException {
register(ACTIVATION_DESC);
}
public ActivationGroupID getCurrentGroupID() throws RemoteException {
return ActivationGroup.currentGroupID();
}
private static void setup() {
try {
DayTimeInterface rsi; // Remote server interface
System.setSecurityManager(new RMISecurityManager());
rsi = (DayTimeInterface)Activatable.register(ACTIVATION_DESC);
System.out.println("Got stub for "+SERVER_OBJECT+" implementation");
Naming.rebind(SERVER_OBJECT, rsi);
System.out.println("Exported "+SERVER_OBJECT+" implementation");
} catch (Exception e) {
System.err.println("Exception: " + e);
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
Properties props = new Properties();
props.setProperty("java.security.policy", POLICY_FILE);
ActivationGroupDesc agd = new ActivationGroupDesc(props, null);
ActivationGroupID agid = ActivationGroup.getSystem().registerGroup(agd);
ACTIVATION_DESC = new ActivationDesc(agid,
CLASS_NAME, CODE_LOCATION, DATA, false);
}
catch (Exception e) {
System.err.println("Exception: " + e);
e.printStackTrace();
}
setup();
}
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface G1 extends Remote {
void m() throws RemoteException;
}
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
public class G1Impl implements G1 {
public void m() { }
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册