1 package demo.interceptors; 2 3 import org.omg.PortableInterceptor.*; 4 import org.omg.CosNaming.*; 5 import org.omg.CORBA.Any ; 6 7 14 15 public class ClientForwardInterceptor 16 extends org.omg.CORBA.LocalObject 17 implements ClientRequestInterceptor 18 { 19 private MyServer grid = null; 20 private boolean in_loop = false; 21 22 public ClientForwardInterceptor(NamingContextExt nc) 23 { 24 try 25 { 26 grid = MyServerHelper.narrow(nc.resolve(nc.to_name("grid2.example"))); 27 } 28 catch (Exception e) 29 { 30 e.printStackTrace(); 31 } 32 } 33 34 public String name() 35 { 36 return "ClientForwardInterceptor"; 37 } 38 39 public void destroy() 40 { 41 42 } 43 44 47 public void send_request(ClientRequestInfo ri) 48 throws ForwardRequest 49 { 50 if (! in_loop) 52 { 53 in_loop = true; 54 55 if (ri.effective_target()._is_a(MyServerHelper.id())) 56 { 57 if (! grid._is_equivalent(ri.effective_target())) 58 { 59 System.out.println("Interceptor: Throwing ForwardRequest"); 60 61 throw new ForwardRequest( grid ); 63 } 64 else 65 { 66 System.out.println("Interceptor: target is ok"); 67 in_loop = false; 68 } 69 } 70 else 71 { 72 System.out.println("Interceptor: ignoring, target has wrong type"); 73 in_loop = false; 74 } 75 } 76 else 77 System.out.println("Interceptor: ignoring, loop prevention"); 78 } 79 80 public void send_poll(ClientRequestInfo ri){ 81 } 82 83 public void receive_reply(ClientRequestInfo ri){ 84 } 85 86 public void receive_exception(ClientRequestInfo ri) 87 throws ForwardRequest{ 88 } 89 90 public void receive_other(ClientRequestInfo ri) 91 throws ForwardRequest{ 92 } 93 } | Popular Tags |