/** cached value of property java.rmi.server.ignoreStubClasses */
@SuppressWarnings("removal") privatestaticfinalboolean ignoreStubClasses =
AccessController.doPrivileged(
(PrivilegedAction<Boolean>) () -> Boolean.getBoolean("java.rmi.server.ignoreStubClasses"));
/** cache of impl classes that have no corresponding stub class */ privatestaticfinal Map<Class<?>, Void> withoutStubs =
Collections.synchronizedMap(new WeakHashMap<Class<?>, Void>(11));
final ClassLoader loader = implClass.getClassLoader(); finalClass<?>[] interfaces = getRemoteInterfaces(implClass); final InvocationHandler handler = new RemoteObjectInvocationHandler(clientRef);
/* Make sure to use the local stub loader for the stub classes. *Whenloadedbythelocalloadertheloadpathcanbe *propagatedtoremoteclients,bytheMarshalOutputStream/InStream *picklemethods
*/ try { Class<?> stubcl = Class.forName(stubname, false, remoteClass.getClassLoader());
Constructor<?> cons = stubcl.getConstructor(stubConsParamTypes); return (RemoteStub) cons.newInstance(new Object[] { ref });
} catch (ClassNotFoundException e) { thrownew StubNotFoundException( "Stub class not found: " + stubname, e);
} catch (NoSuchMethodException e) { thrownew StubNotFoundException( "Stub class missing constructor: " + stubname, e);
} catch (InstantiationException e) { thrownew StubNotFoundException( "Can't create instance of stub class: " + stubname, e);
} catch (IllegalAccessException e) { thrownew StubNotFoundException( "Stub class constructor not public: " + stubname, e);
} catch (InvocationTargetException e) { thrownew StubNotFoundException( "Exception creating instance of stub class: " + stubname, e);
} catch (ClassCastException e) { thrownew StubNotFoundException( "Stub class not instance of RemoteStub: " + stubname, e);
}
}
/** *LocateandreturntheSkeletonforthespecifiedremoteobject
*/ static Skeleton createSkeleton(Remote object) throws SkeletonNotFoundException
{ Class<?> cl; try {
cl = getRemoteClass(object.getClass());
} catch (ClassNotFoundException ex ) { thrownew SkeletonNotFoundException( "object does not implement a remote interface: " +
object.getClass().getName());
}
// now try to load the skeleton based ont he name of the class
String skelname = cl.getName() + "_Skel"; try { Class<?> skelcl = Class.forName(skelname, false, cl.getClassLoader());
/** *Computethe"methodhash"ofaremotemethod.Themethodhash *isalongcontainingthefirst64bitsoftheSHAdigestfrom *theUTFencodedstringofthemethodnameanddescriptor.
*/ publicstaticlong computeMethodHash(Method m) { long hash = 0;
ByteArrayOutputStream sink = new ByteArrayOutputStream(127); try {
MessageDigest md = MessageDigest.getInstance("SHA");
DataOutputStream out = new DataOutputStream( new DigestOutputStream(sink, md));
String s = getMethodNameAndDescriptor(m); if (serverRefLog.isLoggable(Log.VERBOSE)) {
serverRefLog.log(Log.VERBOSE, "string used for method hash: \"" + s + "\"");
}
out.writeUTF(s);
// use only the first 64 bits of the digest for the hash
out.flush(); byte hasharray[] = md.digest(); for (int i = 0; i < Math.min(8, hasharray.length); i++) {
hash += ((long) (hasharray[i] & 0xFF)) << (i * 8);
}
} catch (IOException ignore) { /* can't happen, but be deterministic anyway. */
hash = -1;
} catch (NoSuchAlgorithmException complain) { thrownew SecurityException(complain.getMessage());
} return hash;
}
/** *Returnastringconsistingofthegivenmethod'snamefollowedby *its"methoddescriptor",asappropriateforuseinthecomputation *ofthe"methodhash". * *Seesection4.3.3ofTheJavaVirtualMachineSpecificationfor *thedefinitionofa"methoddescriptor".
*/ privatestatic String getMethodNameAndDescriptor(Method m) {
StringBuilder desc = new StringBuilder(m.getName());
desc.append('('); Class<?>[] paramTypes = m.getParameterTypes(); for (int i = 0; i < paramTypes.length; i++) {
desc.append(getTypeDescriptor(paramTypes[i]));
}
desc.append(')'); Class<?> returnType = m.getReturnType(); if (returnType == void.class) { // optimization: handle void here
desc.append('V');
} else {
desc.append(getTypeDescriptor(returnType));
} return desc.toString();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.