1 22 package org.jboss.test.classloader.scoping.naming.service; 23 24 import javax.naming.InitialContext ; 25 import javax.naming.Context ; 26 import javax.management.MBeanServer ; 27 import javax.management.ObjectName ; 28 import javax.management.Attribute ; 29 30 import org.jboss.mx.util.MBeanServerLocator; 31 32 39 public class BindingService 40 { 41 private String [] names = {"Name0", "Name1", "Name2"}; 42 private Boolean origCallByValue; 43 44 public String [] getNames() 45 { 46 return names; 47 } 48 public void setNames(String [] names) 49 { 50 this.names = names; 51 } 52 53 public void start() throws Exception 54 { 55 MBeanServer server = MBeanServerLocator.locateJBoss(); 57 ObjectName namingService = new ObjectName ("jboss:service=Naming"); 58 origCallByValue = (Boolean ) server.getAttribute(namingService, "CallByValue"); 59 Attribute callByValue = new Attribute ("CallByValue", Boolean.TRUE); 60 server.setAttribute(namingService, callByValue); 61 System.out.println("NamingService.CallByValue set to true"); 62 63 InitialContext ctx = new InitialContext (); 64 Context testCtx = ctx.createSubcontext("shared-context"); 65 System.out.println("Created shared-context"); 66 testCtx.bind("KeyCount", new Integer (names.length)); 67 System.out.println("Bound KeyCount"); 68 for(int n = 0; n < names.length; n ++) 69 { 70 String key = "Key#" + n; 71 BindValue value = new BindValue(); 72 value.setValue("Value#"+n); 73 testCtx.bind(key, value); 74 System.out.println("Bound "+key); 75 } 76 } 77 78 public void stop() throws Exception 79 { 80 MBeanServer server = MBeanServerLocator.locateJBoss(); 81 ObjectName namingService = new ObjectName ("jboss:service=Naming"); 82 Attribute callByValue = new Attribute ("CallByValue", origCallByValue); 83 server.setAttribute(namingService, callByValue); 84 System.out.println("NamingService.CallByValue restored to: "+origCallByValue); 85 86 InitialContext ctx = new InitialContext (); 87 Context testCtx = (Context ) ctx.lookup("shared-context"); 88 testCtx.unbind("KeyCount"); 89 System.out.println("Unbound KeyCount"); 90 for(int n = 0; n < names.length; n ++) 91 { 92 String key = "Key#" + n; 93 testCtx.unbind(key); 94 System.out.println("Unbound "+key); 95 } 96 ctx.unbind("shared-context"); 97 System.out.println("Destroyed shared-context"); 98 } 99 } 100 | Popular Tags |