00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030  
00031 package org.objectweb.proactive.branchnbound;
00032 
00033 import org.apache.log4j.Logger;
00034 import org.objectweb.proactive.ActiveObjectCreationException;
00035 import org.objectweb.proactive.ProActive;
00036 import org.objectweb.proactive.branchnbound.core.Manager;
00037 import org.objectweb.proactive.branchnbound.core.Task;
00038 import org.objectweb.proactive.branchnbound.core.queue.TaskQueue;
00039 import org.objectweb.proactive.core.config.ProActiveConfiguration;
00040 import org.objectweb.proactive.core.descriptor.data.VirtualNode;
00041 import org.objectweb.proactive.core.node.Node;
00042 import org.objectweb.proactive.core.node.NodeException;
00043 import org.objectweb.proactive.core.node.NodeFactory;
00044 import org.objectweb.proactive.core.util.log.Loggers;
00045 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00046 
00047 
00060 public class ProActiveBranchNBound {
00061     private static Logger logger = ProActiveLogger.getLogger(Loggers.P2P_SKELETONS);
00062 
00063     static {
00064         
00065         ProActiveConfiguration.load();
00066     }
00067 
00068     
00069     
00070     
00071 
00091     public static Manager newBnB(Task root, Node managerNode, Node[] nodes,
00092         String queueType) throws ActiveObjectCreationException, NodeException {
00093         Object[] args = new Object[4];
00094         args[0] = root;
00095         args[1] = managerNode;
00096         args[2] = nodes;
00097         args[3] = queueType;
00098         return ProActiveBranchNBound.activingTheManager(args);
00099     }
00100 
00121     public static Manager newBnB(Task root, VirtualNode virtualNode,
00122         String queueType) throws ActiveObjectCreationException, NodeException {
00123         virtualNode.activate();
00124         Object[] args = new Object[4];
00125         args[0] = root;
00126         args[1] = null;
00127         args[2] = virtualNode.getNodes();
00128         args[3] = queueType;
00129         return ProActiveBranchNBound.activingTheManager(args);
00130     }
00131 
00154     public static Manager newBnB(Task root, Node managerNode, Node[][] nodes,
00155         String queueType) throws ActiveObjectCreationException, NodeException {
00156         Object[] args = new Object[4];
00157         args[0] = root;
00158         args[1] = managerNode;
00159         args[2] = nodes;
00160         args[3] = queueType;
00161         return ProActiveBranchNBound.activingTheManager(args);
00162     }
00163 
00190     public static Manager newBnB(Task root, VirtualNode[] virtualNodes,
00191         String queueType) throws ActiveObjectCreationException, NodeException {
00192         Object[] args = new Object[4];
00193         args[0] = root;
00194         args[1] = null;
00195         args[2] = virtualNodes;
00196         args[3] = queueType;
00197         return ProActiveBranchNBound.activingTheManager(args);
00198     }
00199 
00200     
00201     
00202     
00203 
00226     private static Manager activingTheManager(Object[] args)
00227         throws ActiveObjectCreationException, NodeException {
00228         assert args.length == 4 : args;
00229         if (logger.isDebugEnabled()) {
00230             logger.debug("New Active Manager with these arguments:\n" + "\t" +
00231                 args[0].getClass().getName() + "\n" + "\t" +
00232                 args[1].getClass().getName() + "\n" + "\t" +
00233                 args[2].getClass().getName() + "\n" + "\t" +
00234                 args[3].getClass().getName() + "\n");
00235         }
00236         assert args[0] instanceof Task : args[0];
00237         args[1] = (args[1] == null) ? NodeFactory.getDefaultNode()
00238                                     : (Node) args[1];
00239         assert args[1] instanceof Node : args[1];
00240         assert args[2] instanceof Node[] || args[2] instanceof Node[][] ||
00241         args[2] instanceof VirtualNode[] : args[2];
00242         assert args[3] instanceof String : args[3];
00243 
00244         return (Manager) ProActive.newActive(Manager.class.getName(), args,
00245             (Node) args[1]);
00246     }
00247 }