1 24 25 package helloworld; 26 27 import org.objectweb.dream.Push; 28 import org.objectweb.dream.control.activity.task.TaskManagerController; 29 import org.objectweb.dream.message.manager.MessageManagerImpl; 30 import org.objectweb.dream.message.manager.MessageManager; 31 import org.objectweb.dream.message.manager.MessageManagerAttributeController; 32 import org.objectweb.fractal.api.Component; 33 import org.objectweb.fractal.api.control.BindingController; 34 import org.objectweb.fractal.api.control.ContentController; 35 import org.objectweb.fractal.api.factory.GenericFactory; 36 import org.objectweb.fractal.api.type.ComponentType; 37 import org.objectweb.fractal.api.type.InterfaceType; 38 import org.objectweb.fractal.api.type.TypeFactory; 39 import org.objectweb.fractal.util.Fractal; 40 41 42 public final class Main 43 { 44 45 private Main() 46 { 47 } 48 49 57 public static void main(String [] args) throws Exception 58 { 59 if (args.length > 1) 60 { 61 usage(); 62 } 63 String clientClass = null; 64 if (args.length == 0) 65 { 66 clientClass = ClientImpl.class.getName(); 67 } 68 else 69 { 70 String arg = args[0]; 71 if (arg.equalsIgnoreCase("-mono")) 72 { 73 clientClass = ClientImpl.class.getName(); 74 } 75 else if (arg.equalsIgnoreCase("-pool")) 76 { 77 clientClass = PoolClientImpl.class.getName(); 78 } 79 else 80 { 81 usage(); 82 } 83 } 84 85 Component bootstrap = org.objectweb.fractal.api.Fractal 86 .getBootstrapComponent(); 87 GenericFactory genericFactory = Fractal.getGenericFactory(bootstrap); 88 TypeFactory typeFactory = Fractal.getTypeFactory(bootstrap); 89 90 InterfaceType outPushType = typeFactory.createFcItfType( 92 Push.OUT_PUSH_ITF_NAME, Push.class.getName(), true, false, false); 93 InterfaceType inPushType = typeFactory.createFcItfType( 94 Push.IN_PUSH_ITF_NAME, Push.class.getName(), false, false, false); 95 InterfaceType messageManagerClientType = typeFactory.createFcItfType( 96 MessageManager.ITF_NAME, MessageManager.class.getName(), true, false, 97 false); 98 InterfaceType messageManagerServerType = typeFactory.createFcItfType( 99 MessageManager.ITF_NAME, MessageManager.class.getName(), false, false, 100 false); 101 InterfaceType messageManagerAttributeControllerType = typeFactory 102 .createFcItfType("attribute-controller", 103 MessageManagerAttributeController.class.getName(), false, false, 104 false); 105 InterfaceType taskRegistrationClientType = typeFactory.createFcItfType( 106 "task-manager", TaskManagerController.class.getName(), true, false, 107 false); 108 109 ComponentType clientType = typeFactory.createFcType(new InterfaceType[]{ 111 outPushType, messageManagerClientType, taskRegistrationClientType}); 112 ComponentType serverType = typeFactory.createFcType(new InterfaceType[]{ 113 inPushType, messageManagerClientType}); 114 ComponentType messageManagerType = typeFactory 115 .createFcType(new InterfaceType[]{messageManagerServerType, 116 messageManagerAttributeControllerType}); 117 ComponentType compositeType = typeFactory 118 .createFcType(new InterfaceType[0]); 119 120 Component client = genericFactory.newFcInstance(clientType, 122 "activeDreamPrimitive", clientClass); 123 Component server = genericFactory.newFcInstance(serverType, 124 "dreamPrimitive", ServerImpl.class.getName()); 125 Component messageManager = genericFactory.newFcInstance(messageManagerType, 126 "dreamPrimitive", MessageManagerImpl.class.getName()); 127 Component composite = genericFactory.newFcInstance(compositeType, 128 "dreamComposite", null); 129 Component activityManager = genericFactory.newFcInstance(compositeType, 130 "threadPerTaskActivityComposite", null); 131 132 Fractal.getNameController(composite).setFcName("HelloWorld"); 134 Fractal.getNameController(client).setFcName("client"); 135 Fractal.getNameController(server).setFcName("server"); 136 Fractal.getNameController(messageManager).setFcName("messageManager"); 137 Fractal.getNameController(activityManager).setFcName("activityManager"); 138 139 MessageManagerAttributeController mmac = (MessageManagerAttributeController) messageManager 141 .getFcInterface("attribute-controller"); 142 mmac.setId((short) 0); 143 144 ContentController compositeCC = Fractal.getContentController(composite); 146 compositeCC.addFcSubComponent(client); 147 compositeCC.addFcSubComponent(server); 148 compositeCC.addFcSubComponent(messageManager); 149 compositeCC.addFcSubComponent(activityManager); 150 151 BindingController clientBC = Fractal.getBindingController(client); 153 clientBC.bindFc(Push.OUT_PUSH_ITF_NAME, server 154 .getFcInterface(Push.IN_PUSH_ITF_NAME)); 155 clientBC.bindFc(MessageManager.ITF_NAME, messageManager 156 .getFcInterface(MessageManager.ITF_NAME)); 157 clientBC.bindFc("task-manager", activityManager 158 .getFcInterface("task-manager-controller")); 159 BindingController serverBC = Fractal.getBindingController(server); 160 serverBC.bindFc(MessageManager.ITF_NAME, messageManager 161 .getFcInterface(MessageManager.ITF_NAME)); 162 163 Fractal.getLifeCycleController(composite).startFc(); 165 Thread.sleep(3000); 166 System.out.println("call to stop..."); 167 Fractal.getLifeCycleController(composite).stopFc(); 168 System.out.println("stop returned"); 169 } 170 171 private static void usage() 172 { 173 System.out.println("Usage : HelloWorld [-mono|-pool]"); 174 System.out.println("Run the Helloworld example of Dream core framework"); 175 System.out.println("Arguments : "); 176 System.out 177 .println(" -mono : use the mono-threaded client component (default) "); 178 System.out.println(" -pool : use the client component using thread pool"); 179 System.exit(1); 180 } 181 } | Popular Tags |