//Add Constructor
{
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, new String[] { Names.RMIException });
mv.visitCode();
Label l0 = new Label();
Label l1 = new Label();
Label l2 = new Label();
mv.visitTryCatchBlock(l0, l1, l2, Names.RMIException);
Label l3 = new Label();
Label l4 = new Label();
Label l5 = new Label();
mv.visitTryCatchBlock(l3, l4, l5, Names.Exception);
Label l6 = new Label();
mv.visitLabel(l6);
//Call Super Class
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, Names.UniCastObject, "<init>", "()V");
Label l7 = new Label();
mv.visitLabel(l7);
mv.visitMethodInsn(INVOKESTATIC, Names.Hyflow, "getLocator", Type.getMethodDescriptor(Type.getType(DirectoryManager.class), new Type [] {})); //"()Laleph/dir/DirectoryManager;");
mv.visitTypeInsn(CHECKCAST, Names.ControlFlowDirectory);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKEVIRTUAL, Names.ControlFlowDirectory, "addProxy", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {Type.getType(Object.class)})); //"(Ljava/lang/Object;)V");
Label l8 = new Label();
mv.visitLabel(l8);
mv.visitMethodInsn(INVOKESTATIC, Names.System, "getSecurityManager", Type.getMethodDescriptor(Type.getType(SecurityManager.class), new Type[]{}));//"()Ljava/lang/SecurityManager;");
Label l9 = new Label();
mv.visitJumpInsn(IFNONNULL, l9);
Label l10 = new Label();
mv.visitLabel(l10);
mv.visitTypeInsn(NEW, Names.RMISecurityManager);
mv.visitInsn(DUP);
mv.visitMethodInsn(INVOKESPECIAL, Names.RMISecurityManager, "<init>", "()V");
mv.visitMethodInsn(INVOKESTATIC, Names.System, "setSecurityManager", Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {Type.getType(SecurityManager.class)}));//"(Ljava/lang/SecurityManager;)V");
mv.visitLabel(l9);
mv.visitFrame(Opcodes.F_FULL, 1, new Object[] {proxyName}, 0, new Object[] {});
mv.visitMethodInsn(INVOKESTATIC, Names.HyflowNetwork, "getInstance", Type.getMethodDescriptor(Type.getType(Network.class), new Type[]{}));//"()Ledu/vt/rt/hyflow/util/network/Network;");
mv.visitMethodInsn(INVOKEVIRTUAL, Names.HyflowNetwork, "getPort", "()I");
mv.visitIntInsn(SIPUSH, 1000);
mv.visitInsn(IADD);
mv.visitVarInsn(ISTORE, 1);
Label l11 = new Label();
mv.visitLabel(l11);
mv.visitInsn(ACONST_NULL);
mv.visitVarInsn(ASTORE, 2);
mv.visitLabel(l0);
mv.visitVarInsn(ILOAD, 1);
mv.visitMethodInsn(INVOKESTATIC, "java/rmi/registry/LocateRegistry", "createRegistry", "(I)Ljava/rmi/registry/Registry;");
mv.visitVarInsn(ASTORE, 2);
mv.visitLabel(l1);
mv.visitJumpInsn(GOTO, l3);
mv.visitLabel(l2);
mv.visitFrame(Opcodes.F_FULL, 3, new Object[] {proxyName, Opcodes.INTEGER, "java/rmi/registry/Registry"}, 1, new Object[] {Names.RMIException});
mv.visitVarInsn(ASTORE, 3);
Label l12 = new Label();
mv.visitLabel(l12);
mv.visitVarInsn(ALOAD, 3);
mv.visitMethodInsn(INVOKEVIRTUAL, Names.RMIException, "printStackTrace", "()V");
mv.visitLabel(l3);
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
mv.visitVarInsn(ALOAD, 0);
mv.visitInsn(ICONST_1);
mv.visitMethodInsn(INVOKESTATIC, Names.UniCastObject, "unexportObject", "(Ljava/rmi/Remote;Z)Z");
mv.visitInsn(POP);
mv.visitLabel(l4);
Label l13 = new Label();
mv.visitJumpInsn(GOTO, l13);
mv.visitLabel(l5);
mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {"java/lang/Exception"});
mv.visitVarInsn(ASTORE, 3);
Label l14 = new Label();
mv.visitLabel(l14);
mv.visitLdcInsn("RMI unexporting");
mv.visitMethodInsn(INVOKESTATIC, "edu/vt/rt/hyflow/util/io/Logger", "error", "(Ljava/lang/String;)V");
mv.visitLabel(l13);
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
mv.visitVarInsn(ALOAD, 0);
mv.visitInsn(ICONST_0);
mv.visitMethodInsn(INVOKESTATIC, "java/rmi/server/UnicastRemoteObject", "exportObject", "(Ljava/rmi/Remote;I)Ljava/rmi/Remote;");
mv.visitTypeInsn(CHECKCAST, proxyIName);
mv.visitVarInsn(ASTORE, 3);
Label l15 = new Label();
mv.visitLabel(l15);
mv.visitVarInsn(ALOAD, 2);
mv.visitLdcInsn(Type.getType("L"+className+";"));
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;");
mv.visitVarInsn(ALOAD, 3);
mv.visitMethodInsn(INVOKEINTERFACE, "java/rmi/registry/Registry", "rebind", "(Ljava/lang/String;Ljava/rmi/Remote;)V");
Label l16 = new Label();
mv.visitLabel(l16);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESTATIC, "edu/vt/rt/hyflow/HyFlow", "getLocator", "()Laleph/dir/DirectoryManager;");
mv.visitFieldInsn(PUTFIELD, proxyName, "locator", "Laleph/dir/DirectoryManager;");
Label l17 = new Label();
mv.visitLabel(l17);
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
//Add Methods
for(RemoteMethodDetails mD: urmdtl){
mv = cw.visitMethod(ACC_PUBLIC, mD.rmD.name, mD.rmD.desc, null, null);
Type[] src = Type.getArgumentTypes(mD.rmD.desc);
Type returnType = Type.getReturnType(mD.rmD.desc);
int callerIndex = src.length + 1; //1 for this
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
// mv.visitLineNumber(56, l0);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEVIRTUAL, Names.ControlflowInterface, "getLastExecuter", "()Laleph/comm/Address;");
mv.visitVarInsn(ASTORE, callerIndex);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitInsn(ICONST_1);
mv.visitVarInsn(ALOAD, callerIndex);
mv.visitMethodInsn(INVOKESTATIC, "edu/vt/rt/hyflow/util/network/Network", "linkDelay", "(ZLaleph/comm/Address;)V");
Label l2 = new Label();
mv.visitLabel(l2);
mv.visitVarInsn(ALOAD, 2);
mv.visitMethodInsn(INVOKEVIRTUAL, "edu/vt/rt/hyflow/core/tm/control/ControlContext", "getContextId", "()Ljava/lang/Long;");
mv.visitMethodInsn(INVOKESTATIC, "edu/vt/rt/hyflow/core/tm/control/ControlContext", "getNeighbors", "(Ljava/lang/Long;)Ljava/util/Set;");
mv.visitVarInsn(ALOAD, callerIndex);
mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Set", "add", "(Ljava/lang/Object;)Z");
mv.visitInsn(POP);
Label l3 = new Label();
mv.visitLabel(l3);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, proxyName, "locator", "Laleph/dir/DirectoryManager;");
mv.visitVarInsn(ALOAD, 2);