1 3 package org.jgroups.tests; 4 5 6 import org.jgroups.*; 7 import org.jgroups.blocks.GroupRequest; 8 import org.jgroups.blocks.MethodCall; 9 import org.jgroups.blocks.RpcDispatcher; 10 11 12 13 17 public class DeadlockTest { 18 19 public class InRpc { 20 public void rpc_1() { _in_rpc_1(); } 21 public void rpc_2() { _in_rpc_2(); } 22 } 23 24 25 private class Handler implements MessageListener, MembershipListener { 26 public Handler() { super(); } 27 public byte[] getState() { return(null); } 29 public void setState(byte[] state) {} 30 public void receive(Message msg) {} 31 public void block() {} 33 public void suspect(Address suspect) {} 34 public void viewAccepted(View view) {} 35 } 36 37 39 private String name = "JG"; 40 private String stack = null; private JChannel channel; 42 private RpcDispatcher disp; 43 44 45 private void _in_rpc_1() { 46 System.out.println("In rpc_1()"); 47 cast_call("rpc_2", new Object []{}, new Class []{}); 48 System.out.println("Exiting rpc_1()"); 49 } 50 51 private void _in_rpc_2() { 52 System.out.println("In rpc_2()"); 53 System.out.println("Exiting rpc_2()"); 54 } 55 56 57 private void cast_call(String method, Object [] args, Class [] types) { 58 MethodCall call; 59 call = new MethodCall(method, args, types); 60 disp.callRemoteMethods(null, call, GroupRequest.GET_ALL, 0); 61 } 62 63 65 public DeadlockTest(boolean use_deadlock_detection) { 66 Handler handler = new Handler(); 67 InRpc in_rpc = new InRpc(); 68 69 try { 70 channel = new JChannel(stack); 71 disp = new RpcDispatcher(channel, handler, handler, in_rpc, use_deadlock_detection); 72 channel.connect(name); 73 } 74 catch(ChannelClosedException ex) { ex.printStackTrace(); } 75 catch(ChannelException ex) { ex.printStackTrace(); } 76 77 System.out.println("Calling rpc_1()"); 79 if(!use_deadlock_detection) 80 System.out.println("** Not using deadlock detection -- recursive call will hang !"); 81 else 82 System.out.println("** Using deadlock detection -- recursive call will succeed"); 83 cast_call("rpc_1", new Object []{}, new Class []{}); 84 System.out.println("Out of rpc_1()"); 85 channel.disconnect(); 86 channel.close(); 87 System.out.println("Disconnected"); 88 } 89 90 92 public static void main(String [] args) { 93 if(args.length != 1) { 94 System.out.println("DeadlockTest <true|false (use_deadlock_detection)>"); 95 return; 96 } 97 new DeadlockTest(Boolean.valueOf(args[0]).booleanValue()); 98 } 99 } 100 | Popular Tags |