1 23 24 package org.objectweb.clif.server.lib; 25 26 import org.objectweb.clif.server.api.ClifServerControl; 27 import org.objectweb.clif.supervisor.api.SupervisorInfo; 28 import org.objectweb.clif.supervisor.api.ClifException; 29 import org.objectweb.clif.util.ClifClassLoader; 30 import org.objectweb.fractal.api.Component; 31 import org.objectweb.fractal.api.NoSuchInterfaceException; 32 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 33 import org.objectweb.fractal.api.control.IllegalContentException; 34 import org.objectweb.fractal.util.Fractal; 35 import org.objectweb.fractal.adl.FactoryFactory; 36 import org.objectweb.fractal.adl.Factory; 37 import org.objectweb.fractal.adl.ADLException; 38 import org.objectweb.util.monolog.api.Logger; 39 import org.objectweb.util.monolog.api.BasicLevel; 40 import org.objectweb.util.monolog.Monolog; 41 import java.util.Map ; 42 import java.util.HashMap ; 43 44 45 49 public class ClifServerImpl 50 implements ClifServerControl 51 { 52 static protected Logger log = Monolog.getDefaultMonologFactory().getLogger(ClifServerImpl.class.toString()); 53 54 55 56 protected Map blades = new HashMap (); 57 58 59 public ClifServerImpl() 60 { 61 } 62 63 64 68 69 77 public synchronized Component addBlade(Component clifApp, String adlDefinition, Map context, String bladeId) 78 throws ClifException 79 { 80 try 81 { 82 Factory adlFactory = FactoryFactory.getFactory(FactoryFactory.FRACTAL_BACKEND); 83 context.put("classloader", ClifClassLoader.getClassLoader()); 84 Component blade = (Component)adlFactory.newComponent(adlDefinition, context); 85 Fractal.getContentController(clifApp).addFcSubComponent(blade); 86 blades.put(bladeId, blade); 87 return blade; 88 } 89 catch (ADLException ex) 90 { 91 String message = "Unable to deploy blade " + bladeId; 92 log.log(BasicLevel.ERROR, message, ex); 93 throw new ClifException(message, ex); 94 } 95 catch (NoSuchInterfaceException ex) 96 { 97 throw new Error ( 98 "Bad configuration: unable to get Clif Application content controller", 99 ex); 100 } 101 catch (IllegalContentException ex) 102 { 103 throw new Error ( 104 "Bad configuration: unable to add a " + adlDefinition + " blade to Clif Application", 105 ex); 106 } 107 catch (IllegalLifeCycleException ex) 108 { 109 throw new Error ("Unable to add a new blade to the Clif Application", ex); 110 } 111 } 112 113 114 117 public synchronized void removeAllBlades(Component clifApp) 118 throws ClifException 119 { 120 String [] ids = (String [])blades.keySet().toArray(new String [blades.size()]); 121 for (int i=0 ; i<ids.length ; ++i) 122 { 123 removeBlade(clifApp, ids[i]); 124 } 125 } 126 127 128 134 public synchronized void removeBlade(Component clifApp, String id) 135 throws ClifException 136 { 137 Component blade = (Component) blades.remove(id); 138 if (blade == null) 139 { 140 throw new ClifException("Unknown blade identifier " + id); 141 } 142 try 143 { 144 Fractal.getBindingController(blade).unbindFc(SupervisorInfo.SUPERVISOR_INFO); 145 Fractal.getContentController(clifApp).removeFcSubComponent(blade); 146 if (blades.isEmpty()) 147 { 148 ClifClassLoader.clear(); 149 } 150 } 151 catch (Exception ex) 152 { 153 blades.put(id, blade); 154 String message = "Unable to complete removal of blade " + id; 155 log.log(BasicLevel.ERROR, message, ex); 156 throw new ClifException(message, ex); 157 } 158 } 159 } 160 | Popular Tags |