1 22 package org.jboss.ejb3.embedded; 23 24 import java.util.HashSet ; 25 import java.util.Iterator ; 26 import java.util.Set ; 27 import org.jboss.dependency.spi.Controller; 28 import org.jboss.dependency.spi.ControllerContext; 29 import org.jboss.dependency.spi.ControllerState; 30 import org.jboss.dependency.spi.DependencyInfo; 31 import org.jboss.dependency.spi.DependencyItem; 32 import org.jboss.kernel.Kernel; 33 import org.jboss.kernel.spi.dependency.KernelControllerContext; 34 import org.jboss.util.JBossStringBuilder; 35 import org.jboss.logging.Logger; 36 37 43 public class KernelErrors 44 { 45 private static final Logger log = Logger.getLogger(KernelErrors.class); 46 47 public static boolean validate(Kernel kernel) 48 { 49 Controller controller = kernel.getController(); 50 Set notInstalled = new HashSet (controller.getNotInstalled()); 51 if (notInstalled.isEmpty()) return true; 52 53 for (Iterator i = notInstalled.iterator(); i.hasNext();) 54 { 55 KernelControllerContext context = (KernelControllerContext) i.next(); 56 if (context.getState().equals(context.getRequiredState())) 57 i.remove(); 58 } 59 60 if (notInstalled.isEmpty()) return true; 61 62 HashSet errors = new HashSet (); 63 HashSet incomplete = new HashSet (); 64 for (Iterator i = notInstalled.iterator(); i.hasNext();) 65 { 66 KernelControllerContext ctx = (KernelControllerContext) i.next(); 67 if (ctx.getState().equals(ControllerState.ERROR)) 68 errors.add(ctx); 69 else 70 incomplete.add(ctx); 71 } 72 if (errors.size() != 0) 73 { 74 log.error("*** DEPLOYMENTS IN ERROR:\n"); 75 for (Iterator i = errors.iterator(); i.hasNext();) 76 { 77 KernelControllerContext ctx = (KernelControllerContext) i.next(); 78 log.error("Failed deployment: " + ctx.getName(), ctx.getError()); 79 } 80 } 81 if (incomplete.size() != 0) 82 { 83 JBossStringBuilder buffer = new JBossStringBuilder(); 84 buffer.append("\n*** DEPLOYMENTS MISSING DEPENDENCIES:\n"); 85 for (Iterator i = incomplete.iterator(); i.hasNext();) 86 { 87 KernelControllerContext ctx = (KernelControllerContext) i.next(); 88 buffer.append(ctx.getName()).append(" depends on: \n"); 89 DependencyInfo dependsInfo = ctx.getDependencyInfo(); 90 Set depends = dependsInfo.getIDependOn(null); 91 for (Iterator j = depends.iterator(); j.hasNext();) 92 { 93 DependencyItem item = (DependencyItem) j.next(); 94 buffer.append(" ").append(item.getIDependOn()).append("'{").append(item.getWhenRequired().getStateString()); 95 buffer.append(':'); 96 ControllerContext other = controller.getContext(item.getIDependOn(), null); 97 if (other == null) 98 buffer.append("NOT FOUND"); 99 else 100 buffer.append(other.getState().getStateString()); 101 buffer.append('}'); 102 if (j.hasNext()) 103 buffer.append("\n"); 104 } 105 buffer.append('\n'); 106 } 107 log.error(buffer.toString()); 108 } 109 if (errors.size() > 0 || incomplete.size() > 0) 110 { 111 return false; 112 } 113 return true; 114 } 115 } 116 | Popular Tags |